Skip to content

Commit

Permalink
stupid astro content collections not supporting remark plugins well.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbloxhub committed Jul 24, 2023
1 parent d4ec4bf commit c39c215
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/components/BlogPost.astro
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
---
const { title, url, minutesRead, pubDate } = Astro.props
const { title, url, pubDate, renderPromise } = Astro.props
const { remarkPluginFrontmatter } = await renderPromise
---

<li>
<a href={url}>{title}</a> <br />
Approximately {minutesRead}, published {pubDate.toISOString().slice(0,10)}
Approximately {remarkPluginFrontmatter.minutesRead}, published {pubDate.toISOString().slice(0,10)}
</li>
2 changes: 1 addition & 1 deletion src/content/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const blogCollection = defineCollection({
pubDate: z.date(),
description: z.string(),
author: z.string(),
minutesRead: z.string()
minutesRead: z.string().optional()
})
})

Expand Down
4 changes: 2 additions & 2 deletions src/layouts/MarkdownPostLayout.astro
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
import Layout from "./Layout.astro"
const { frontmatter } = Astro.props
const { frontmatter, remarkPluginFrontmatter } = Astro.props
---
<Layout title={frontmatter.title}>
<main class="m-auto p-6 max-w-6xl text-left">
<h1>{frontmatter.title}</h1>
<p>Written by {frontmatter.author}</p>
<p>Published on {frontmatter.pubDate.toISOString().slice(0,10)}</p>
<p>Approximately {frontmatter.minutesRead}</p>
<p>Approximately {remarkPluginFrontmatter.minutesRead}</p>
<slot />
</main>
</Layout>
4 changes: 2 additions & 2 deletions src/pages/blog.astro
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const pageTitle = "bitbloxhub's blog"
<main class="m-auto p-6 max-w-6xl text-left">
<h1>bitbloxhub's blog!</h1>
<ul class="text-base">
{allPosts.map((post) => <BlogPost url={`/posts/${post.slug}/`} title={post.data.title} minutesRead={post.data.minutesRead} pubDate={post.data.pubDate} />)}
</ul>
{allPosts.map((post) => <BlogPost url={`/posts/${post.slug}/`} title={post.data.title} pubDate={post.data.pubDate} renderPromise={post.render()} />)}
</ul>
</main>
</Layout>
4 changes: 2 additions & 2 deletions src/pages/posts/[...slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export async function getStaticPaths() {
}
// 2. When it's time to render, you can get the entry directly from the prop
const { entry } = Astro.props
const { Content } = await entry.render()
const { Content, remarkPluginFrontmatter } = await entry.render()
---
<MarkdownPostLayout frontmatter={entry.data}>
<MarkdownPostLayout frontmatter={entry.data} remarkPluginFrontmatter={remarkPluginFrontmatter}>
<Content />
</MarkdownPostLayout>

0 comments on commit c39c215

Please sign in to comment.