Add draft support

This commit is contained in:
Evrard Van Espen
2025-11-18 09:40:07 +00:00
parent fb6c11b7ec
commit 4fafe1254a
3 changed files with 15 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
#!/bin/bash
export BLOG_ENV=dev
watchexec --restart -w ./ --no-process-group -- go run .

View File

@@ -1,3 +1,4 @@
#!/bin/bash
rm -rf build
go run .

View File

@@ -27,6 +27,7 @@ type Post struct {
Content *org.Document // Parsed content of the post
ReadTime uint8 // Estimated reading time in minutes
Hero string // URL path to the hero image for the post
Draft bool // Is the article a draft (will not be rendered if so)
}
// listPosts reads the posts directory and returns a slice of Post structs.
@@ -49,7 +50,13 @@ func listPosts() ([]Post, error) {
if err != nil {
log.Println("[!] Unable to parse ", filePath)
} else {
posts = append(posts, post)
if post.Draft {
if os.Getenv("BLOG_ENV") == "dev" {
posts = append(posts, post)
}
} else {
posts = append(posts, post)
}
}
}
@@ -103,6 +110,10 @@ func parseOrg(filePath string) (Post, error) {
slug := orgData.Get("SLUG")
tags := strings.Split(orgData.Get("TAGS"), ", ")
hero := path.Join("/medias", orgData.Get("HERO"))
draft := true
if orgData.Get("DRAFT") == "false" {
draft = false
}
date, _ := time.Parse("2006-01-02", dateStr)
ts := date.Unix()
@@ -123,5 +134,6 @@ func parseOrg(filePath string) (Post, error) {
Content: orgData,
ReadTime: uint8(readTime),
Hero: hero,
Draft: draft,
}, nil
}