Skip to content

Commit feaf5e1

Browse files
committed
feat: allow blog posts to be organized by subdirectories
Blog posts can now be structured into subdirectories, which determine their slugs. Example: - `/src/data/blog/2025/testing.md` → `/posts/2025/testing` Directories prefixed with `_` will be excluded from the slug. Example: - `/src/data/blog/_examples/tailwind-typography.md` → `/posts/tailwind-typography` Closes #470, #366
1 parent 67b9536 commit feaf5e1

19 files changed

Lines changed: 64 additions & 39 deletions

src/components/Card.astro

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
---
22
import { slugifyStr } from "@/utils/slugify";
33
import type { CollectionEntry } from "astro:content";
4+
import { getPath } from "@/utils/getPath";
45
import Datetime from "./Datetime.astro";
56
6-
export interface Props {
7+
export interface Props extends CollectionEntry<"blog"> {
78
variant?: "h2" | "h3";
8-
href?: string;
9-
frontmatter: CollectionEntry<"blog">["data"];
109
}
1110
12-
const { href, frontmatter, variant = "h2" } = Astro.props;
11+
const { variant = "h2", data, id, filePath } = Astro.props;
1312
14-
const { title, pubDatetime, modDatetime, description } = frontmatter;
13+
const { title, pubDatetime, modDatetime, description } = data;
1514
1615
const headerProps = {
1716
style: { viewTransitionName: slugifyStr(title) },
@@ -21,7 +20,7 @@ const headerProps = {
2120

2221
<li class="my-6">
2322
<a
24-
href={href}
23+
href={getPath(id, filePath)}
2524
class="inline-block text-lg font-medium text-accent decoration-dashed underline-offset-4 focus-visible:no-underline focus-visible:underline-offset-0"
2625
>
2726
{

src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const SITE = {
1212
showArchives: true,
1313
showBackButton: true, // show back button in post detail
1414
editPost: {
15-
url: "https://github.com/satnaing/astro-paper/edit/main/src/content/blog",
15+
url: "https://github.com/satnaing/astro-paper/edit/main/src/data/blog",
1616
text: "Suggest Changes",
1717
appendFilePath: true,
1818
},

src/content.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { defineCollection, z } from "astro:content";
22
import { glob } from "astro/loaders";
33
import { SITE } from "@/config";
44

5+
export const BLOG_PATH = "src/data/blog";
6+
57
const blog = defineCollection({
6-
loader: glob({ pattern: "**/[^_]*.md", base: "./src/data/blog" }),
8+
loader: glob({ pattern: "**/[^_]*.md", base: `./${BLOG_PATH}` }),
79
schema: ({ image }) =>
810
z.object({
911
author: z.string().default(SITE.author),
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pubDatetime: 2024-01-04T09:30:41.816Z
44
title: AstroPaper 4.0
55
slug: "astro-paper-v4"
66
featured: false
7-
ogImage: ../../assets/images/AstroPaper-v4.png
7+
ogImage: ../../../assets/images/AstroPaper-v4.png
88
tags:
99
- release
1010
description: "AstroPaper v4: ensuring a smoother and more feature-rich blogging experience."
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pubDatetime: 2025-03-08T08:18:19.693Z
33
title: AstroPaper 5.0
44
slug: astro-paper-v5
55
featured: true
6-
ogImage: ../../assets/images/AstroPaper-v5.png
6+
ogImage: ../../../assets/images/AstroPaper-v5.png
77
tags:
88
- release
99
description: "AstroPaper v5: keep the clean look, updates under the hood."

0 commit comments

Comments
 (0)