Skip to content

Commit

Permalink
Allow for YAML/JSON Hugo config
Browse files Browse the repository at this point in the history
Hugo allows storing config in either config.toml, config.json, or
config.yaml, while gmnhg previously only checked for config.toml.

Fixes #7.
  • Loading branch information
tdemin committed Aug 13, 2021
1 parent d887040 commit af021e9
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions cmd/gmnhg/main.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit af021e9

Please sign in to comment.