From 4fafe1254ac8223803aef31576d031ddb3876d30 Mon Sep 17 00:00:00 2001 From: Evrard Van Espen Date: Tue, 18 Nov 2025 09:40:07 +0000 Subject: [PATCH] Add draft support --- build-dev.sh | 1 + build.sh | 1 + parse.go | 14 +++++++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/build-dev.sh b/build-dev.sh index e120402..2183f08 100755 --- a/build-dev.sh +++ b/build-dev.sh @@ -1,3 +1,4 @@ #!/bin/bash +export BLOG_ENV=dev watchexec --restart -w ./ --no-process-group -- go run . diff --git a/build.sh b/build.sh index a1be35d..6bda2da 100755 --- a/build.sh +++ b/build.sh @@ -1,3 +1,4 @@ #!/bin/bash +rm -rf build go run . diff --git a/parse.go b/parse.go index 2025c4e..ee266d2 100644 --- a/parse.go +++ b/parse.go @@ -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 }