-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Changes from 5 commits
8cac940
a00215c
f9008f1
047f79c
f811f9b
f575aaf
80fe9c9
d182e90
929f8be
6c877be
a1107d5
adbf222
26d6d56
a514100
5adb95c
d2d4080
cb0d89c
ecae7e6
5ec6d80
7cf7ffc
79523ba
92de144
a1846f7
20cd227
42683d1
0ab2855
6335764
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
--- | ||
import { getEntryBySlug } from 'astro:content'; | ||
|
||
export interface Props { | ||
slugs: string[]; | ||
} | ||
|
||
function convertSlug(slug: string) { | ||
let corrected = slug; | ||
if (slug.startsWith('/')) { | ||
corrected = corrected.slice(1); | ||
} | ||
if (slug.endsWith('/')) { | ||
corrected = corrected.slice(0, -1); | ||
} | ||
return corrected; | ||
} | ||
|
||
const slugs = Astro.props.slugs.map(convertSlug); | ||
Jutanium marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const entries = await Promise.all( | ||
slugs.map(async (slug, i) => { | ||
let entry = await getEntryBySlug('docs', slug); | ||
Jutanium marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (!entry) throw Error(`Could not find entry for slug "${Astro.props.slugs[i]}"`); | ||
Jutanium marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return entry; | ||
}) | ||
); | ||
|
||
const isList = entries.length > 1; | ||
const noun = isList ? 'Recipes' : 'Recipe'; | ||
Jutanium marked this conversation as resolved.
Show resolved
Hide resolved
|
||
--- | ||
|
||
<div class="root"> | ||
<div class="flex"> | ||
<img src="/houston_chef.png" width="26" alt="Chef Houston" /> | ||
Jutanium marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<span class="title">Related {noun}:</span> | ||
Jutanium marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{!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> | ||
.title { | ||
font-weight: 600; | ||
font-size: 1rem; | ||
color: #c7c5d3; | ||
} | ||
Jutanium marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.flex { | ||
display: flex; | ||
align-items: center; | ||
Jutanium marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
.flex > * { | ||
margin-right: 0.25rem; | ||
} | ||
.flex > img { | ||
margin-right: 0.5rem; | ||
} | ||
Jutanium marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ul { | ||
margin-left: 0.5rem; | ||
} | ||
div.root { | ||
Jutanium marked this conversation as resolved.
Show resolved
Hide resolved
|
||
background-color: rgba(90, 59, 134, 0.15); | ||
Jutanium marked this conversation as resolved.
Show resolved
Hide resolved
|
||
border-radius: 8px; | ||
padding: 24px; | ||
Jutanium marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
title: Add an RSS feed | ||
description: Let users subscribe to your content by adding an RSS feed to your Astro site. | ||
i18nReady: true | ||
type: recipe | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this intentional? Didn’t see any discussion of why we’re making this not a recipe (which means it doesn’t show up in “More recipes”). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not intentional! Thanks so much for catching that |
||
--- | ||
import PackageManagerTabs from '~/components/tabs/PackageManagerTabs.astro' | ||
import Since from '~/components/Since.astro' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we compress this? I’d drop it in https://squoosh.app/, make it 50% smaller (so it’s ~52px wide), and optimize it.