Add draft support
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
export BLOG_ENV=dev
|
||||||
watchexec --restart -w ./ --no-process-group -- go run .
|
watchexec --restart -w ./ --no-process-group -- go run .
|
||||||
|
|||||||
12
parse.go
12
parse.go
@@ -27,6 +27,7 @@ type Post struct {
|
|||||||
Content *org.Document // Parsed content of the post
|
Content *org.Document // Parsed content of the post
|
||||||
ReadTime uint8 // Estimated reading time in minutes
|
ReadTime uint8 // Estimated reading time in minutes
|
||||||
Hero string // URL path to the hero image for the post
|
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.
|
// listPosts reads the posts directory and returns a slice of Post structs.
|
||||||
@@ -49,8 +50,14 @@ func listPosts() ([]Post, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("[!] Unable to parse ", filePath)
|
log.Println("[!] Unable to parse ", filePath)
|
||||||
} else {
|
} else {
|
||||||
|
if post.Draft {
|
||||||
|
if os.Getenv("BLOG_ENV") == "dev" {
|
||||||
posts = append(posts, post)
|
posts = append(posts, post)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
posts = append(posts, post)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Slice(posts, func(i, j int) bool {
|
sort.Slice(posts, func(i, j int) bool {
|
||||||
@@ -103,6 +110,10 @@ func parseOrg(filePath string) (Post, error) {
|
|||||||
slug := orgData.Get("SLUG")
|
slug := orgData.Get("SLUG")
|
||||||
tags := strings.Split(orgData.Get("TAGS"), ", ")
|
tags := strings.Split(orgData.Get("TAGS"), ", ")
|
||||||
hero := path.Join("/medias", orgData.Get("HERO"))
|
hero := path.Join("/medias", orgData.Get("HERO"))
|
||||||
|
draft := true
|
||||||
|
if orgData.Get("DRAFT") == "false" {
|
||||||
|
draft = false
|
||||||
|
}
|
||||||
|
|
||||||
date, _ := time.Parse("2006-01-02", dateStr)
|
date, _ := time.Parse("2006-01-02", dateStr)
|
||||||
ts := date.Unix()
|
ts := date.Unix()
|
||||||
@@ -123,5 +134,6 @@ func parseOrg(filePath string) (Post, error) {
|
|||||||
Content: orgData,
|
Content: orgData,
|
||||||
ReadTime: uint8(readTime),
|
ReadTime: uint8(readTime),
|
||||||
Hero: hero,
|
Hero: hero,
|
||||||
|
Draft: draft,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user