commit fa879c7
0uppy
·
2026-05-31 16:32:40 +0000 UTC
parent 5bc39bc
ssg: the sidebar's order can now be tinkered with from config hooray
4 files changed,
+23,
-12
+1,
-1
1@@ -65,7 +65,7 @@ func mainAction(ctx context.Context, c *cli.Command) error {
2 if err != nil {
3 return err
4 }
5- sidebar, err := ssg.GetSidebar(pagesDir)
6+ sidebar, err := ssg.GetSidebar(pagesDir, config.SidebarOrder)
7 if err != nil {
8 return err
9 }
+3,
-4
1@@ -1,6 +1,5 @@
2 base_url = "https://dani-institute.codeberg.page"
3-title = "The Dani Institute"
4-description = "This is where you can find information about the Dani Village."
5+title = "the dani musem"
6+description = "this is where you can find information about the Dani Village, feel free to look around!! :D"
7
8-[extra]
9-test = "hi"
10+sidebar_order = ["index", "danipedia", "danilore", "thedanivillagemap", "misc"]
+1,
-0
1@@ -11,6 +11,7 @@ type Config struct {
2 Title string `toml:"title"`
3 Description string `toml:"description"`
4 Extra map[string]any `toml:"extra"`
5+ SidebarOrder []string `toml:"sidebar_order"`
6 }
7
8 func LoadConfigFile(fn string, config *Config) error {
1@@ -2,23 +2,20 @@ package ssg
2
3 import (
4 "os"
5+ "sort"
6 "strings"
7 )
8
9-func GetSidebar(pagesDir string) ([]SidebarItem, error) {
10+func GetSidebar(pagesDir string, order []string) ([]SidebarItem, error) {
11 entries, err := os.ReadDir(pagesDir)
12 if err != nil {
13 return nil, err
14 }
15+
16 var nav []SidebarItem
17+
18 for _, entry := range entries {
19 name := entry.Name()
20- if entry.IsDir() {
21- nav = append(nav, SidebarItem{
22- Name: name,
23- Path: "/" + name,
24- })
25- }
26 stem, ok := strings.CutSuffix(name, ".md")
27 if !ok {
28 continue
29@@ -28,5 +25,19 @@ func GetSidebar(pagesDir string) ([]SidebarItem, error) {
30 Path: stem + ".html",
31 })
32 }
33+
34+ sort.Slice(nav, func(i, j int) bool {
35+ iIdx, jIdx := len(order), len(order)
36+ for k, v := range order {
37+ if nav[i].Name == v {
38+ iIdx = k
39+ }
40+ if nav[j].Name == v {
41+ jIdx = k
42+ }
43+ }
44+ return iIdx < jIdx
45+ })
46+
47 return nav, nil
48 }