diff options
| -rw-r--r-- | content/index.md | 1 | ||||
| -rw-r--r-- | content/posts.md | 1 | ||||
| -rw-r--r-- | markdown/markdown.go | 5 | ||||
| -rw-r--r-- | pages/pages.go | 23 | ||||
| -rw-r--r-- | templates/layouts/_default.html | 23 | ||||
| -rw-r--r-- | web/web.go | 2 |
6 files changed, 30 insertions, 25 deletions
diff --git a/content/index.md b/content/index.md index 240517a..94bcd77 100644 --- a/content/index.md +++ b/content/index.md @@ -1,5 +1,6 @@ --- title: home +nav: "/" --- ## me * backend cloud software engineer diff --git a/content/posts.md b/content/posts.md index 020e1cc..011720b 100644 --- a/content/posts.md +++ b/content/posts.md @@ -1,5 +1,6 @@ --- title: posts +nav: /posts --- {{range .Collections.posts}} - [{{.Meta.title}}]({{.Path}}) diff --git a/markdown/markdown.go b/markdown/markdown.go index 658e527..1a529f6 100644 --- a/markdown/markdown.go +++ b/markdown/markdown.go @@ -60,7 +60,10 @@ func parseMarkdownFile(embedded fs.FS, path string) (Content, error) { if err != nil { return Content{}, fmt.Errorf("failed to parse frontmatter: %v", err) } - path = strings.Replace(path, ".md", "", 1) + path = "/" + strings.Replace(path, ".md", "", 1) + if path == "/index" { + path = "/" + } mc := Content{ Body: string(rest), diff --git a/pages/pages.go b/pages/pages.go index 63c3432..2caa866 100644 --- a/pages/pages.go +++ b/pages/pages.go @@ -12,6 +12,7 @@ import ( type GlobalState struct { Collections map[string][]markdown.Content + Nav map[string]markdown.Content } type ParserPair struct { @@ -67,21 +68,25 @@ func Collect() ([]Page, error) { Collections: map[string][]markdown.Content{ "all": contents, }, + Nav: map[string]markdown.Content{}, } for _, content := range contents { tags, ok := content.Meta["tags"] - if !ok { - continue + if ok { + switch tags := tags.(type) { + case string: + gs.Collections[tags] = append(gs.Collections[tags], content) + case []string: + for _, tag := range tags { + gs.Collections[tag] = append(gs.Collections[tag], content) + } + } } - switch tags := tags.(type) { - case string: - gs.Collections[tags] = append(gs.Collections[tags], content) - case []string: - for _, tag := range tags { - gs.Collections[tag] = append(gs.Collections[tag], content) - } + nav, ok := content.Meta["nav"] + if ok { + gs.Nav[nav.(string)] = content } } diff --git a/templates/layouts/_default.html b/templates/layouts/_default.html index 09b2239..2e7ec0c 100644 --- a/templates/layouts/_default.html +++ b/templates/layouts/_default.html @@ -61,20 +61,15 @@ <sub>high effort, low reward</sub> <nav> <ul> - {{ if eq .Path "index" }} - <li><a href="/">home</a></li> - {{else}} - <li><a class="no-decorations" href="/">home</a></li> - {{end}} - {{ range $key, $value := .Collections }} - {{if ne $key "all"}} - {{ if eq $.Path $key }} - <li><a href="/{{$key}}">{{$key}}</a></li> - {{else}} - <li><a class="no-decorations" href="/{{$key}}">{{$key}}</a></li> - {{end}} - {{end}} - {{end}} + <!--{{$.Path}}--> + {{ range $key, $value := .Nav}} + <!--{{$key}}--> + {{ if eq $.Path $key }} + <li><a href="{{$key}}">{{$value.Meta.title}}</a></li> + {{else}} + <li><a class="no-decorations" href="{{$key}}">{{$value.Meta.title}}</a></li> + {{end}} + {{end}} </ul> </nav> {{ template "content" . }} @@ -38,7 +38,7 @@ func New(logger *zap.Logger) (*http.Server, error) { mux.Handle("GET /static/", http.StripPrefix("/static/", http.FileServer(http.FS(staticFs)))) for _, page := range pages { - mux.HandleFunc("GET /"+page.Path, func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("GET "+page.Path, func(w http.ResponseWriter, r *http.Request) { w.Write([]byte(page.Content)) }) } |
