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

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/"
+++

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!

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

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