fast and minimal static site generator
ssg

Add a new Allowed field

Useful to check if post is allowed for inclusion in say, index listings.

Signed-off-by: Anirudh Oppiliappan <anirudh@tangled.sh>

anirudh.fi 483e5689 7125ccb0

verified
Changed files
+11 -4
formats
markdown
types
+9 -4
formats/markdown/markdown.go
··· 90 90 } 91 91 92 92 type templateData struct { 93 - Cfg config.ConfigYaml 94 - Meta map[string]any 95 - Body string 96 - Extra any 93 + Cfg config.ConfigYaml 94 + Meta map[string]any 95 + Body string 96 + Extra any 97 + Allowed bool 97 98 } 98 99 99 100 func (md *Markdown) Render(dest string, data any, drafts bool) error { ··· 116 117 fmt.Printf("vite: rendering draft %s\n", md.Path) 117 118 } 118 119 120 + // allow post if it's not a draft, or if it's a draft and drafts are enabled 121 + allowed := !isDraft || drafts 122 + 119 123 err = md.template(dest, types.TemplatesDir, templateData{ 120 124 config.Config, 121 125 md.frontmatter, 122 126 string(md.body), 123 127 data, 128 + allowed, 124 129 }) 125 130 if err != nil { 126 131 return fmt.Errorf("markdown: failed to render to destination %s: %w", dest, err)
+2
types/types.go
··· 27 27 Meta map[string]any 28 28 // HTML-formatted body of post 29 29 Body string 30 + // Whether this post should be shown (based on draft status and drafts flag) 31 + Allowed bool 30 32 }