commit 7622c61
0uppy
·
2026-05-11 14:03:16 +0000 UTC
parent 04b7cc8
ssg: added sidebar generation,.,,. like werc :D
3 files changed,
+14,
-3
+6,
-2
1@@ -61,6 +61,10 @@ func mainAction(ctx context.Context, c *cli.Command) error {
2 if err != nil {
3 return err
4 }
5+ sidebar, err := ssg.GetSidebar(pagesDir)
6+ if err != nil {
7+ return err
8+ }
9 outputDir := c.String("output-dir")
10 if err := os.MkdirAll(outputDir, 0o700); os.IsNotExist(err) {
11 return err
12@@ -80,8 +84,8 @@ func mainAction(ctx context.Context, c *cli.Command) error {
13 if err != nil {
14 return err
15 }
16- if err := ssg.BuildPage(f, name, path, page, markdown, templates, config, baseUrl); err != nil {
17- return err
18+ if err := ssg.BuildPage(f, name, path, page, markdown, templates, config, baseUrl, sidebar); err != nil {
19+ return err
20 }
21 }
22 return nil
+2,
-1
1@@ -52,7 +52,7 @@ func GetPages(dir string) (map[string]string, error) {
2 return res, nil
3 }
4
5-func BuildPage(w io.Writer, name string, path string, page string, markdown goldmark.Markdown, templates Templates, config Config, baseUrl string) error {
6+func BuildPage(w io.Writer, name string, path string, page string, markdown goldmark.Markdown, templates Templates, config Config, baseUrl string, sidebar []SidebarItem) error {
7 var buff bytes.Buffer
8 ctx := parser.NewContext()
9 if err := markdown.Convert([]byte(page), &buff, parser.WithContext(ctx)); err != nil {
10@@ -94,6 +94,7 @@ func BuildPage(w io.Writer, name string, path string, page string, markdown gold
11 Params: frontmatter,
12 Config: config,
13 Content: buff.String(),
14+ Sidebar: sidebar,
15 }
16 if err := BuildTemplate(w, name, templates[templateName], templateData); err != nil {
17 return err
+6,
-0
1@@ -15,6 +15,12 @@ type TemplateData struct {
2 Params map[string]any
3 Config Config
4 Content string
5+ Sidebar []SidebarItem
6+}
7+
8+type SidebarItem struct {
9+ Name string
10+ Path string
11 }
12
13 type Templates map[string]string