From 913e4bf46059062da596b25b33ab889e1f901b05 Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Fri, 17 Feb 2017 07:13:26 -0700 Subject: [PATCH] bounds checking for the number of posts --- main.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 60e0c02..ec39c4c 100644 --- a/main.go +++ b/main.go @@ -38,6 +38,9 @@ var funcMap = template.FuncMap{ return string(b) }, "lop": func(p Posts, start, end int) Posts { + if len(p) < end { + return p + } return p[start:end] }, "joinTags": func(ts Tags) template.HTML { @@ -311,10 +314,17 @@ func main() { Title: "Contact", Author: posts[0].Author, }) - renderTemplate(path.Join(dst, "/archive.html"), "archive.html", content{ - Title: "Archive", - Posts: posts[5:], - }) + if len(posts) < 5 { + renderTemplate(path.Join(dst, "/archive.html"), "archive.html", content{ + 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