cvh
November 28, 2018, 5:01pm
1
Hi!
I have a content folder structure like that:
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!
zwbetz
November 28, 2018, 5:26pm
2
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/"
+++
cvh
November 28, 2018, 11:41pm
4
Thanks for your help. I guess there is no solution without specifying something in every front matter?
regis
November 29, 2018, 12:07am
5
@zwbetz ’s solution only involves the sections’ Front Matter though. Your pages’ can remain unchanged.
cvh
November 29, 2018, 8:55am
6
Tried that but that doesnt work. @zwbetz also mentioned “in each index.md file”.
zwbetz
November 29, 2018, 1:13pm
7
@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
cvh
November 29, 2018, 1:19pm
8
@zwbetz Yes. There are also _index.md in latest-infos and older-infos. But that shouldn’t make a difference, right?.
zwbetz
November 29, 2018, 1:26pm
9
Hmm, it works fine on my end.
You’ve added the permalink setting to your config file?
ju52
November 29, 2018, 3:00pm
10
use archetypes!
slug: /latest-infos/
will be copied from archetype to content file!
cvh
November 30, 2018, 8:26am
11
If I specify the slug in every index.md it works. Would be nice to have it specified only at one place
cvh
November 30, 2018, 8:27am
12
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).
zwbetz
November 30, 2018, 1:13pm
13
Text editors these days (vscode, atom, etc.) make find-n-replace like that easy
cvh
November 30, 2018, 9:03pm
14
Yes you are right. I’ll take this approach. Thank you all for your quick help!