From 3a86f0f7e6b0e2d9f3c2c85d4a10d577b2d8e31b Mon Sep 17 00:00:00 2001 From: mntn <85877297+mntn-xyz@users.noreply.github.com> Date: Tue, 31 Aug 2021 15:06:23 -0400 Subject: [PATCH] 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. --- cmd/gmnhg/main.go | 7 ++++++- render.go | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/gmnhg/main.go b/cmd/gmnhg/main.go index 11408f8..472bfa5 100644 --- a/cmd/gmnhg/main.go +++ b/cmd/gmnhg/main.go @@ -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 diff --git a/render.go b/render.go index 4c5aa68..f60680d 100644 --- a/render.go +++ b/render.go @@ -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.