-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
resources/page: Allow section&taxonomy pages to have a permalink configuration #10847
resources/page: Allow section&taxonomy pages to have a permalink configuration #10847
Conversation
@Mai-Lapyst I did some quick testing and the first thing I found was... If an _index.md does not exist for a top level section, the permalink setting is not applied. It is somewhat common to not create an _index.md for top-level content sections, and very common to not create an _index.md file for taxonomy or term pages.
But with this I get the desired result:
|
1f25526
to
fb35e7f
Compare
@jmooring Thanks for the feedback. Turns out that the if around the expand is completly redundant now. Removed it and it works like intended. Also added some debug logging to verify that the permalink for any given file/section is set and to what value exactly. ( |
Nice! I spent a couple of hours testing this, and functionally it looks great. It behaves as expected:
FYI, when I run |
Thanks!
I noticed that too; digged a bit into it and you can get the same crash even in the patched version, by simply using an empty string:
It seems that an unchecked string slice access seems to be the problem: hugo/resources/page/permalinks.go Lines 259 to 260 in fb35e7f
Will add a patch for it as well. |
4636e32
to
2306a9f
Compare
@bep Functionally this is great, and scratches a long-term itch. Would appreciate a review if/when you have the chance. |
OK, I guess this is what lots of people would want, and I like the config. I will merge this if we could
|
…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
2306a9f
to
9caaf86
Compare
@bep Thanks for looking over it. Have rebased it onto master and reworked it to work with the new allconfig. Also added a test for it; let me know if more tests are needed. |
@@ -93,6 +93,7 @@ const ( | |||
ContentClassBranch ContentClass = "branch" | |||
ContentClassFile ContentClass = "zfile" // Sort below | |||
ContentClassContent ContentClass = "zcontent" | |||
ContentClassZero ContentClass = "zero" // Special value for zeroFile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need/want this. A zero file would have an empty ContentClass string, which is the natural zero value, no need to make one up.
desc.ExpandedPermalink = opath | ||
|
||
if !p.File().IsZero() { | ||
s.Log.Debugf("Set expanded permalink path for %s %s to %#v", p.Kind(), p.File().Path(), opath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove these debug statement, it makes the debug log very busy,.
// [permalinks.key] | ||
// xyz = ??? | ||
|
||
if (k == "page") || (k == "section") || (k == "taxonomy") || (k == "term") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can use the constants in pagekinds.Page
etc.
p.c.Permalinks = maps.CleanConfigStringMapString(p.p.GetStringMapString(d.key)) | ||
p.c.Permalinks = make(map[string]map[string]string) | ||
|
||
p.c.Permalinks["page"] = make(map[string]string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pagekinds.Page etc.
@@ -69,6 +69,7 @@ func TestPermalinkExpansion(t *testing.T) { | |||
page.date = d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all looks good, but I think we need a test that shows the new setup working. I suggest you create a new permalink_integration_test.go
and follow the the cue of similar tests (using the NewIntegrationTest...) that tests the new permalink setup in a site build.
Never mind the comments above. I suspect we need to test this out on some real projects and then do some adjustments/add some tests, so I might as well merge this early. |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
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
Example config: