Skip to content

Commit

Permalink
main.go: schedule articles
Browse files Browse the repository at this point in the history
If an article's date is in the future,
publish it during `blog serve` but
don't publish it during `blog build`.

#15
  • Loading branch information
croaky authored Mar 27, 2020
1 parent a3b06d0 commit 663a9d6
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
)

var wd string
var showScheduled = true

func main() {
if len(os.Args) < 2 {
Expand All @@ -56,6 +57,7 @@ func main() {
fmt.Println("Serving at http://localhost:2000")
serve(":2000")
case "build":
showScheduled = false
build()
fmt.Println("Built at ./public")
default:
Expand Down Expand Up @@ -240,13 +242,18 @@ func load() ([]Article, []string, map[string]string) {
redirectMap := make(map[string]string)

for i, a := range articles {
t, err := time.Parse("2006-01-02", a.LastUpdated)
check(err)

now := time.Now()
if showScheduled == false && t.After(now) {
continue
}

title, body := preProcess("articles/" + a.ID + ".md")
ext := parser.CommonExtensions | parser.AutoHeadingIDs
html := markdown.ToHTML([]byte(body), parser.NewWithExtensions(ext), nil)

t, err := time.Parse("2006-01-02", a.LastUpdated)
check(err)

a := Article{
Body: template.HTML(html),
Canonical: a.Canonical,
Expand Down

0 comments on commit 663a9d6

Please sign in to comment.