Support Hugo headless page bundle leaf nodes

With Hugo, a page bundle can be skipped from rendering if
it specifies headless = true in its front matter. This makes
gmnhg properly skip these pages from rendering.

Fixes #11.
This commit is contained in:
mntn 2021-08-31 15:06:23 -04:00 committed by GitHub
parent ea62886fca
commit 3a86f0f7e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View file

@ -278,6 +278,11 @@ func main() {
} else if err != nil {
return err
}
// skip headless leaves from rendering
isLeafIndex := info.Name() == "index.md"
if isLeafIndex && metadata.IsHeadless {
return nil
}
key := strings.TrimPrefix(strings.TrimSuffix(path, ".md"), contentBase) + ".gmi"
p := gmnhg.Post{
Post: gemText,
@ -288,7 +293,7 @@ func main() {
if matches := pagePathRegex.FindStringSubmatch(path); matches != nil {
dirs := strings.Split(matches[1], "/")
// only include leaf resources pages in leaf index
if info.Name() != "index.md" && hasSubPath(leafIndexPaths, path) {
if !isLeafIndex && hasSubPath(leafIndexPaths, path) {
topLevelPosts[matches[1]] = append(topLevelPosts[matches[1]], p)
} else {
// include normal pages in all subdirectory indices

View file

@ -36,6 +36,7 @@ type HugoMetadata struct {
PostIsDraft bool `yaml:"draft"`
PostLayout string `yaml:"layout"`
PostDate time.Time `yaml:"date"`
IsHeadless bool `yaml:"headless"`
}
// Title returns post title.