From 29b398921be8fc56a7c364c20f061c8563931a96 Mon Sep 17 00:00:00 2001 From: Keith Solomon Date: Mon, 21 Apr 2025 15:10:28 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8feature:=20Wire=20up=20contact=20and?= =?UTF-8?q?=20thank=20you=20pages,=20add=20showInNav=20meta=20functionalit?= =?UTF-8?q?y?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- content/thanks.md | 5 + css/typography.css | 4 + main.go | 43 +- public/about/index.html | 4 +- public/assets/contact.js | 41 ++ public/assets/favicon.ico | Bin 0 -> 109045 bytes public/assets/style.css | 527 ++------------------- public/blog/another-blog-post/index.html | 4 +- public/blog/category/anger/index.html | 4 +- public/blog/category/go/index.html | 4 +- public/blog/category/progrmming/index.html | 4 +- public/blog/index.html | 4 +- public/blog/my-first-blog-post/index.html | 4 +- public/contact/index.html | 42 +- public/index.html | 4 +- public/thanks/index.html | 47 ++ templates/base.html | 7 + templates/contact_page.html | 53 ++- templates/header.html | 2 +- templates/thanks_page.html | 10 + 20 files changed, 280 insertions(+), 533 deletions(-) create mode 100644 content/thanks.md create mode 100644 public/assets/contact.js create mode 100644 public/assets/favicon.ico create mode 100644 public/thanks/index.html create mode 100644 templates/thanks_page.html diff --git a/content/thanks.md b/content/thanks.md new file mode 100644 index 0000000..01c07a7 --- /dev/null +++ b/content/thanks.md @@ -0,0 +1,5 @@ +--- +title: Thank You +navTitle: "" +showInNav: false +--- diff --git a/css/typography.css b/css/typography.css index f1020ed..cbb09fd 100644 --- a/css/typography.css +++ b/css/typography.css @@ -107,6 +107,10 @@ h3 a, .h3 a { text-decoration: underline; } +#site_head h1 a { + @apply text-white text-40px hover:text-primary-200; +} + p { margin-top: 0; margin-bottom: 1rem; diff --git a/main.go b/main.go index 060db5b..013f238 100644 --- a/main.go +++ b/main.go @@ -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) diff --git a/public/about/index.html b/public/about/index.html index bb050d3..ee6e953 100644 --- a/public/about/index.html +++ b/public/about/index.html @@ -7,12 +7,13 @@ Go SSG - About +