Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repeated use of :sections breaks permalink #10377

Closed
stefanv opened this issue Oct 13, 2022 · 7 comments · Fixed by #10627
Closed

Repeated use of :sections breaks permalink #10377

stefanv opened this issue Oct 13, 2022 · 7 comments · Fixed by #10627
Assignees
Milestone

Comments

@stefanv
Copy link

stefanv commented Oct 13, 2022

Using this setting:

permalinks:
  posts: "/:sections[1]/:sections[last]"

I expect output paths of the form /section_one/section_last/index.html, but instead a lot of files are published to the root of the public folder.

Using other variables work fine, e.g.:

  posts: "/:sections[1]/:section"

What version of Hugo are you using (hugo version)?

hugo v0.104.3-58b824581360148f2d91f5cc83f69bd22c1aa331 linux/amd64 BuildDate=2022-10-04T14:25:23Z VendorInfo=gohugoio

Does this issue reproduce with the latest release?

Yes

@jmooring
Copy link
Member

jmooring commented Nov 4, 2022

Clarification...

First, the permalinks setting in site configuration does not apply to section pages. See this proposal.

Second, the permalink needs to be unique for each page, otherwise one page will clobber another.

Example 1 - Bad (demonstrates pages being clobbered)

content/
├── posts/
│   ├── _index.md
│   ├── post-1.md
│   ├── post-2.md
│   └── post-3.md
└── _index.md

site configuration

[permalinks]
posts = '/:sections[1]/:sections[last]'  # this will not be unique for each page

command

$ hugo --printPathWarnings

WARN 2022/11/04 12:29:29 Duplicate target paths: /index.html (4)

$ tree public

public/
├── posts/
│   └── index.html
└── index.html

Example 2 - Good (but demonstrates the bug)

content/
├── posts/
│   ├── _index.md
│   ├── post-1.md
│   ├── post-2.md
│   └── post-3.md
└── _index.md

site configuration

[permalinks]
posts = '/:sections[1]/:sections[last]/:slug'

command

$ hugo --printPathWarnings
$ tree public

public/
├── post-1/
│   └── index.html
├── post-2/
│   └── index.html
├── post-3/
│   └── index.html
├── posts/
│   └── index.html
└── index.html

The issue as reported is valid, as these files are dumped in the root instead of in a section.

@stefanv
Copy link
Author

stefanv commented Nov 4, 2022

I still don't think the original behavior is correct, despite resulting in non-unique filenames.

@jmooring
Copy link
Member

jmooring commented Nov 4, 2022

@stefanv That's why I wrote

The issue as reported is valid

@jmooring
Copy link
Member

jmooring commented Nov 4, 2022

Minimal reproducible example:

git clone --single-branch -b hugo-github-issue-10377 https://github.com/jmooring/hugo-testing hugo-github-issue-10377
cd hugo-github-issue-10377
hugo && tree public
content/
├── posts/
│   ├── foo/
│   │   ├── bar/
│   │   │   ├── baz/
│   │   │   │   ├── _index.md
│   │   │   │   ├── post-1.md
│   │   │   │   ├── post-2.md
│   │   │   │   └── post-3.md
│   │   │   └── _index.md
│   │   └── _index.md
│   └── _index.md
└── _index.md

site config

[permalinks]
posts = '/:sections[1]/:sections[last]/:slug'

Expected output:

public/
├── foo/
│   └── baz/
│       ├── post-1/
│       │   └── index.html
│       ├── post-2/
│       │   └── index.html
│       └── post-3/
│           └── index.html
├── posts/
│   ├── foo/
│   │   ├── bar/
│   │   │   ├── baz/
│   │   │   │   └── index.html
│   │   │   └── index.html
│   │   └── index.html
│   └── index.html
└── index.html

Actual output:

public/
├── post-1/
│   └── index.html
├── post-2/
│   └── index.html
├── post-3/
│   └── index.html
├── posts/
│   ├── foo/
│   │   ├── bar/
│   │   │   ├── baz/
│   │   │   │   └── index.html
│   │   │   └── index.html
│   │   └── index.html
│   └── index.html
└── index.html

@bep bep added this to the v0.106.0 milestone Nov 4, 2022
@bep
Copy link
Member

bep commented Nov 4, 2022

Yea, it's a bug and it will be fixed soonish.

@stefanv
Copy link
Author

stefanv commented Nov 4, 2022

valid

Apologies, @jmooring, I missed that last sentence.

@bep bep modified the milestones: v0.106.0, v0.107.0 Nov 18, 2022
@bep bep modified the milestones: v0.107.0, v0.108.0 Dec 3, 2022
@bep bep modified the milestones: v0.108.0, v0.109.0 Dec 14, 2022
@bep bep self-assigned this Jan 17, 2023
bep added a commit to bep/hugo that referenced this issue Jan 17, 2023
bep added a commit that referenced this issue Jan 17, 2023
@github-actions
Copy link

github-actions bot commented Feb 8, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants