feature: Wire up contact and thank you pages, add showInNav meta functionality

This commit is contained in:
Keith Solomon
2025-04-21 15:10:28 -05:00
parent 1a9b58d7d7
commit 29b398921b
20 changed files with 280 additions and 533 deletions

43
main.go
View File

@@ -26,6 +26,7 @@ type NavItem struct {
type PageMeta struct {
Title string `yaml:"title"`
NavTitle string `yaml:"navTitle"`
ShowInNav *bool `yaml:"showInNav"`
Description string `yaml:"description"`
Date string `yaml:"date"`
Categories []string `yaml:"categories"`
@@ -54,6 +55,8 @@ func main() {
nav := buildNav(entries, contentDir)
renderStaticPages(files, contentDir, outputDir, tpl, nav)
blogPosts, categoryMap := processBlogPosts(contentDir, outputDir, tpl, nav)
renderContactPage(contentDir, outputDir, tpl, nav)
renderThanksPage(contentDir, outputDir, tpl, nav)
buildBlogIndex(blogPosts, tpl, outputDir, nav)
buildCategoryPages(categoryMap, tpl, outputDir, nav)
@@ -83,10 +86,18 @@ func buildNav(entries []fs.DirEntry, contentDir string) []NavItem {
meta, _ := parseFrontMatter(rawContent)
title := meta.NavTitle
title := strings.TrimSpace(meta.NavTitle)
if title == "" {
title = meta.Title
}
if title == "" {
title = strings.Title(name)
}
// Respect showInNav: false
if meta.ShowInNav != nil && !*meta.ShowInNav {
continue
}
if title == "" && name == "index" {
title = "Home"
} else if title == "" {
@@ -202,6 +213,36 @@ func renderContactPage(contentDir, outputDir string, tpl *template.Template, nav
fmt.Println("Generated: /contact/")
}
func renderThanksPage(contentDir, outputDir string, tpl *template.Template, nav []NavItem) {
path := filepath.Join(contentDir, "thanks.md")
rawContent, err := os.ReadFile(path)
if err != nil {
fmt.Printf("Thanks page not found: %v\n", err)
return
}
meta, _ := parseFrontMatter(rawContent)
outPath := filepath.Join(outputDir, "thanks", "index.html")
os.MkdirAll(filepath.Dir(outPath), os.ModePerm)
outFile, err := os.Create(outPath)
if err != nil {
fmt.Printf("Failed to create thanks page: %v\n", err)
return
}
tpl.ExecuteTemplate(outFile, "thanks_page", map[string]interface{}{
"Title": meta.Title,
"Description": meta.Description,
"Nav": nav,
"Year": time.Now().Year(),
"PageTemplate": "thanks_page",
})
fmt.Println("Generated: /thanks/")
}
func processBlogPosts(contentDir, outputDir string, tpl *template.Template, nav []NavItem) ([]PageMeta, map[string][]PageMeta) {
var blogPosts []PageMeta
categoryMap := make(map[string][]PageMeta)