all repos — vite @ 8aa214da3df13539a3a49b93f86ed5b046550c80

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

frontmatter.go (view raw)

 1package main
 2
 3import (
 4	"bytes"
 5	"github.com/adrg/frontmatter"
 6	"time"
 7)
 8
 9type Date8601 struct {
10	time.Time
11}
12
13func (d *Date8601) UnmarshalYAML(unmarshal func(interface{}) error) error {
14	var date string
15
16	err := unmarshal(&date)
17	if err != nil {
18		return err
19	}
20
21	d.Time, err = time.Parse("2006-01-02", date)
22	return err
23}
24
25type Matter struct {
26	Template string   `yaml:"template"`
27	URL      string   `yaml:"url"`
28	Title    string   `yaml:"title"`
29	Subtitle string   `yaml:"subtitle"`
30	Date     Date8601 `yaml:"date"`
31	Body     string
32}
33
34// Parses frontmatter, populates the `matter` struct and
35// returns the rest
36func parseFrontmatter(inputBytes []byte) ([]byte, Matter) {
37	m := Matter{}
38	input := bytes.NewReader(inputBytes)
39	rest, err := frontmatter.Parse(input, &m)
40
41	if err != nil {
42		printErr(err)
43	}
44	return rest, m
45}