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.

RSS feeds!

+98 -10
+12
build.go
··· 13 13 14 14 var cfg = parseConfig() 15 15 16 + type Post struct { 17 + fm Matter 18 + } 19 + 20 + var posts []Post 21 + 16 22 func execute(cmds []string) { 17 23 for _, cmd := range cmds { 18 24 out, err := exec.Command(cmd).Output() ··· 58 64 os.MkdirAll(buildPath, 0755) 59 65 60 66 fm.Body = string(bodyHtml) 67 + 68 + if strings.Contains(relPath, "blog/") { 69 + posts = append(posts, Post{fm}) 70 + } 61 71 62 72 // combine config and matter structs 63 73 combined := struct { ··· 120 130 printErr(err) 121 131 } 122 132 printMsg("site build complete") 133 + printMsg("generating feeds...") 134 + generateRSS(posts, cfg) 123 135 printMsg("executing post-build actions...") 124 136 execute(cfg.Postbuild) 125 137 }
+9 -5
config.go
··· 6 6 ) 7 7 8 8 type Config struct { 9 - Title string 10 - Header string 11 - Footer string 12 - Prebuild []string 13 - Postbuild []string 9 + Title string `yaml:"title"` 10 + Header string `yaml:"header"` 11 + SiteURL string `yaml:"siteurl"` 12 + Description string `yaml:"description"` 13 + Author map[string]string `yaml:"author"` 14 + Footer string `yaml:"footer"` 15 + Prebuild []string `yaml:"prebuild"` 16 + Postbuild []string `yaml:"postbuild"` 17 + RSSPrefixURL string `yaml:"rssprefixurl"` 14 18 } 15 19 16 20 func parseConfig() Config {
+22 -5
frontmatter.go
··· 3 3 import ( 4 4 "bytes" 5 5 "github.com/adrg/frontmatter" 6 + "time" 6 7 ) 7 8 9 + type Date8601 struct { 10 + time.Time 11 + } 12 + 13 + func (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 + 8 25 type Matter struct { 9 - Template string `yaml:"template"` 10 - URL string `yaml:"url"` 11 - Title string `yaml:"title"` 12 - Subtitle string `yaml:"subtitle"` 13 - Date string `yaml:"date"` 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"` 14 31 Body string 15 32 } 16 33
+2
go.mod
··· 6 6 github.com/Depado/bfchroma v1.3.0 7 7 github.com/adrg/frontmatter v0.1.0 8 8 github.com/cross-cpm/go-shutil v0.0.0-20190908093542-3fcbb1a2151e 9 + github.com/gorilla/feeds v1.1.1 10 + github.com/kr/pretty v0.2.1 // indirect 9 11 github.com/russross/blackfriday/v2 v2.0.1 10 12 gopkg.in/yaml.v2 v2.3.0 11 13 )
+7
go.sum
··· 23 23 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 24 24 github.com/dlclark/regexp2 v1.2.0 h1:8sAhBGEM0dRWogWqWyQeIJnxjWO6oIjl8FKqREDsGfk= 25 25 github.com/dlclark/regexp2 v1.2.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= 26 + github.com/gorilla/feeds v1.1.1 h1:HwKXxqzcRNg9to+BbvJog4+f3s/xzvtZXICcQGutYfY= 27 + github.com/gorilla/feeds v1.1.1/go.mod h1:Nk0jZrvPFZX1OBe5NPiddPw7CfwF6Q9eqzaBbaightA= 28 + github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= 29 + github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= 30 + github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 31 + github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= 32 + github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 26 33 github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= 27 34 github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= 28 35 github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
+46
rss.go
··· 1 + package main 2 + 3 + import ( 4 + . "github.com/gorilla/feeds" 5 + "sort" 6 + "time" 7 + "os" 8 + "path/filepath" 9 + ) 10 + 11 + func generateRSS(posts []Post, cfg Config) { 12 + now := time.Now() 13 + feed := &Feed{ 14 + Title: cfg.Title, 15 + Link: &Link{Href: cfg.SiteURL}, 16 + Description: cfg.Description, 17 + Author: &Author{ 18 + Name: cfg.Author["name"], 19 + Email: cfg.Author["email"], 20 + }, 21 + Created: now, 22 + } 23 + 24 + // Sort posts by date 25 + sort.Slice(posts, func(i, j int) bool { 26 + return posts[j].fm.Date.Time.Before(posts[i].fm.Date.Time) 27 + }) 28 + 29 + atomfile, err := os.Create(filepath.Join("build", "blog", "feed.xml")) 30 + if err != nil { 31 + printErr(err) 32 + } 33 + for _, p := range posts { 34 + 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, 39 + }) 40 + } 41 + 42 + err = feed.WriteAtom(atomfile) 43 + if err != nil { 44 + printErr(err) 45 + } 46 + }