How to setup a different slug types for different sections

My director structure is such
-content
|—blog
-----||—blog1
-----||—blog 2
|—ideas
-----||—ideas1
-----||—ideas 2
Resultantly my urls are
-example.com/blog/blog1
-example.com/ideas/ideas1
i.e. (domain) / (section) / (slug)

I want the url structure to continue like as it is, for one section i.e. blogs. -example.com/blog/blog1
However, set the URL structure for other just as the slug i.e. -example.com/ideas1 (domain) / (slug).

How do I achieve this ?

Try the code below in your configuration file (I found it today also and put it in one section of my theme).

[permalinks]
ideas = "/:sections[1:]/:slug/"

Read More

1 Like

Thanks much, this works like a marvel

However, I read the docs again and I think this should also work and be more efficient:

[permalinks]
<section name> = "/:slug/"

and adding /:sections[1:]/ seems a bit unnecessary to me

Would love to hear your thoughts about it ?

2 Likes

Yo are misunderstanding the docs. Slug is the last part of the URL which is what you set in your front matter (or it defaults to the title). So, the part you don’t want in your URL will appear. You should test your suggestion before you conclude what I shared is unnecessary to remove doubt (I did test and it does not work as you expected. Mine works though). You explicitly said

and that is what my solution does. Yours only shows title then slug.

If you have an even deeper hierarchy and you only want the last section you can also do:

[permalinks]    
    blog = '/:sections[last]/:slug/'

Content created under /blog/sub/subsub/ would have permalinks at /subsub/ instead of /sub/subsub/. This achieves the same as your solution for /blog/sub//sub/.

FYI, this doesn’t change the permalink for the section list page (e.g. /blog/sub/_index.md). I haven’t found a way to achieve this with permalinks but a workaround is manually changing the URL in that page’s frontmatter (url: sub).

Based on my understanding of the docs, url is relative to the root (domain). So, you are are correct about the sections. I went with url for my section pages.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.