Get categories from a DB.
This commit is contained in:
parent
668075cbe2
commit
3b78aa64e2
@ -1,6 +1,7 @@
|
|||||||
package http
|
package http
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"math"
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -52,19 +53,32 @@ func (h *Handlers) Mindflow(w http.ResponseWriter, r *http.Request) {
|
|||||||
entry.Body = strings.ReplaceAll(entry.Body, "\\n", "\n")
|
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) {
|
func (h *Handlers) MindflowAdmin(w http.ResponseWriter, r *http.Request) {
|
||||||
posts, err := h.mindflowDB.Posts()
|
posts, err := h.mindflowDB.Posts()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, entry := range posts {
|
for _, entry := range posts {
|
||||||
entry.Body = strings.ReplaceAll(entry.Body, "\\n", "\n")
|
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) {
|
func (h *Handlers) About(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -15,14 +15,14 @@ block nav
|
|||||||
h1 Mindflow
|
h1 Mindflow
|
||||||
|
|
||||||
block content
|
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. :)
|
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
|
section#filter.hidden
|
||||||
p.center
|
p.center
|
||||||
button(name='all') All
|
button(name='all') All
|
||||||
button(name='update') Updates
|
each category in categories
|
||||||
button(name='diary') Diary
|
button(name=strings.ToLower(category.Name)) #{category.Name}
|
||||||
section
|
section
|
||||||
if (len(posts) > 0)
|
if (len(posts) > 0)
|
||||||
each post in posts
|
each post in posts
|
||||||
|
@ -17,17 +17,20 @@ block nav
|
|||||||
h1 Mindflow Admin
|
h1 Mindflow Admin
|
||||||
|
|
||||||
block content
|
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
|
section
|
||||||
form(id='add' action='/api/mindflow', method='POST')
|
form(id='add' action='/api/mindflow', method='POST')
|
||||||
select(name='category' required='')
|
select(name='category' required='')
|
||||||
option(value='1' selected='') Update
|
each category in categories
|
||||||
option(value='2') Diary
|
if (category.ID == 1)
|
||||||
option(value='0') New category
|
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='New category name' name='new-category')
|
||||||
input(type='text', placeholder='Title' name='title' required='')
|
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
|
button(type="submit") Add
|
||||||
section
|
section
|
||||||
if (len(posts) > 0)
|
if (len(posts) > 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user