Skip to content

Commit f81dd52

Browse files
committed
Blog implementation
1 parent e37e955 commit f81dd52

6 files changed

Lines changed: 74 additions & 0 deletions

File tree

src/blog-posts/test1.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: "Test post foobar"
3+
description: "kekw"
4+
keywords: []
5+
6+
hidetoc: true
7+
---
8+
9+
barbaz

src/content.config.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {glob} from "astro/loaders";
2+
import {z, defineCollection} from "astro:content";
3+
4+
const blogPosts = defineCollection({
5+
loader: glob({pattern: "**/[^_]*.md", base: "./src/blog-posts"}),
6+
schema: z.object({
7+
title: z.string(),
8+
description: z.string(),
9+
keywords: z.array(z.string()),
10+
11+
hidetoc: z.boolean().optional(),
12+
wip: z.boolean().optional(),
13+
}),
14+
});
15+
16+
export const collections = {
17+
blogPosts,
18+
};

src/danger.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,14 @@ export function isViteGlobObject(obj: unknown): obj is ViteGlobObject {
5353

5454
return true;
5555
}
56+
57+
/*
58+
* Workaround for casting arbitrary objects to { [key: string]: unknown; }
59+
*/
60+
//export function toObjMappingUnknowns(obj: unknown): {[key: string]: unknown;} {
61+
// if (!obj || typeof obj !== "object") {
62+
// throw new Error("Failed to cast object to { [key: string]: unknown; }");
63+
// }
64+
// return obj as {[key: string]: unknown;};
65+
//}
66+

src/helpers/experimental-glob.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ function makeFullTree(): PageTree {
6767
"/src/pages/**/*.mdx",
6868
"!/src/pages/**/_*",
6969
"!/src/pages/**/_*/**/*",
70+
"!/src/pages/**/\\[*.astro",
7071
], {eager: true});
7172

7273
const reprocessedResult = Object.entries(globResult).map(([k, v]) => {

src/pages/blog/[...slug].astro

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
import {getCollection, render} from "astro:content";
3+
import Layout from "@layouts/GeneralLayout.astro";
4+
5+
import {makeFrontmatter} from "@helpers/frontmatter";
6+
7+
export async function getStaticPaths() {
8+
const posts = await getCollection("blogPosts");
9+
return posts.map(post => ({
10+
params: {slug: post.id},
11+
props: {post},
12+
}));
13+
}
14+
15+
const {post} = Astro.props;
16+
const {Content} = await render(post);
17+
18+
const frontmatter = makeFrontmatter({...post.data});
19+
---
20+
21+
<Layout {...frontmatter}>
22+
<Content/>
23+
</Layout>

src/pages/blog/index.astro

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
---
22
import Layout from "@layouts/BaseLayout.astro";
3+
import {getCollection} from "astro:content";
4+
35
import {fm} from "@helpers/frontmatter";
46
7+
const allPosts = await getCollection("blogPosts");
8+
59
export const frontmatter = fm({
610
title: "Sim's Blog",
711
description: "Sim's blog.",
@@ -15,5 +19,13 @@ export const frontmatter = fm({
1519

1620
<p><em>This is an early WIP focused on experimenting with ways to manage my blog posts before migrating <a href="https://blog.simshadows.com/">my old blog</a> to this website.</em></p>
1721

22+
<ul>
23+
{
24+
allPosts.map((post) => (
25+
<li><a href={`/blog/${post.id}/`}>{post.data.title}</a></li>
26+
))
27+
}
28+
</ul>
29+
1830
</Layout>
1931

0 commit comments

Comments
 (0)