blogs: ignore future posts

This commit is contained in:
gutmet 2022-12-05 21:46:01 +01:00
parent 5d04342b42
commit dac343fa51

View File

@ -3,8 +3,6 @@ package blog
import ( import (
"bytes" "bytes"
"fmt" "fmt"
goutil "git.gutmet.org/goutil.git/misc"
. "git.gutmet.org/wombat.git/templatestructures"
"math" "math"
"os" "os"
"path" "path"
@ -14,6 +12,9 @@ import (
"strings" "strings"
"text/template" "text/template"
"time" "time"
goutil "git.gutmet.org/goutil.git/misc"
. "git.gutmet.org/wombat.git/templatestructures"
) )
const postsPerPage int = 5 const postsPerPage int = 5
@ -49,10 +50,14 @@ func keys(m map[string][]Post) []string {
return keys return keys
} }
func emitPostPage(post Post) string { func removeFromStage2(filename string) {
filename := strings.TrimPrefix(strings.TrimPrefix(post.Filename, "stage1/"), "stage1\\") filename = strings.TrimPrefix(strings.TrimPrefix(filename, "stage1/"), "stage1\\")
link := post.Link
os.Remove(filepath.Join("stage2", filename)) os.Remove(filepath.Join("stage2", filename))
}
func emitPostPage(post Post) string {
link := post.Link
removeFromStage2(post.Filename)
base := path.Base(link) base := path.Base(link)
folders := strings.TrimSuffix("stage2"+link, base) folders := strings.TrimSuffix("stage2"+link, base)
os.MkdirAll(folders, 0755) os.MkdirAll(folders, 0755)
@ -220,9 +225,14 @@ func getPosts() []Post {
for _, file := range files { for _, file := range files {
tmp, err := getPost(file) tmp, err := getPost(file)
if err == nil { if err == nil {
isFuture := tmp.Meta.Date != time.Time{} && tmp.Meta.Date.After(time.Now())
if isFuture {
removeFromStage2(file)
} else {
posts = append(posts, tmp) posts = append(posts, tmp)
} }
} }
}
return posts return posts
} }