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 (
"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,9 +225,14 @@ func getPosts() []Post {
for _, file := range files {
tmp, err := getPost(file)
if err == nil {
isFuture := tmp.Meta.Date != time.Time{} && tmp.Meta.Date.After(time.Now())
if isFuture {
removeFromStage2(file)
} else {
posts = append(posts, tmp)
}
}
}
return posts
}