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

Add Permalink option for section pages #8523

Closed
writeonlycode opened this issue May 11, 2021 · 21 comments · Fixed by #10847
Closed

Add Permalink option for section pages #8523

writeonlycode opened this issue May 11, 2021 · 21 comments · Fixed by #10847

Comments

@writeonlycode
Copy link

writeonlycode commented May 11, 2021

I have something like the following option in the config.toml:

[permalinks]
posts = "/new-posts/:filename/"

If I visit http://localhost:1313/new-posts/post-name/ I get the intended page. But if I visit http://localhost:1313/new-posts/ I don't get the list page, as I would expect. Instead, I get nothing at all. I still have to go to http://localhost:1313/posts/ to get the list page.

The version I'm using:

hugo v0.83.1+extended linux/amd64 BuildDate=unknown

I'm not sure if this behavior is intended. But it would be a good idea to have the ability to change the URL of the list pages using the permalinks option as well. Right now, I have to add the url parameter in the front matter of the _index.md to make the list page have the different url.

@bep
Copy link
Member

bep commented May 11, 2021

I'm not sure if this behavior is intended.

It is.

@writeonlycode
Copy link
Author

I see. Maybe this should be a feature request, then? It would be quite helpful for me at least to be able to change the URL of the list pages using some option similar to the permalinks option.

@bep
Copy link
Member

bep commented May 11, 2021

I see. Maybe this should be a feature request, then?

It behaves like it is for a reason -- I don't see how you could translate the permalink config to work for list pages, but I would be happy to be proven wrong.

@writeonlycode
Copy link
Author

I don't really know how it works behind the scenes. But we already have the ability to change the URL of list pages. We just have to use the url parameter in their front matter. The "problem" I'm having is that I want to change the whole folder to a different URL, so, on top of adding the permalinks option, I also have to add the url in all _index.md files in that folder and subfolders. The proposal would be to have an option to add to the config.toml that does this job of "adding the url option to all list pages". Not a huge problem really, but it would be convenient.

@bep
Copy link
Member

bep commented May 11, 2021

So, on the technical side this isn't a problem.

But it's a permalink config, so they should be ... permanent. And the only permanent part of a section is the ... section path.

Given 2 common examples (assuming no date is set in section front matter):

[permalinks]
  "posts" = "/:year/:month/:filename/"
[permalinks]
  posts = "/:06/:1/:2/:title/"

How stable would the above be? And would it be a good URL?

@writeonlycode
Copy link
Author

Right. I suppose it would be necessary to have different options for single pages vs. list pages. Something like the following for list pages:

[permalinks.sections]
posts = "/some/new/path/"

It could support the :year, :month and such as well, even if these options would not be terribly useful in regular use cases. Then the current permalinks option could stay as it is, and this new option would change the url of the list pages.

@bep bep added this to the v0.84 milestone May 12, 2021
@bep bep changed the title Permalink option in config.toml not working for list pages Add Permalink option for sections May 12, 2021
@bep
Copy link
Member

bep commented May 12, 2021

