fork of anirudh.fi/vite that uses chroma for hl
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add a new default-template config option

Also reworks config loading.

+34 -34
+9 -10
atom/feed.go
··· 52 52 // Creates a new Atom feed. 53 53 func NewAtomFeed(srcDir string, posts []markdown.Output) ([]byte, error) { 54 54 entries := []AtomEntry{} 55 - cfg := config.ConfigYaml{} 56 - cfg.ParseConfig() 55 + 57 56 for _, p := range posts { 58 57 dateStr := p.Meta["date"] 59 58 date, err := time.Parse("2006-01-02", dateStr) ··· 68 67 // tag:icyphox.sh,2019-10-23:blog/some-post/ 69 68 ID: fmt.Sprintf( 70 69 "tag:%s,%s:%s", 71 - cfg.URL[8:], // strip https:// 70 + config.Config.URL[8:], // strip https:// 72 71 dateStr, 73 72 filepath.Join(srcDir, p.Meta["slug"]), 74 73 ), 75 74 // filepath.Join strips the second / in http:// 76 - Link: &AtomLink{Href: cfg.URL + filepath.Join(srcDir, p.Meta["slug"])}, 75 + Link: &AtomLink{Href: config.Config.URL + filepath.Join(srcDir, p.Meta["slug"])}, 77 76 Summary: &AtomSummary{ 78 77 Content: fmt.Sprintf("<h2>%s</h2>\n%s", 79 78 p.Meta["subtitle"], ··· 88 87 now := time.Now().Format(time.RFC3339) 89 88 feed := &AtomFeed{ 90 89 Xmlns: "http://www.w3.org/2005/Atom", 91 - Title: cfg.Title, 92 - ID: cfg.URL, 93 - Subtitle: cfg.Desc, 94 - Link: &AtomLink{Href: cfg.URL}, 90 + Title: config.Config.Title, 91 + ID: config.Config.URL, 92 + Subtitle: config.Config.Desc, 93 + Link: &AtomLink{Href: config.Config.URL}, 95 94 Author: &AtomAuthor{ 96 - Name: cfg.Author.Name, 97 - Email: cfg.Author.Email, 95 + Name: config.Config.Author.Name, 96 + Email: config.Config.Author.Email, 98 97 }, 99 98 Updated: now, 100 99 Entries: entries,
+3 -16
commands/build.go
··· 72 72 73 73 out := markdown.Output{} 74 74 out.RenderMarkdown(fb) 75 - cfg := config.ConfigYaml{} 76 - if err := cfg.ParseConfig(); err != nil { 77 - return err 78 - } 79 75 if err = out.RenderHTML( 80 76 htmlFile, 81 77 TEMPLATES, ··· 83 79 Cfg config.ConfigYaml 84 80 Meta markdown.Matter 85 81 Body string 86 - }{cfg, out.Meta, string(out.HTML)}, 82 + }{config.Config, out.Meta, string(out.HTML)}, 87 83 ); err != nil { 88 84 return err 89 85 } ··· 131 127 132 128 out := markdown.Output{} 133 129 out.RenderMarkdown(fb) 134 - cfg := config.ConfigYaml{} 135 - if err := cfg.ParseConfig(); err != nil { 136 - return err 137 - } 138 - 139 130 if err = out.RenderHTML( 140 131 htmlFile, 141 132 TEMPLATES, ··· 143 134 Cfg config.ConfigYaml 144 135 Meta markdown.Matter 145 136 Body string 146 - }{cfg, out.Meta, string(out.HTML)}, 137 + }{config.Config, out.Meta, string(out.HTML)}, 147 138 ); err != nil { 148 139 return err 149 140 } ··· 170 161 } 171 162 out := markdown.Output{} 172 163 out.RenderMarkdown(indexMd) 173 - cfg := config.ConfigYaml{} 174 - if err := cfg.ParseConfig(); err != nil { 175 - return err 176 - } 177 164 178 165 out.RenderHTML(indexHTML, TEMPLATES, struct { 179 166 Cfg config.ConfigYaml 180 167 Meta markdown.Matter 181 168 Body string 182 169 Posts []markdown.Output 183 - }{cfg, out.Meta, string(out.HTML), posts}) 170 + }{config.Config, out.Meta, string(out.HTML), posts}) 184 171 185 172 // Create feeds 186 173 // ex: build/blog/feed.xml
+16 -4
config/config.go
··· 1 1 package config 2 2 3 3 import ( 4 + "fmt" 4 5 "os" 5 6 6 7 "gopkg.in/yaml.v3" 7 8 ) 8 9 10 + var Config ConfigYaml 11 + 12 + func 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 + 9 20 type ConfigYaml struct { 10 - Title string `yaml:"title"` 11 - Desc string `yaml:"description"` 12 - Author struct { 21 + Title string `yaml:"title"` 22 + Desc string `yaml:"description"` 23 + DefaultTemplate string `yaml:"default-template"` 24 + Author struct { 13 25 Name string `yaml:"name"` 14 26 Email string `yaml:"email"` 15 27 } `yaml:"author"` ··· 18 30 // Postbuild []string `yaml:"postbuild"` 19 31 } 20 32 21 - func (c *ConfigYaml) ParseConfig() error { 33 + func (c *ConfigYaml) parseConfig() error { 22 34 cf, err := os.ReadFile("config.yaml") 23 35 if err != nil { 24 36 return err
+2 -1
markdown/markdown.go
··· 5 5 gotmpl "text/template" 6 6 "time" 7 7 8 + "git.icyphox.sh/vite/config" 8 9 "git.icyphox.sh/vite/markdown/template" 9 10 10 11 bfc "github.com/Depado/bfchroma" ··· 49 50 func (out *Output) RenderHTML(dst, tmplDir string, data interface{}) error { 50 51 metaTemplate := out.Meta["template"] 51 52 if metaTemplate == "" { 52 - metaTemplate = "text.html" 53 + metaTemplate = config.Config.DefaultTemplate 53 54 } 54 55 55 56 tmpl := template.NewTmpl()
+4 -3
readme
··· 26 26 below struct: 27 27 28 28 type ConfigYaml struct { 29 - Title string `yaml:"title"` 30 - Desc string `yaml:"description"` 31 - Author struct { 29 + Title string `yaml:"title"` 30 + Desc string `yaml:"description"` 31 + DefaultTemplate string `yaml:"default-template"` 32 + Author struct { 32 33 Name string `yaml:"name"` 33 34 Email string `yaml:"email"` 34 35 } `yaml:"author"`