#How to implement taxonomies (tagging)?

5 messages · Page 1 of 1 (latest)

worldly fiber
#

I have blog content in the form of 1000+ markdown files w/ frontmatter metadata. Can Astro build taxonomy (tag) pages from these files?

For example, if there are two posts with tag "vue", and three tagged "typescript", we'd have /tags/vue/ that listed two posts and /tags/typescript/ that listed three. (And /tags/ that would list all the tags used in all the posts.) Is this doable with Astro? If not right now, can it be done as an integration? Couldn't find anything from the docs, repo, or here via search.

chrome blade
#

Hi, welcome to Astro-land!

Here's an older archived thread which provides an overview of the approach you should use: https://discord.com/channels/830184174198718474/1018914253656297532

You'll want to take a look at the 'Dynamic Routes' section of the Routing docs: https://docs.astro.build/en/core-concepts/routing/#dynamic-routes, particularly the getStaticPaths function. This is what you will use to generate all of your /tags/[tag]/ routes.

Then to populate those pages with the correct posts, you'll need to use Astro.glob() , then filter by your tag: https://docs.astro.build/en/reference/api-reference/#astroglob

Astro Documentation

Build faster websites with less client-side Javascript.

Astro Documentation

An intro to routing with Astro.

worldly fiber
#

Cool, looks good -- thanks! 👍

chrome blade
#

(Note that their normalizePosts function is not standard Astro stuff, so you don't need to incorporate that)