bounds checking for the number of posts

This commit is contained in:
Aaron Bieber 2017-02-17 07:13:26 -07:00
parent 1a85e8c734
commit 913e4bf460

18
main.go
View File

@ -38,6 +38,9 @@ var funcMap = template.FuncMap{
return string(b) return string(b)
}, },
"lop": func(p Posts, start, end int) Posts { "lop": func(p Posts, start, end int) Posts {
if len(p) < end {
return p
}
return p[start:end] return p[start:end]
}, },
"joinTags": func(ts Tags) template.HTML { "joinTags": func(ts Tags) template.HTML {
@ -311,10 +314,17 @@ func main() {
Title: "Contact", Title: "Contact",
Author: posts[0].Author, Author: posts[0].Author,
}) })
renderTemplate(path.Join(dst, "/archive.html"), "archive.html", content{ if len(posts) < 5 {
Title: "Archive", renderTemplate(path.Join(dst, "/archive.html"), "archive.html", content{
Posts: posts[5:], Title: "Archive",
}) Posts: posts,
})
} else {
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 // TODO variablize all of this and shove it in some kind of config