-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RecipeLink component and link to recipes (#3005)
Co-authored-by: Reuben Tier <[email protected]> Co-authored-by: Sarah Rainsberger <[email protected]> Co-authored-by: Chris Swithinbank <[email protected]>
- Loading branch information
1 parent
3c2d147
commit 829b663
Showing
7 changed files
with
78 additions
and
4 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters