Skip to content

Commit

Permalink
fix(demos/narcissus-astro): 💫 add blog post dynamic route
Browse files Browse the repository at this point in the history
  • Loading branch information
rodneylab committed Dec 9, 2021
1 parent 1961322 commit d62b01b
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions demos/narcissus-astro/src/pages/[slug].astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
import Layout from '$components/Layout/index.tsx';
import { lstatSync, readdirSync } from 'node:fs';
import { join, resolve } from 'node:path';
import { Markdown } from 'astro/components';
export async function getStaticPaths() {
const __dirname = resolve();
const BLOG_PATH = join(__dirname, 'content/blog');
const directories = readdirSync(BLOG_PATH).filter((element) =>
lstatSync(`${BLOG_PATH}/${element}`).isDirectory(),
);
return directories.map((element) => ({ params: { slug: element } }));
}
const { slug } = Astro.request.params;
const Content = (await import(`../../content/blog/${slug}/index.md`)).default;
---

<html lang="en-GB">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<script src="https://js.hcaptcha.com/1/api.js?render=explicit" async defer hoist></script>
</head>
<body>
<Layout client:load {slug}>
<Markdown>
<Content />
</Markdown>
</Layout>
</body>
</html>

0 comments on commit d62b01b

Please sign in to comment.