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.
This commit is contained in:
parent
d8870403fe
commit
af021e9ae1
1 changed files with 17 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue