I’m trying to replicate an existing site, most things are pretty easy so far, but I’m having a hard time to customize the URL.
The site I work on contains nothing but posts, not really blog posts, but that doesn’t matter.
Each page is found at /category/post-slug/, something like
/landscape/lovely-water
/buildings/nice-house
/buildings/nicer-house
I can do that if I create multiple blog pages for each category, but that’s not really what I’m looking for. I’d like to have a flat list of posts in a single directory and assign each post a category which is then used in the URL.
Can anyone point me in the right direction? Thanks!
The URL is tied pretty closely to the structure of your site. This is how Grav maintains its simplicity. You can change the ‘slug’ of a page but this is only the slug for the page itself, not the entire URL path. You have a couple of options though.
Probably the best approach is to create your Grav site as you have been, by keeping it flat, and using taxonomy for for category. Then use .htaccess rules to redirect posts to your old URL format to the new one. This way you are not hampered by the old structure, but old links still work.
Another approach that is similar is to use the Grav routes: capability to do the same thing but with grav handling those redirects for you. More information in the site.yaml configuration section.
The problem with each of these approaches is that they are sort of static, and you would need to put an entry in for each post. You could however create a plu gin that did the same thing as the routes and dynamically did the redirect for you. This is slightly more involved but should be doable, and would be automatic.
Thanks for the suggestions! I missed the routes part in the documentation, I think I’ll fiddle around with that and see if it works and if it doesn’t I’ll try to improve my ancient M4 skills