Skip to content

Commit

Permalink
Support Hugo headless page bundle leaf nodes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mntn-xyz committed Aug 31, 2021
1 parent ea62886 commit 3a86f0f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cmd/gmnhg/main.go
Expand Up @@ -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,
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions render.go
Expand Up @@ -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.
Expand Down

0 comments on commit 3a86f0f

Please sign in to comment.