diff --git a/internal/http/handlers.go b/internal/http/handlers.go index 6d0459c..03e427f 100644 --- a/internal/http/handlers.go +++ b/internal/http/handlers.go @@ -1,6 +1,7 @@ package http import ( + "log" "math" "net/http" "strconv" @@ -52,19 +53,32 @@ func (h *Handlers) Mindflow(w http.ResponseWriter, r *http.Request) { entry.Body = strings.ReplaceAll(entry.Body, "\\n", "\n") } - web.Mindflow("/ Mindflow", posts, r, w) + categories, err := h.mindflowDB.Categories() + if err != nil { + log.Println(err) + return + } + + web.Mindflow("/ Mindflow", posts, categories, r, w) } func (h *Handlers) MindflowAdmin(w http.ResponseWriter, r *http.Request) { posts, err := h.mindflowDB.Posts() if err != nil { + log.Println(err) return } for _, entry := range posts { entry.Body = strings.ReplaceAll(entry.Body, "\\n", "\n") } - web.MindflowAdmin("/ Mindflow Administration", posts, r, w) + categories, err := h.mindflowDB.Categories() + if err != nil { + log.Println(err) + return + } + + web.MindflowAdmin("/ Mindflow Administration", posts, categories, r, w) } func (h *Handlers) About(w http.ResponseWriter, r *http.Request) { diff --git a/web/templates/mindflow.pug b/web/templates/mindflow.pug index 51129c0..a7e25e4 100755 --- a/web/templates/mindflow.pug +++ b/web/templates/mindflow.pug @@ -15,14 +15,14 @@ block nav h1 Mindflow block content - :go:func Mindflow(title string, posts []mindflow.Post, r *http.Request) + :go:func Mindflow(title string, posts []mindflow.Post, categories []mindflow.Category, r *http.Request) p.center Here I post updates on websites and infrastructure, my very important opinions and thoughts no one asked for. If you'd like to subscribe to this bullshittery then #[a(href='rss.xml') RSS feed] at your service. :) section#filter.hidden p.center button(name='all') All - button(name='update') Updates - button(name='diary') Diary + each category in categories + button(name=strings.ToLower(category.Name)) #{category.Name} section if (len(posts) > 0) each post in posts diff --git a/web/templates/mindflow_admin.pug b/web/templates/mindflow_admin.pug index caccec8..288da19 100755 --- a/web/templates/mindflow_admin.pug +++ b/web/templates/mindflow_admin.pug @@ -17,17 +17,20 @@ block nav h1 Mindflow Admin block content - :go:func MindflowAdmin(title string, posts []mindflow.Post, r *http.Request) + :go:func MindflowAdmin(title string, posts []mindflow.Post, categories []mindflow.Category, r *http.Request) section form(id='add' action='/api/mindflow', method='POST') select(name='category' required='') - option(value='1' selected='') Update - option(value='2') Diary - option(value='0') New category + each category in categories + if (category.ID == 1) + option(value=category.ID selected='') #{category.Name} + else + option(value=category.ID) #{category.Name} + option(value='0') -- New category -- input(type='text', placeholder='New category name' name='new-category') input(type='text', placeholder='Title' name='title' required='') - textarea(placeholder='Body post' name='body' required='') + textarea(placeholder='Body post' name!='body' required='') button(type="submit") Add section if (len(posts) > 0)