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
This commit is contained in:
satnaing
2025-03-16 20:09:03 +07:00
committed by Sat Naing
parent 67b9536cce
commit feaf5e122a
19 changed files with 64 additions and 39 deletions
+5 -6
View File
@@ -1,17 +1,16 @@
---
import { slugifyStr } from "@/utils/slugify";
import type { CollectionEntry } from "astro:content";
import { getPath } from "@/utils/getPath";
import Datetime from "./Datetime.astro";
export interface Props {
export interface Props extends CollectionEntry<"blog"> {
variant?: "h2" | "h3";
href?: string;
frontmatter: CollectionEntry<"blog">["data"];
}
const { href, frontmatter, variant = "h2" } = Astro.props;
const { variant = "h2", data, id, filePath } = Astro.props;
const { title, pubDatetime, modDatetime, description } = frontmatter;
const { title, pubDatetime, modDatetime, description } = data;
const headerProps = {
style: { viewTransitionName: slugifyStr(title) },
@@ -21,7 +20,7 @@ const headerProps = {
<li class="my-6">
<a
href={href}
href={getPath(id, filePath)}
class="inline-block text-lg font-medium text-accent decoration-dashed underline-offset-4 focus-visible:no-underline focus-visible:underline-offset-0"
>
{