@writeonlycode yes, something like that could work, but we need to somehow rework the existing permalinks struct in a backwards compatible way (we're not adding something ... else)... I suggest we somehow use the page Kind. I'm not sure if this is even valid TOML, but:

[permalinks]
[permalinks.section]
posts = "/some/new/path/"
[permalinks.page]
posts = "/:06/:1/:2/:title/"

@writeonlycode
Copy link
Author

writeonlycode commented May 12, 2021

That looks good! And it is valid TOML as far as I can see. I suppose the assumption should be that if no kind is specified, it defaults to single pages, so the following two should be equivalent:

[permalinks]
posts = "/:06/:1/:2/:title/"
[permalinks]
[permalinks.page]
posts = "/:06/:1/:2/:title/"

In this way, it will be backwards compatible. And in addition to those, we could have the section option, to accommodate the new behavior:

[permalinks]
[permalinks.section]
posts = "/some/new/path/"

This looks like a good way to go!

@bep bep modified the milestones: v0.84, v0.85 Jun 18, 2021
@bep bep modified the milestones: v0.85, v0.86 Jul 5, 2021
@bep bep modified the milestones: v0.86, v0.87, v0.88 Jul 26, 2021
@bep bep modified the milestones: v0.88, v0.89 Sep 2, 2021
@bep bep modified the milestones: v0.89, v0.90 Nov 2, 2021
@bep bep modified the milestones: v0.90, v0.91.0 Dec 13, 2021
@bep bep modified the milestones: v0.91.0, v0.92.0 Dec 22, 2021
@bep bep modified the milestones: v0.92.0, v0.93.0 Jan 12, 2022
@Mai-Lapyst
Copy link
Contributor

Since this was a major deal-breaker I worked on a patch for this; here's the branch in my fork for anyone interested: https://github.com/Mai-Lapyst/hugo/tree/allow-permalinks-conf-for-branchbundles
Can also open a PR if wanted.

Works currently with permalinks configs like

[permalinks]
  docs = "/docs/1.0/:sections[1:]/:filename"

And even when using :slug, :slugorfilename or :title.

@istr
Copy link

istr commented Mar 16, 2023

@Mai-Lapyst I think that a PR would be highly welcome.

Mai-Lapyst added a commit to Mai-Lapyst/hugo that referenced this issue Mar 17, 2023
…iguration

Allows using permalink configuration for sections (branch bundles) and
also for taxonomy pages. Extends the current permalink configuration to
be able to specified per page kind while also staying backward compatible:
all permalink patterns not dedicated to a certain kind, get automatically
added for both normal pages and term pages.

Fixes gohugoio#8523
@Mai-Lapyst
Copy link
Contributor

@Mai-Lapyst I think that a PR would be highly welcome.

@istr Have created one; you can test it out if you want.

Mai-Lapyst added a commit to Mai-Lapyst/hugo that referenced this issue Mar 18, 2023
…iguration

Allows using permalink configuration for sections (branch bundles) and
also for taxonomy pages. Extends the current permalink configuration to
be able to specified per page kind while also staying backward compatible:
all permalink patterns not dedicated to a certain kind, get automatically
added for both normal pages and term pages.

Fixes gohugoio#8523
Mai-Lapyst added a commit to Mai-Lapyst/hugo that referenced this issue Mar 19, 2023
…iguration

Allows using permalink configuration for sections (branch bundles) and
also for taxonomy pages. Extends the current permalink configuration to
be able to specified per page kind while also staying backward compatible:
all permalink patterns not dedicated to a certain kind, get automatically
added for both normal pages and term pages.

Fixes gohugoio#8523
Mai-Lapyst added a commit to Mai-Lapyst/hugo that referenced this issue Mar 19, 2023
…iguration

Allows using permalink configuration for sections (branch bundles) and
also for taxonomy pages. Extends the current permalink configuration to
be able to specified per page kind while also staying backward compatible:
all permalink patterns not dedicated to a certain kind, get automatically
added for both normal pages and term pages.

Fixes gohugoio#8523
Mai-Lapyst added a commit to Mai-Lapyst/hugo that referenced this issue Mar 19, 2023
…iguration

Allows using permalink configuration for sections (branch bundles) and
also for taxonomy pages. Extends the current permalink configuration to
be able to specified per page kind while also staying backward compatible:
all permalink patterns not dedicated to a certain kind, get automatically
added for both normal pages and term pages.

Fixes gohugoio#8523
@bep bep modified the milestones: v0.112.0, v0.113.0 Apr 15, 2023
Mai-Lapyst added a commit to Mai-Lapyst/hugo that referenced this issue May 26, 2023
…iguration

Allows using permalink configuration for sections (branch bundles) and
also for taxonomy pages. Extends the current permalink configuration to
be able to specified per page kind while also staying backward compatible:
all permalink patterns not dedicated to a certain kind, get automatically
added for both normal pages and term pages.

Fixes gohugoio#8523
@bep bep modified the milestones: v0.113.0, v0.115.0 Jun 13, 2023
bep pushed a commit that referenced this issue Jun 26, 2023
…configuration

Allows using permalink configuration for sections (branch bundles) and
also for taxonomy pages. Extends the current permalink configuration to
be able to specified per page kind while also staying backward compatible:
all permalink patterns not dedicated to a certain kind, get automatically
added for both normal pages and term pages.

Fixes #8523
jmooring added a commit to jmooring/hugo that referenced this issue Jun 26, 2023
bep pushed a commit that referenced this issue Jun 27, 2023
bep added a commit to bep/hugo that referenced this issue Jun 28, 2023
bep added a commit to bep/hugo that referenced this issue Jun 28, 2023
bep added a commit to bep/hugo that referenced this issue Jun 28, 2023
bep added a commit to bep/hugo that referenced this issue Jun 28, 2023
bep added a commit to bep/hugo that referenced this issue Jun 29, 2023
* Move config loading to the page package
* Fix a lower bound panic for the `:sections` slice syntax.
* Always return the `:title`
* Add some permalinks integration tests
* Also see issues below

Fixes gohugoio#9448
Fixes gohugoio#11184
See gohugoio#8523
bep added a commit to bep/hugo that referenced this issue Jun 29, 2023
* Move config loading to the page package
* Fix a lower bound panic for the `:sections` slice syntax.
* Always return the `:title`
* Add some permalinks integration tests
* Also see issues below

Fixes gohugoio#9448
Fixes gohugoio#11184
See gohugoio#8523
bep added a commit that referenced this issue Jun 29, 2023
* Move config loading to the page package
* Fix a lower bound panic for the `:sections` slice syntax.
* Always return the `:title`
* Add some permalinks integration tests
* Also see issues below

Fixes #9448
Fixes #11184
See #8523
@github-actions
Copy link

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 Jul 18, 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.

10 participants