all repos — vite @ 55ee643427df6d011b2ed05ccc892301034ba437

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
10type ConfigYaml struct {
11	Title  string `yaml:"title"`
12	Desc   string `yaml:"description"`
13	Author struct {
14		Name  string `yaml:"name"`
15		Email string `yaml:"email"`
16	} `yaml:"author"`
17	URL       string   `yaml:"url"`
18	Prebuild  []string `yaml:"prebuild"`
19	Postbuild []string `yaml:"postbuild"`
20}
21
22var Config ConfigYaml
23
24func init() {
25	cf, err := os.ReadFile("config.yaml")
26	if err != nil {
27		fmt.Fprintf(os.Stderr, "error: %+v\n", err)
28		os.Exit(1)
29	}
30	if err = Config.ParseConfig(cf); err != nil {
31		fmt.Fprintf(os.Stderr, "error: %+v\n", err)
32	}
33}
34
35func (c *ConfigYaml) ParseConfig(cf []byte) error {
36	err := yaml.Unmarshal(cf, c)
37	return err
38}