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.

Rework config handling

+32 -26
+10 -9
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 - config := config.Config 55 + cfg := config.ConfigYaml{} 56 + cfg.ParseConfig() 56 57 for _, p := range posts { 57 58 dateStr := p.Meta["date"] 58 59 date, err := time.Parse("2006-01-02", dateStr) ··· 67 68 // tag:icyphox.sh,2019-10-23:blog/some-post/ 68 69 ID: fmt.Sprintf( 69 70 "tag:%s,%s:%s", 70 - config.URL[8:], // strip https:// 71 + cfg.URL[8:], // strip https:// 71 72 dateStr, 72 73 filepath.Join(srcDir, p.Meta["slug"]), 73 74 ), 74 - Link: &AtomLink{Href: filepath.Join(config.URL, srcDir, p.Meta["slug"])}, 75 + Link: &AtomLink{Href: filepath.Join(cfg.URL, srcDir, p.Meta["slug"])}, 75 76 Summary: &AtomSummary{Content: string(p.HTML), Type: "html"}, 76 77 } 77 78 entries = append(entries, entry) ··· 81 82 now := time.Now().Format(time.RFC3339) 82 83 feed := &AtomFeed{ 83 84 Xmlns: "http://www.w3.org/2005/Atom", 84 - Title: config.Title, 85 - ID: config.URL, 86 - Subtitle: config.Desc, 87 - Link: &AtomLink{Href: config.URL}, 85 + Title: cfg.Title, 86 + ID: cfg.URL, 87 + Subtitle: cfg.Desc, 88 + Link: &AtomLink{Href: cfg.URL}, 88 89 Author: &AtomAuthor{ 89 - Name: config.Author.Name, 90 - Email: config.Author.Email, 90 + Name: cfg.Author.Name, 91 + Email: cfg.Author.Email, 91 92 }, 92 93 Updated: now, 93 94 Entries: entries,
+15 -3
commands/build.go
··· 70 70 71 71 out := markdown.Output{} 72 72 out.RenderMarkdown(fb) 73 + cfg := config.ConfigYaml{} 74 + if err := cfg.ParseConfig(); err != nil { 75 + return err 76 + } 73 77 if err = out.RenderHTML( 74 78 htmlFile, 75 79 TEMPLATES, ··· 77 81 Cfg config.ConfigYaml 78 82 Meta markdown.Matter 79 83 Body string 80 - }{config.Config, out.Meta, string(out.HTML)}, 84 + }{cfg, out.Meta, string(out.HTML)}, 81 85 ); err != nil { 82 86 return err 83 87 } ··· 125 129 126 130 out := markdown.Output{} 127 131 out.RenderMarkdown(fb) 132 + cfg := config.ConfigYaml{} 133 + if err := cfg.ParseConfig(); err != nil { 134 + return err 135 + } 128 136 129 137 if err = out.RenderHTML( 130 138 htmlFile, ··· 133 141 Cfg config.ConfigYaml 134 142 Meta markdown.Matter 135 143 Body string 136 - }{config.Config, out.Meta, string(out.HTML)}, 144 + }{cfg, out.Meta, string(out.HTML)}, 137 145 ); err != nil { 138 146 return err 139 147 } ··· 160 168 } 161 169 out := markdown.Output{} 162 170 out.RenderMarkdown(indexMd) 171 + cfg := config.ConfigYaml{} 172 + if err := cfg.ParseConfig(); err != nil { 173 + return err 174 + } 163 175 164 176 out.RenderHTML(indexHTML, TEMPLATES, struct { 165 177 Cfg config.ConfigYaml 166 178 Meta markdown.Matter 167 179 Body string 168 180 Posts []markdown.Output 169 - }{config.Config, out.Meta, string(out.HTML), posts}) 181 + }{cfg, out.Meta, string(out.HTML), posts}) 170 182 171 183 // Create feeds 172 184 // ex: build/blog/feed.xml
+1 -1
commands/init.go
··· 18 18 } 19 19 } 20 20 fp, _ := filepath.Abs(path) 21 - fmt.Printf("vite: created project at %q\n", fp) 21 + fmt.Printf("vite: created project at %s\n", fp) 22 22 return nil 23 23 }
+1
commands/new.go
··· 25 25 return err 26 26 } 27 27 os.WriteFile(path, []byte(content), 0755) 28 + fmt.Printf("vite: created new post at %s\n", path) 28 29 return nil 29 30 }
+5 -13
config/config.go
··· 1 1 package config 2 2 3 3 import ( 4 - "fmt" 5 4 "os" 6 5 7 6 "gopkg.in/yaml.v3" ··· 19 18 // Postbuild []string `yaml:"postbuild"` 20 19 } 21 20 22 - var Config ConfigYaml 23 - 24 - func init() { 21 + func (c *ConfigYaml) ParseConfig() error { 25 22 cf, err := os.ReadFile("config.yaml") 26 23 if err != nil { 27 - fmt.Fprintf(os.Stderr, "error: %+v\n", err) 28 - os.Exit(1) 24 + return err 29 25 } 30 - if err = Config.ParseConfig(cf); err != nil { 31 - fmt.Fprintf(os.Stderr, "error: %+v\n", err) 26 + if err = yaml.Unmarshal(cf, c); err != nil { 27 + return err 32 28 } 33 - } 34 - 35 - func (c *ConfigYaml) ParseConfig(cf []byte) error { 36 - err := yaml.Unmarshal(cf, c) 37 - return err 29 + return nil 38 30 }