rss / atom feeds
This commit is contained in:
parent
2ecdca9149
commit
1a85e8c734
6
glide.lock
generated
6
glide.lock
generated
@ -1,6 +1,8 @@
|
|||||||
hash: 83b61e3f32d25a66b5faa0922f14dd294a540f1b9918921aa73af340de31ad24
|
hash: af0c2b0e7fd58c70a43dcf5c75b802f7a49c5d53ad6aec1975adfebe0acee206
|
||||||
updated: 2017-02-03T09:14:47.670780155-07:00
|
updated: 2017-02-04T09:25:07.785352554-07:00
|
||||||
imports:
|
imports:
|
||||||
|
- name: github.com/gorilla/feeds
|
||||||
|
version: 441264de03a8117ed530ae8e049d8f601a33a099
|
||||||
- name: github.com/russross/blackfriday
|
- name: github.com/russross/blackfriday
|
||||||
version: 0b647d0506a698cca42caca173e55559b12a69f2
|
version: 0b647d0506a698cca42caca173e55559b12a69f2
|
||||||
- name: github.com/shurcooL/sanitized_anchor_name
|
- name: github.com/shurcooL/sanitized_anchor_name
|
||||||
|
@ -3,3 +3,4 @@ import:
|
|||||||
- package: github.com/russross/blackfriday
|
- package: github.com/russross/blackfriday
|
||||||
version: ~1.4.0
|
version: ~1.4.0
|
||||||
- package: github.com/ylih/extrasys
|
- package: github.com/ylih/extrasys
|
||||||
|
- package: github.com/gorilla/feeds
|
||||||
|
75
main.go
75
main.go
@ -13,6 +13,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
. "github.com/gorilla/feeds"
|
||||||
"github.com/russross/blackfriday"
|
"github.com/russross/blackfriday"
|
||||||
// "github.com/ylih/extrasys"
|
// "github.com/ylih/extrasys"
|
||||||
)
|
)
|
||||||
@ -20,6 +21,13 @@ import (
|
|||||||
var templ *template.Template
|
var templ *template.Template
|
||||||
|
|
||||||
var funcMap = template.FuncMap{
|
var funcMap = template.FuncMap{
|
||||||
|
"hasTitle": func(s string) bool {
|
||||||
|
ret := false
|
||||||
|
if s != "" {
|
||||||
|
ret = true
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
},
|
||||||
"formatDate": func(t time.Time) string {
|
"formatDate": func(t time.Time) string {
|
||||||
return t.Format(time.RFC1123)
|
return t.Format(time.RFC1123)
|
||||||
},
|
},
|
||||||
@ -44,9 +52,10 @@ var funcMap = template.FuncMap{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
type response struct {
|
type content struct {
|
||||||
User interface{}
|
Posts Posts
|
||||||
Data interface{}
|
Title string
|
||||||
|
Author User
|
||||||
}
|
}
|
||||||
|
|
||||||
// AuthorRE is a regex to grab our Authors
|
// AuthorRE is a regex to grab our Authors
|
||||||
@ -107,7 +116,7 @@ func (u *User) Parse(s string) {
|
|||||||
|
|
||||||
// Combine concatenates FName, LName and Email into one line
|
// Combine concatenates FName, LName and Email into one line
|
||||||
func (u *User) Combine() string {
|
func (u *User) Combine() string {
|
||||||
return fmt.Sprintf("%s %s <%s>", u.FName, u.LName, u.Email)
|
return fmt.Sprintf("%s %s", u.FName, u.LName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Post is the base type for all posts
|
// Post is the base type for all posts
|
||||||
@ -234,6 +243,7 @@ func renderTemplate(dst string, tmpl string, data interface{}) {
|
|||||||
|
|
||||||
err = templ.ExecuteTemplate(o, tmpl, data)
|
err = templ.ExecuteTemplate(o, tmpl, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Println(dst)
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -289,8 +299,57 @@ func main() {
|
|||||||
|
|
||||||
sort.Sort(posts)
|
sort.Sort(posts)
|
||||||
|
|
||||||
renderTemplate(path.Join(dst, "/index.html"), "index.html", posts)
|
renderTemplate(path.Join(dst, "/index.html"), "index.html", content{
|
||||||
renderTemplate(path.Join(dst, "/about.html"), "about.html", posts[0].Author)
|
Title: "",
|
||||||
renderTemplate(path.Join(dst, "/contact.html"), "contact.html", posts[0].Author)
|
Posts: posts,
|
||||||
renderTemplate(path.Join(dst, "/archive.html"), "archive.html", posts[5:])
|
})
|
||||||
|
renderTemplate(path.Join(dst, "/about.html"), "about.html", content{
|
||||||
|
Title: "About",
|
||||||
|
Author: posts[0].Author,
|
||||||
|
})
|
||||||
|
renderTemplate(path.Join(dst, "/contact.html"), "contact.html", content{
|
||||||
|
Title: "Contact",
|
||||||
|
Author: posts[0].Author,
|
||||||
|
})
|
||||||
|
renderTemplate(path.Join(dst, "/archive.html"), "archive.html", content{
|
||||||
|
Title: "Archive",
|
||||||
|
Posts: posts[5:],
|
||||||
|
})
|
||||||
|
|
||||||
|
// TODO variablize all of this and shove it in some kind of config
|
||||||
|
|
||||||
|
latestDate := posts[0].Date
|
||||||
|
|
||||||
|
feed := &Feed{
|
||||||
|
Title: "deftly.net - All posts",
|
||||||
|
Link: &Link{Href: "https://deftly.net/"},
|
||||||
|
Description: "Personal blog of Aaron Bieber",
|
||||||
|
Author: &Author{Name: "Aaron Bieber", Email: "aaron@bolddaemon.com"},
|
||||||
|
Created: latestDate,
|
||||||
|
Copyright: "This work is copyright © Aaron Bieber",
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, post := range posts {
|
||||||
|
var i = &Item{}
|
||||||
|
i.Title = post.Title
|
||||||
|
i.Description = string(post.Body)
|
||||||
|
i.Link = &Link{Href: "https://deftly.net" + post.URL}
|
||||||
|
i.Author = &Author{Name: post.Author.Combine(), Email: "aaron@bolddaemon.com"}
|
||||||
|
i.Created = post.Date
|
||||||
|
|
||||||
|
feed.Items = append(feed.Items, i)
|
||||||
|
}
|
||||||
|
|
||||||
|
atomFile, err := os.Create(path.Join(dst, "atom.xml"))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
rssFile, err := os.Create(path.Join(dst, "rss.xml"))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
feed.WriteAtom(atomFile)
|
||||||
|
feed.WriteRss(rssFile)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user