Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RecipeLink component and link to recipes #3005

Merged
merged 27 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8cac940
Add RecipeLink component
Jutanium Apr 6, 2023
a00215c
Update src/components/RecipeLinks.astro
Jutanium Apr 8, 2023
f9008f1
Update src/components/RecipeLinks.astro
Jutanium Apr 8, 2023
047f79c
implement Ximena's design
Jutanium Apr 26, 2023
f811f9b
another recipe link
Jutanium Apr 26, 2023
f575aaf
Update src/components/RecipeLinks.astro
Jutanium Apr 26, 2023
80fe9c9
Merge branch 'main' into recipes-linking
Jutanium Apr 26, 2023
d182e90
Update src/content/docs/en/core-concepts/endpoints.mdx
Jutanium Apr 27, 2023
929f8be
Update src/content/docs/en/guides/content.mdx
Jutanium Apr 27, 2023
6c877be
Update src/components/RecipeLinks.astro
Jutanium Apr 27, 2023
a1107d5
Update src/components/RecipeLinks.astro
Jutanium Apr 27, 2023
adbf222
Update src/components/RecipeLinks.astro
Jutanium Apr 27, 2023
26d6d56
Update src/components/RecipeLinks.astro
Jutanium Apr 27, 2023
a514100
Update src/components/RecipeLinks.astro
Jutanium Apr 27, 2023
5adb95c
Update src/components/RecipeLinks.astro
Jutanium Apr 27, 2023
d2d4080
Update src/components/RecipeLinks.astro
Jutanium Apr 27, 2023
cb0d89c
Update src/components/RecipeLinks.astro
Jutanium Apr 27, 2023
ecae7e6
Update src/content/docs/en/guides/imports.mdx
Jutanium Apr 27, 2023
5ec6d80
Update src/components/RecipeLinks.astro
Jutanium Apr 27, 2023
7cf7ffc
Update src/components/RecipeLinks.astro
Jutanium Apr 27, 2023
79523ba
make rss a recipe again
Jutanium Apr 27, 2023
92de144
Update src/components/RecipeLinks.astro
Jutanium Apr 27, 2023
a1846f7
compressed houston
Jutanium Apr 27, 2023
20cd227
Merge branch 'recipes-linking' of https://github.com/withastro/docs i…
Jutanium Apr 27, 2023
42683d1
remove recipe quotes
Jutanium Apr 27, 2023
0ab2855
Merge branch 'main' into recipes-linking
Jutanium Apr 27, 2023
6335764
Fix `max-width` typo
delucis Apr 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added public/houston_chef.webp
Binary file not shown.
64 changes: 64 additions & 0 deletions src/components/RecipeLinks.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
import { getEntryBySlug } from 'astro:content';
import { removeLeadingSlash, removeTrailingSlash } from '~/util';

export interface Props {
slugs: string[];
}

const slugs = Astro.props.slugs.map((slug) => removeLeadingSlash(removeTrailingSlash(slug)));

const entries = await Promise.all(
slugs.map(async (slug, i) => {
const entry = await getEntryBySlug('docs', slug);
if (!entry) {
throw new Error(`Could not find entry for slug "${Astro.props.slugs[i]}"`);
}
return entry;
})
);

const isList = entries.length > 1;
const noun = isList ? 'recipes' : 'recipe';
---

<div class="root">
<div class="flex">
<img src="/houston_chef.webp" width="26" alt="" />
<strong>Related {noun}:</strong>
{!isList && <a href={`/${entries[0]!.slug}/`}> {entries[0]!.data.title}</a>}
</div>
{
isList && (
<ul>
{entries.map((entry) => (
<li>
<a href={`/${entry!.slug}/`}>{entry!.data.title}</a>
</li>
))}
</ul>
)
}
</div>

<style>
.flex {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 0.25rem;
}
.flex > img {
margin-right: 0.25rem;
}
ul {
margin-left: 0.5rem;
}
.root {
background-color: var(--theme-bg-offset);
border-radius: 8px;
padding: 24px;
width: max-content;
max-width: 100%;
}
</style>
5 changes: 4 additions & 1 deletion src/content/docs/en/core-concepts/endpoints.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ title: Endpoints
description: Learn how to create endpoints that serve any kind of data
i18nReady: true
---
import RecipeLinks from "~/components/RecipeLinks.astro";

Astro lets you create custom endpoints to serve any kind of data. You can use this to generate images, expose an RSS document, or use them as API Routes to build a full API for your site.

