-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automate homepage link with frontmatter field in blog posts (#1227)
- Loading branch information
Showing
7 changed files
with
48 additions
and
6 deletions.
There are no files selected for viewing
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
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,21 @@ | ||
--- | ||
import { getCollection } from 'astro:content'; | ||
import PillLink from './PillLink.astro'; | ||
/** Blog posts with a banner configured in their frontmatter. */ | ||
const blogPostsWithBanner = await getCollection('blog', (entry) => !!entry.data.homepageLink); | ||
/** The most recent blog post. */ | ||
const latestBlogPost = blogPostsWithBanner | ||
.sort((a, b) => (a.data.publishDate > b.data.publishDate ? 1 : -1)) | ||
.pop(); | ||
--- | ||
|
||
{ | ||
latestBlogPost && ( | ||
<PillLink | ||
href={`https://astro.build/blog/${latestBlogPost.slug}/`} | ||
title={latestBlogPost.data.homepageLink!.title} | ||
subtitle={latestBlogPost.data.homepageLink!.subtitle} | ||
/> | ||
) | ||
} |
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