From af021e9ae16a4a6b855c784f6683d75e177271d0 Mon Sep 17 00:00:00 2001 From: Timur Demin Date: Fri, 13 Aug 2021 10:11:44 +0500 Subject: [PATCH] Allow for YAML/JSON Hugo config Hugo allows storing config in either config.toml, config.json, or config.yaml, while gmnhg previously only checked for config.toml. Fixes #7. --- cmd/gmnhg/main.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/cmd/gmnhg/main.go b/cmd/gmnhg/main.go index f21637b..67dceaf 100644 --- a/cmd/gmnhg/main.go +++ b/cmd/gmnhg/main.go @@ -61,12 +61,18 @@ // config option in config.toml: // // ignoreFiles = [ "_index\\.gmi\\.md$" ] +// +// Limitations: +// +// * For now, the program will only recognize YAML front matter, while +// Hugo supports it in TOML, YAML, JSON, and org-mode formats. package main import ( "bytes" "errors" "flag" + "fmt" "io" "io/ioutil" "os" @@ -97,6 +103,8 @@ var ( topLevelPostRegex = regexp.MustCompile(contentBase + `([\w-_ ]+)/([\w-_ ]+)\.md`) ) +var hugoConfigFiles = []string{"config.toml", "config.yaml", "config.json"} + type post struct { Post []byte Metadata gemini.HugoMetadata @@ -165,8 +173,15 @@ func main() { } } - if fileInfo, err := os.Stat("config.toml"); os.IsNotExist(err) || fileInfo.IsDir() { - panic("config.toml either doesn't exist or is a directory; not in a Hugo site dir?") + configFound := false + for _, filename := range hugoConfigFiles { + if fileInfo, err := os.Stat(filename); !(os.IsNotExist(err) || fileInfo.IsDir()) { + configFound = true + break + } + } + if !configFound { + panic(fmt.Errorf("no Hugo config in %v found; not in a Hugo site dir?", hugoConfigFiles)) } // build templates