blogs: ignore future posts
This commit is contained in:
parent
5d04342b42
commit
dac343fa51
22
blog/blog.go
22
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
|
||||
|
|
Loading…
Reference in New Issue
Block a user