urlhugostatic-site

How can I setup my hugo url so I can list all desired urls under a certain URL path?


I have a urls like this:

https://mfaani.com/posts/foo/bar
https://mfaani.com/posts/foo/baz
https://mfaani.com/posts/foo/qud

I want users to be able to see all my "foo" blog posts at the following URL:

https://mfaani.com/posts/foo or perhaps https://mfaani.com/foo

But that returns a 404.

Is there a way to achieve this?


Solution

  • It's actually very simple.

    Under the https://mfaani.com/posts/foo/ just add an empty _index.md file.

    That will then add all your posts for that category.

    Note:

    It's good idea to add frontmatter to the _index.md page. Because if you've nested one directory in another, then it will use the _index.md of the subdirectory to know how to include the description of the subdirectory the list page.

    For example if the _index.md is empty then you'll see:

    enter image description here


    Alternatively if you add the following frontmatter, then you'll see something like the following:

    ---
    Title: '⚡️ SERIES -  Optimizing App Size'
    ---
    
    A description of the post goes here. 
    

    enter image description here