Rationalise, and make like astro-blog
Posted on 29th May 2026 at 11:36 by Admin
Objectives
After working with astro-blog for some time I’ve got used to the idea of a posts collection, and rathe like it.
I hadn’t realised that astro-test has a posts collection, but the way it’s set up is slightly odd.
The collection is in /src/content/posts. So far so normal, but posts are reached with site-url/post/post-slug, not site-url/posts/post-slug. I vaguely remember setting this up deliberately, but I think the generalisation is counter-productive. So lets get back to site-url/posts/post/slug.
Routing
astro-blog
blog
├── author
│ └── [author].astro
├── category
│ └── [category].astro
├── index.astro
├── [...slug].astro
├── tag
│ └── [tag].astro
└── [year]
└── [month].astro
astro-test
post
└── [...slug].astro
posts
├── author
│ └── [author].astro
├── category
│ └── [category].astro
├── index.astro
├── select-posts.astro
├── [...slug].astro
├── tag
│ └── [tag].astro
└── [year]
└── [month].astro
After fixing post/[…slug].astro to use the posts collection, posts were accesible via site-url/posts/post/slug OR site-url/post/post/slug. The /post branch was deleted.
/src/components/PostList.astro was changed to <a href={/posts/${post.id}/}>{post.data.title}</a> from /post, so posts in post lists had the new url.
Search was generating the old url. Change in /src/pages/search.json.js