In statically-generated sites, your custom endpoints are called at build time to produce static files. If you opt in to [SSR](/en/guides/server-side-rendering/) mode, custom endpoints turn into live server endpoints that are called on request. Static and SSR endpoints are defined similarly, but SSR endpoints support additional features.
Expand Down Expand Up @@ -171,6 +173,8 @@ export const all: APIRoute = ({ request }) => {
}
```

<RecipeLinks slugs={["en/recipes/captcha", "en/recipes/build-forms-api" ]}/>

### `request`
In SSR mode, the `request` property returns a fully usable [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) object that refers to the current request. This allows you to accept data and check headers:

Expand Down Expand Up @@ -210,4 +214,3 @@ export async function get({ params, redirect }) {
}
```

**Related recipe:** [Use server endpoints to verify a CAPTCHA](/en/recipes/captcha/)
3 changes: 3 additions & 0 deletions src/content/docs/en/core-concepts/routing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ description: An intro to routing with Astro.
i18nReady: true
---
import FileTree from '~/components/FileTree.astro'
import RecipeLinks from "~/components/RecipeLinks.astro"

Astro uses **file-based routing** to generate your build URLs based on the file layout of your project `src/pages/` directory.

Expand Down Expand Up @@ -83,6 +84,8 @@ Parameters can be included in separate parts of the path. For example, the file

📚 Learn more about [`getStaticPaths()`](/en/reference/api-reference/#getstaticpaths).

<RecipeLinks slugs={["en/recipes/i18n"]} />

#### Rest parameters

If you need more flexibility in your URL routing, you can use a [rest parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters) (`[...path]`) in your `.astro` filename to match file paths of any depth:
Expand Down
4 changes: 4 additions & 0 deletions src/content/docs/en/guides/content.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ description: >-
connect your CMS of choice.
i18nReady: false
---
import RecipeLinks from "~/components/RecipeLinks.astro"

Astro is a perfect choice for your content-focused site: blogs, marketing sites, portfolios, and more!

Astro helps you author and present your content. You can write a blog post directly in Astro using Markdown/MDX, or fetch your content from a headless CMS. Astro lets you build a site around your content: you can add a layout to your pages, create an index of posts, and set up an RSS feed to allow readers to subscribe.
Expand Down Expand Up @@ -48,6 +50,8 @@ If you're writing your content in a CMS, you can fetch your posts and use [dynam

To build common features to organize and display your content, such as a blog archive or a page for each blog tag, Astro allows you to [fetch filenames and metadata](/en/reference/api-reference/#astroglob) from your Markdown and MDX frontmatter and use these to generate page content and routes.

<RecipeLinks slugs={["en/guides/rss"]} />

## Community Integrations

In addition to the official [`@astrojs/mdx`](/en/guides/integrations-guide/mdx/) integration, there are several third-party [community integrations](https://astro.build/integrations/?search=&categories%5B%5D=css%2Bui) for working with content in your Astro project.
3 changes: 2 additions & 1 deletion src/content/docs/en/guides/imports.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Imports
description: Learn how to import different content types with Astro.
i18nReady: true
---
import RecipeLinks from "~/components/RecipeLinks.astro";

Astro supports most static assets with zero configuration required. You can use the `import` statement anywhere in your project JavaScript (including your Astro frontmatter) and Astro will include a built, optimized copy of that static asset in your final build. `@import` is also supported inside of CSS & `<style>` tags.

Expand Down Expand Up @@ -236,4 +237,4 @@ With **Vite** and compatible **Rollup** plugins, you can import file types which
Refer to your plugin's documentation for configuration options, and how to correctly install it.
:::

**Related recipe:** [Add support for importing YAML data](/en/recipes/add-yaml-support/).
<RecipeLinks slugs={["en/recipes/add-yaml-support"]} />
3 changes: 1 addition & 2 deletions src/content/docs/en/guides/server-side-rendering.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ i18nReady: true
import PackageManagerTabs from '~/components/tabs/PackageManagerTabs.astro'
import Since from '~/components/Since.astro';


**Server-side Rendering**, aka SSR, can be enabled in Astro. When you enable SSR you can:

- Implement sessions for login state in your app.
Expand Down Expand Up @@ -230,4 +229,4 @@ if (!product) {
### Server Endpoints

A server endpoint, also known as an **API route**, is a special function exported from a `.js` or `.ts` file within the `src/pages/` folder.
The function takes an [endpoint context](/en/reference/api-reference/#endpoint-context) and returns a [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response). A powerful feature of SSR, API routes are able to securely execute code on the server. To learn more, see our [Endpoints Guide](/en/core-concepts/endpoints/#server-endpoints-api-routes).
The function takes an [endpoint context](/en/reference/api-reference/#endpoint-context) and returns a [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response). A powerful feature of SSR, API routes are able to securely execute code on the server. To learn more, see our [Endpoints Guide](/en/core-concepts/endpoints/#server-endpoints-api-routes).