From dac343fa51b716bb6ed91a0369bc7d2f0f735921 Mon Sep 17 00:00:00 2001 From: gutmet Date: Mon, 5 Dec 2022 21:46:01 +0100 Subject: [PATCH] blogs: ignore future posts --- blog/blog.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/blog/blog.go b/blog/blog.go index 0d3a293..9091b3f 100644 --- a/blog/blog.go +++ b/blog/blog.go @@ -3,8 +3,6 @@ package blog import ( "bytes" "fmt" - goutil "git.gutmet.org/goutil.git/misc" - . "git.gutmet.org/wombat.git/templatestructures" "math" "os" "path" @@ -14,6 +12,9 @@ import ( "strings" "text/template" "time" + + goutil "git.gutmet.org/goutil.git/misc" + . "git.gutmet.org/wombat.git/templatestructures" ) const postsPerPage int = 5 @@ -49,10 +50,14 @@ func keys(m map[string][]Post) []string { return keys } -func emitPostPage(post Post) string { - filename := strings.TrimPrefix(strings.TrimPrefix(post.Filename, "stage1/"), "stage1\\") - link := post.Link +func removeFromStage2(filename string) { + filename = strings.TrimPrefix(strings.TrimPrefix(filename, "stage1/"), "stage1\\") os.Remove(filepath.Join("stage2", filename)) +} + +func emitPostPage(post Post) string { + link := post.Link + removeFromStage2(post.Filename) base := path.Base(link) folders := strings.TrimSuffix("stage2"+link, base) os.MkdirAll(folders, 0755) @@ -220,7 +225,12 @@ func getPosts() []Post { for _, file := range files { tmp, err := getPost(file) if err == nil { - posts = append(posts, tmp) + isFuture := tmp.Meta.Date != time.Time{} && tmp.Meta.Date.After(time.Now()) + if isFuture { + removeFromStage2(file) + } else { + posts = append(posts, tmp) + } } } return posts