all repos — vite @ 678fa38599dd50bf47e04e6440675b8e133b543c

a fast (this time, actually) and minimal static site generator

config/config.go (view raw)

 1package config
 2
 3import (
 4	"fmt"
 5	"os"
 6
 7	"gopkg.in/yaml.v3"
 8)
 9
10var Config ConfigYaml
11
12func init() {
13	err := Config.parseConfig()
14	if err != nil {
15		fmt.Fprintf(os.Stderr, "error: config: %+v\n", err)
16		os.Exit(1)
17	}
18}
19
20type ConfigYaml struct {
21	Title           string `yaml:"title"`
22	Desc            string `yaml:"description"`
23	DefaultTemplate string `yaml:"default-template"`
24	Author          struct {
25		Name  string `yaml:"name"`
26		Email string `yaml:"email"`
27	} `yaml:"author"`
28	URL string `yaml:"url"`
29	//	Prebuild  []string `yaml:"prebuild"`
30	//	Postbuild []string `yaml:"postbuild"`
31}
32
33func (c *ConfigYaml) parseConfig() error {
34	cf, err := os.ReadFile("config.yaml")
35	if err != nil {
36		return err
37	}
38	if err = yaml.Unmarshal(cf, c); err != nil {
39		return err
40	}
41	return nil
42}