mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-01-05 17:40:26 +00:00
Categories: Add category list
* /category lists categories * /category/<cat> shows the category
This commit is contained in:
parent
cc4f3c9aed
commit
7865f77060
@ -16,6 +16,16 @@ package categories
|
||||
|
||||
import "sync"
|
||||
|
||||
// List returns names of all categories.
|
||||
func List() (categoryList []string) {
|
||||
mutex.RLock()
|
||||
for cat, _ := range categoryToHyphae {
|
||||
categoryList = append(categoryList, cat)
|
||||
}
|
||||
mutex.RUnlock()
|
||||
return categoryList
|
||||
}
|
||||
|
||||
// WithHypha returns what categories have the given hypha. The hypha name must be canonical.
|
||||
func WithHypha(hyphaName string) (categoryList []string) {
|
||||
mutex.RLock()
|
||||
|
@ -64,3 +64,24 @@ func CategoryPageHTML(meta Meta, catName string) {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
|
||||
func CategoryListHTML(meta Meta) {
|
||||
var buf strings.Builder
|
||||
err := categoryT.ExecuteTemplate(&buf, "category list", struct {
|
||||
Categories []string
|
||||
}{
|
||||
categories.List(),
|
||||
})
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
_, err = io.WriteString(meta.W, BaseHTML(
|
||||
"Category list",
|
||||
buf.String(),
|
||||
meta.Lc,
|
||||
meta.U,
|
||||
))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
|
@ -51,4 +51,21 @@
|
||||
</li>
|
||||
</ul>
|
||||
</main>
|
||||
{{end}}
|
||||
|
||||
{{define "category list"}}
|
||||
<main class="main-width category-list">
|
||||
<h1>Category list</h1>
|
||||
{{if len .Categories}}
|
||||
<ul class="category-list__entries">
|
||||
{{range .Categories}}
|
||||
<li class="category-list__entry">
|
||||
<a class="wikilink" href="/category/{{.}}">{{beautifulName .}}</a>
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
{{else}}
|
||||
<p>This wiki has no categories.</p>
|
||||
{{end}}
|
||||
</main>
|
||||
{{end}}
|
@ -12,6 +12,11 @@ func initCategories(r *mux.Router) {
|
||||
r.PathPrefix("/add-to-category").HandlerFunc(handlerAddToCategory).Methods("POST")
|
||||
r.PathPrefix("/remove-from-category").HandlerFunc(handlerRemoveFromCategory).Methods("POST")
|
||||
r.PathPrefix("/category/").HandlerFunc(handlerCategory).Methods("GET")
|
||||
r.PathPrefix("/category").HandlerFunc(handlerListCategory).Methods("GET")
|
||||
}
|
||||
|
||||
func handlerListCategory(w http.ResponseWriter, rq *http.Request) {
|
||||
views.CategoryListHTML(views.MetaFrom(w, rq))
|
||||
}
|
||||
|
||||
func handlerCategory(w http.ResponseWriter, rq *http.Request) {
|
||||
|
Loading…
Reference in New Issue
Block a user