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.

Support index page generation

+80 -31
+61 -13
build.go
··· 2 2 3 3 import ( 4 4 "fmt" 5 - "github.com/cross-cpm/go-shutil" 6 5 "io/ioutil" 7 6 "os" 8 7 "os/exec" 9 8 "path/filepath" 9 + "sort" 10 10 "strings" 11 11 "text/template" 12 + 13 + "github.com/cross-cpm/go-shutil" 12 14 ) 13 15 14 16 var cfg = parseConfig() 15 17 16 18 type Post struct { 17 - fm Matter 19 + Fm Matter 18 20 } 19 21 20 22 var posts []Post 23 + 24 + type NewFm struct { 25 + Template string 26 + URL string 27 + Title string 28 + Subtitle string 29 + Date string 30 + Body string 31 + } 21 32 22 33 func execute(cmds []string) { 23 34 for _, cmd := range cmds { ··· 69 80 posts = append(posts, Post{fm}) 70 81 } 71 82 72 - type NewFm struct { 73 - Template string 74 - URL string 75 - Title string 76 - Subtitle string 77 - Date string 78 - Body string 79 - } 80 - 81 - var newFm = NewFm { 83 + var newFm = NewFm{ 82 84 fm.Template, 83 85 fm.URL, 84 86 fm.Title, ··· 109 111 htmlFile.Close() 110 112 } 111 113 114 + func renderIndex(posts []Post) { 115 + indexTmpl := processTemplate("index.html") 116 + path := filepath.Join("pages", "_index.md") 117 + 118 + // Sort posts by date 119 + sort.Slice(posts, func(i, j int) bool { 120 + return posts[j].Fm.Date.Time.Before(posts[i].Fm.Date.Time) 121 + }) 122 + 123 + content, err := ioutil.ReadFile(path) 124 + if err != nil { 125 + printErr(err) 126 + } 127 + 128 + restContent, fm := parseFrontmatter(content) 129 + bodyHtml := mdRender(restContent) 130 + fm.Body = string(bodyHtml) 131 + 132 + var newFm = NewFm{ 133 + fm.Template, 134 + fm.URL, 135 + fm.Title, 136 + fm.Subtitle, 137 + fm.Date.Time.Format(cfg.DateFmt), 138 + fm.Body, 139 + } 140 + 141 + combined := struct { 142 + Fm NewFm 143 + Posts []Post 144 + Cfg Config 145 + }{newFm, posts, cfg} 146 + 147 + htmlFile, err := os.Create(filepath.Join("build", "index.html")) 148 + err = indexTmpl.Execute(htmlFile, combined) 149 + if err != nil { 150 + printErr(err) 151 + return 152 + } 153 + htmlFile.Close() 154 + } 155 + 112 156 func viteBuild() { 113 157 if len(cfg.Prebuild) != 0 { 114 158 printMsg("executing pre-build actions...") ··· 119 163 printErr(err) 120 164 return err 121 165 } 122 - if filepath.Ext(path) == ".md" { 166 + if filepath.Ext(path) == ".md" && path != filepath.Join("pages", "_index.md") { 123 167 handleMd(path) 124 168 } else { 125 169 f, err := os.Stat(path) ··· 140 184 } 141 185 return nil 142 186 }) 187 + 143 188 if err != nil { 144 189 printErr(err) 145 190 } 191 + 192 + // Deal with the special snowflake '_index.md' 193 + renderIndex(posts) 146 194 147 195 _, err = shutil.CopyTree("static", filepath.Join("build", "static"), nil) 148 196 if err != nil {
+10 -10
config.go
··· 6 6 ) 7 7 8 8 type Config struct { 9 - Title string `yaml:"title"` 10 - Header string `yaml:"header"` 11 - DateFmt string `yaml:datefmt` 12 - SiteURL string `yaml:"siteurl"` 13 - Description string `yaml:"description"` 14 - Author map[string]string `yaml:"author"` 15 - Footer string `yaml:"footer"` 16 - Prebuild []string `yaml:"prebuild"` 17 - Postbuild []string `yaml:"postbuild"` 18 - RSSPrefixURL string `yaml:"rssprefixurl"` 9 + Title string `yaml:"title"` 10 + Header string `yaml:"header"` 11 + DateFmt string `yaml:datefmt` 12 + SiteURL string `yaml:"siteurl"` 13 + Description string `yaml:"description"` 14 + Author map[string]string `yaml:"author"` 15 + Footer string `yaml:"footer"` 16 + Prebuild []string `yaml:"prebuild"` 17 + Postbuild []string `yaml:"postbuild"` 18 + RSSPrefixURL string `yaml:"rssprefixurl"` 19 19 } 20 20 21 21 func parseConfig() Config {
+9 -8
rss.go
··· 1 1 package main 2 2 3 3 import ( 4 - . "github.com/gorilla/feeds" 4 + "os" 5 + "path/filepath" 5 6 "sort" 6 7 "time" 7 - "os" 8 - "path/filepath" 8 + 9 + . "github.com/gorilla/feeds" 9 10 ) 10 11 11 12 func generateRSS(posts []Post, cfg Config) { ··· 23 24 24 25 // Sort posts by date 25 26 sort.Slice(posts, func(i, j int) bool { 26 - return posts[j].fm.Date.Time.Before(posts[i].fm.Date.Time) 27 + return posts[j].Fm.Date.Time.Before(posts[i].Fm.Date.Time) 27 28 }) 28 29 29 30 atomfile, err := os.Create(filepath.Join("build", "blog", "feed.xml")) ··· 32 33 } 33 34 for _, p := range posts { 34 35 feed.Items = append(feed.Items, &Item{ 35 - Title: p.fm.Title, 36 - Link: &Link{Href: cfg.RSSPrefixURL + p.fm.URL}, 37 - Description: string(p.fm.Body), 38 - Created: p.fm.Date.Time, 36 + Title: p.Fm.Title, 37 + Link: &Link{Href: cfg.RSSPrefixURL + p.Fm.URL}, 38 + Description: string(p.Fm.Body), 39 + Created: p.Fm.Date.Time, 39 40 }) 40 41 } 41 42