1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-05 02:29:54 +00:00

Categories: Make /category/ and /category the same

This commit is contained in:
Timur Ismagilov 2022-03-29 19:41:12 +03:00
parent bfaada494d
commit 3025aab445

View File

@ -7,7 +7,9 @@ import (
"github.com/bouncepaw/mycorrhiza/views"
"github.com/gorilla/mux"
"io"
"log"
"net/http"
"strings"
)
func initCategories(r *mux.Router) {
@ -18,14 +20,18 @@ func initCategories(r *mux.Router) {
}
func handlerListCategory(w http.ResponseWriter, rq *http.Request) {
log.Println("Viewing list of categories")
views.CategoryList(views.MetaFrom(w, rq))
}
func handlerCategory(w http.ResponseWriter, rq *http.Request) {
util.PrepareRq(rq)
var (
catName = util.HyphaNameFromRq(rq, "category")
)
catName := util.CanonicalName(strings.TrimPrefix(strings.TrimPrefix(rq.URL.Path, "/category"), "/"))
if catName == "" {
handlerListCategory(w, rq)
return
}
log.Println("Viewing category", catName)
views.CategoryPage(views.MetaFrom(w, rq), catName)
}