I have the following structure:
Front matter for each book:
date = ""
title = ""
description = "
genre = ""
With this in place, each book can be found at /books/filename/.
However, I’d like to change the URL for each file so it includes the
genre, a custom front matter variable that I’ve created and can be found in each file.
This is the structure I’d like: /books/genre/filename/
I know this can be achieved by changing the books content structure, but this is not something I want to do. Adding a slug to each file, not sure if this works, but even if it would, doesn’t seem optimal.
I’ve had a look at the docs, and it seems I need to configure permalinks, but it doesn’t seem to allow custom configuration values, like
Any suggestions on how I can achieve this structure?
Whenever I see words like “genre” or “type” or I immediately think of the taxonomy system. Would you consider doing something like this?
genre = "genres"
genres = "/books/:slug"
This would allow you to:
- Visit /books/science-fiction/ to see all the science fiction novels
- Visit /books/crime/ to see all the crime novels
- Visit /books/foo to see all the science fiction crime novels (presuming you built a list page for this)
The same book could appear on all three pages. For example, Altered Carbon is a science fiction mystery novel, and would have front matter such as:
title = "Altered Carbon"
author = "Richard K. Morgan"
genres = ["crime","science fiction"]
But the book itself would still have the URL /books/altered-carbon/.
Upon further consideration, do the same with authors:
author = "authors"
genre = "genres"
authors = "/books/author/:slug"
genres = "/books/genre/:slug"
title = "The Talisman"
authors = ["Stephen King", "Peter Straub"]
genres = ["fantasy", "horror"]
One book. Two authors. Two genres. And if you like Stephen King visit /books/author/stephen-king/ to see what else he’s written.
Thank you for the informative reply!
Interesting. I’ll need to take a closer look and see if there may be an issue with using taxonomies in my code. If not, then this seems to be an excellent approach.