diff --git a/content/about.md b/content/about.md index a38e235..b7052af 100644 --- a/content/about.md +++ b/content/about.md @@ -3,6 +3,7 @@ title: Go SSG - About navTitle: About description: More About My Go SSG Site. date: 2025-04-19 +navPosition: 2 --- Experimenting with Go. Seems pretty cool so far! diff --git a/content/contact.md b/content/contact.md index 2b622c6..2ff5860 100644 --- a/content/contact.md +++ b/content/contact.md @@ -1,4 +1,5 @@ --- title: Contact navTitle: Contact +navPosition: 4 --- diff --git a/content/index.md b/content/index.md index d702de8..d2b62b9 100644 --- a/content/index.md +++ b/content/index.md @@ -1,6 +1,8 @@ --- title: Go SSG - Home navTitle: Home +showInNav: true +navPosition: 1 description: My Go SSG Site. date: 2025-04-19 --- diff --git a/main.go b/main.go index 013f238..fa77fc7 100644 --- a/main.go +++ b/main.go @@ -19,14 +19,16 @@ import ( ) type NavItem struct { - Title string - URL string + Title string + URL string + Position int } type PageMeta struct { Title string `yaml:"title"` NavTitle string `yaml:"navTitle"` ShowInNav *bool `yaml:"showInNav"` + NavPosition *int `yaml:"navPosition"` Description string `yaml:"description"` Date string `yaml:"date"` Categories []string `yaml:"categories"` @@ -53,6 +55,9 @@ func main() { entries, _ := os.ReadDir(contentDir) nav := buildNav(entries, contentDir) + for _, item := range nav { + fmt.Printf("Nav: %s (%s) — Pos: %d\n", item.Title, item.URL, item.Position) + } renderStaticPages(files, contentDir, outputDir, tpl, nav) blogPosts, categoryMap := processBlogPosts(contentDir, outputDir, tpl, nav) renderContactPage(contentDir, outputDir, tpl, nav) @@ -85,46 +90,53 @@ func buildNav(entries []fs.DirEntry, contentDir string) []NavItem { } meta, _ := parseFrontMatter(rawContent) + fmt.Printf("meta from %s: %+v\n", entry.Name(), meta) + // Skip pages with showInNav: false + if meta.ShowInNav != nil && !*meta.ShowInNav { + continue + } + + // Pull title info 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 == "" { title = strings.Title(name) } + // Build URL url := "/" if name != "index" { url = "/" + name + "/" } - nav = append(nav, NavItem{Title: title, URL: url}) + // Pull nav position regardless of title logic + position := 999 + if meta.NavPosition != nil { + position = *meta.NavPosition + } + + nav = append(nav, NavItem{ + Title: title, + URL: url, + Position: position, + }) } - // Add Blog manually - nav = append(nav, NavItem{Title: "Blog", URL: "/blog/"}) - - // Optional: order the nav explicitly - preferredOrder := map[string]int{ - "Home": 0, - "Blog": 1, - "About": 2, - "Contact": 3, - } + // Optional: add Blog manually (or skip if you handle it as a page) + nav = append(nav, NavItem{ + Title: "Blog", + URL: "/blog/", + Position: 3, + }) + // Sort by position sort.SliceStable(nav, func(i, j int) bool { - return preferredOrder[nav[i].Title] < preferredOrder[nav[j].Title] + return nav[i].Position < nav[j].Position }) return nav diff --git a/public/about/index.html b/public/about/index.html index ee6e953..d9ef014 100644 --- a/public/about/index.html +++ b/public/about/index.html @@ -20,10 +20,10 @@