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 support for branch and leaf bundles #10

Merged
merged 17 commits into from Aug 17, 2021
Merged

Conversation

mntn-xyz
Copy link
Contributor

This patch adds support for Hugo's branch and leaf bundles: https://gohugo.io/content-management/page-bundles/

Content directories can now have nested subdirectories, and content from each level will be converted to Gemini. If a subdirectory has a file named index.md (or any index.* file per the footnote on the Hugo page) then it becomes a leaf bundle. For leaf bundles, only the generated index.gmi file will be passed up to parent directories as a page. The rest will be treated as "resources" that are not normally visible to pages in parent folders.

Each parent _index.md receives a list of pages from all nested subdirectories (except for the aforementioned leaf resource pages). This allows for content "rollup" pages. For instance, /series could show all pages under /series/first-season and /series/second-season, while allowing each subfolder to have its own more limited index. This also allows for "clean" URLs, as leaf bundles can be used to make pages that are basically just an index.md page under a named folder. You can then use the trimSuffix function (from sprig) in your gotmpl templates to clean up any links, by stripping "/index.md".

This patch also adds the copying of non-Markdown resource files from content directories, so that bundled resources can be pulled in. Theoretically if someone puts carefully named .gmi files in their content folder then this could cause a name collision, but you'd almost have to try to make that happen, so I didn't put in any checks for it. If this happens then any generated files with the same name are simply overwritten, so there's no serious harm done.

Hugo's leaf bundles support a special front matter attribute, "headless", which if set to true will cause the index.md file to be "invisible" and it will not be passed up to the parent. This is not currently implemented.

@mntn-xyz
Copy link
Contributor Author

I also wanted to mention that while leaf resource pages are gathered for use on the leaf index.md page, nothing is currently done with them and index.md doesn't have access to them during rendering. In the future, it might be a good idea to extend the template system to allow custom templates for leaf index.md pages. I'm not aware of an immediate use for this but I can imagine some sites finding a use for it.

@@ -150,6 +162,15 @@ func writeFile(dst string, contents []byte) error {
return nil
}

func hasSubPath(paths []string, path string) bool {
Copy link
Owner

Choose a reason for hiding this comment

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

Does your editor run gofmt on save? hasSubPath appears to be indented with spaces, whilst the rest of the code is done with tabs (as most Go code does).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I need to invest some time into my setup. I thought this was going to be a small change, a few lines at most, so I didn't even set up a proper environment... but hey, now I'm learning go, so that's a win. :)

@tdemin
Copy link
Owner

tdemin commented Aug 17, 2021

Overall, appears to be a great replacement for the existing top-level dir indexing logic. Thanks!

@tdemin tdemin merged commit c2f2386 into tdemin:master Aug 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants