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

hugolib: improve menu generation for section pages with content #2978

Closed
wants to merge 3 commits into from

Conversation

aroig
Copy link
Contributor

@aroig aroig commented Jan 22, 2017

When using the lazy blogger setting to automatically generate menu entries from section pages, we now recognize section pages that have content, and use the weight and linktitle configured in the frontmatter.

This way, we can use the lazy blogger automatic generation, and influence menu order and translations, directly from the frontmatter.

Fixes #2974

Copy link
Member

@bep bep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very useful, but needs a test or two.

hugolib/site.go Outdated
URL: p.RelPermalink()}

// menu with same id defined in config, let that one win
if _, ok := flat[twoD{sectionPagesMenu, me.KeyName()}]; ok {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conditional can be pulled above the me above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I can squash all the commits if you wish, once we finish reviewing.

hugolib/site.go Outdated
if sectionPagesMenu != "" {
// Create menu entries for section pages with content
for _, p := range pages {
if p.Section() != "" && p.Kind == KindSection {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why check for p.Section()? Every page have a Kind -- and all section pages (with or without content) == KindSection.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check for p.Section() was already there before I touched it. You do not want to synthesize a section menu entry for the empty string, and that would happen if there are pages that do not belong to a section.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry, in this case you are right, on the second pass is when this test is supposed to be relevant.

}
}

// Create entries for remaining content-less section pages
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean by "content-less" section pages? The code below should be superfluous with the code above.

Copy link
Contributor Author

@aroig aroig Feb 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest... I forgot most of it.

This piece of code was kind of ugly. It ran through all pages, collecting a list of all sections they belong to, and from this collection of section, synthesized menu entries.

What I remember, is that I thought I could do better, by running through all section pages, and assembling the menu entry via some method in Page, using the actual section page metadata. It didn't work, it turns out there was a reason for doing the old ugly thing. Probably content-less section pages are not yet there when the menu is assembled. Oh, by content-less I mean without a markdown file under content/.

Then I ended up refining the old method, by using the section page if it is there, and doing the old thing of synthesizing a menu entry for mentioned sections (not actual section pages) otherwise.

Maybe you, that are more familiar with the code can fill in the blanks. Otherwise I can try squeeze my brain a little more and see if anything else comes out.

When using the lazy blogger setting to automatically generate menu
entries from section pages, we now recognize section pages that have
content, and use the weight and linktitle configured in the frontmatter.

This way, we can use the lazy blogger automatic generation, and
influence menu order and translations, directly from the frontmatter.

Fixes gohugoio#2974
@aroig
Copy link
Contributor Author

aroig commented Feb 19, 2017

I'll try to add some tests tomorrow. Thanks for looking into this!

@bep
Copy link
Member

bep commented Feb 20, 2017

I will finish this ins #3067

I'll need to do some general test cleanup in this department, and I might as well clean up after myself.

Thanks for starting this and bringing this to my attention.

@bep bep closed this Feb 20, 2017
@aroig
Copy link
Contributor Author

aroig commented Feb 20, 2017

Thanks! I'll try to do some testing of master before the upcoming release.

@github-actions
Copy link

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.

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

Successfully merging this pull request may close these issues.

Menu weight and linktitle should be inherited from the front-matter in section pages with content
2 participants