Best practice to remove section from URL

Hi!

I have a content folder structure like that:

  • section-1
    • latest-infos
      • info-1
      • info-2
    • older-infos
      • info-a
      • info-b

It would be good if that is generated to the following URLs:

/latest-infos/
/latest-infos/info-1/
/latest-infos/info-2/
/older-infos/
/older-infos/info-a/
/older-infos/info-b/

Is there straight forward practice to achieve that? I had no luck with β€œpermalinks” in config.yaml.

Thanks!

Here’s one way to accomplish this.

Given content structure like you mentioned:

content/
└── section-1
    β”œβ”€β”€ latest-infos
    β”‚   β”œβ”€β”€ info-1
    β”‚   β”‚   └── index.md
    β”‚   └── info-2
    β”‚       └── index.md
    └── older-infos
        β”œβ”€β”€ info-a
        β”‚   └── index.md
        └── info-b
            └── index.md

You could define a slug front matter param in each index.md file. For example:

---
title: "Info 1"
slug: /latest-infos/
---

Then in your config.yaml:

permalinks:
  section-1: /:slug/:title/

Then when building your site, the structure would be like:

public/
β”œβ”€β”€ latest-infos
β”‚   β”œβ”€β”€ info-1
β”‚   β”‚   └── index.html
β”‚   └── info-2
β”‚       └── index.html
β”œβ”€β”€ older-infos
β”‚   β”œβ”€β”€ info-a
β”‚   β”‚   └── index.html
β”‚   └── info-b
β”‚       └── index.html
1 Like

You could also try to use the url parameter in the front matter of your nested sections’ _index.md as well as in your content files.
e.g.

+++
url = "/latest-infos/"
+++
2 Likes

Thanks for your help. I guess there is no solution without specifying something in every front matter?

@zwbetz’s solution only involves the sections’ Front Matter though. Your pages’ can remain unchanged.

Tried that but that doesnt work. @zwbetz also mentioned β€œin each index.md file”.

@cvh does your content look like this?

 content/
└── section-1
    β”œβ”€β”€ latest-infos
    β”‚   β”œβ”€β”€ info-1
    β”‚   β”‚   └── index.md
    β”‚   └── info-2
    β”‚       └── index.md
    └── older-infos
        β”œβ”€β”€ info-a
        β”‚   └── index.md
        └── info-b
            └── index.md

@zwbetz Yes. There are also _index.md in latest-infos and older-infos. But that shouldn’t make a difference, right?.

Hmm, it works fine on my end.

You’ve added the permalink setting to your config file?

use archetypes!

slug: /latest-infos/

will be copied from archetype to content file!

1 Like

If I specify the slug in every index.md it works. Would be nice to have it specified only at one place :slight_smile:

Yes, thanks. Good idea. But if i want to change it later, I have to replace it in every file (still better than to specify slug always manually, no doubt).

Text editors these days (vscode, atom, etc.) make find-n-replace like that easy

1 Like

Yes you are right. I’ll take this approach. Thank you all for your quick help!