1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-07-01 09:22:50 +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/bouncepaw/mycorrhiza/views"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"io" "io"
"log"
"net/http" "net/http"
"strings"
) )
func initCategories(r *mux.Router) { func initCategories(r *mux.Router) {
@ -18,14 +20,18 @@ func initCategories(r *mux.Router) {
} }
func handlerListCategory(w http.ResponseWriter, rq *http.Request) { func handlerListCategory(w http.ResponseWriter, rq *http.Request) {
log.Println("Viewing list of categories")
views.CategoryList(views.MetaFrom(w, rq)) views.CategoryList(views.MetaFrom(w, rq))
} }
func handlerCategory(w http.ResponseWriter, rq *http.Request) { func handlerCategory(w http.ResponseWriter, rq *http.Request) {
util.PrepareRq(rq) util.PrepareRq(rq)
var ( catName := util.CanonicalName(strings.TrimPrefix(strings.TrimPrefix(rq.URL.Path, "/category"), "/"))
catName = util.HyphaNameFromRq(rq, "category") if catName == "" {
) handlerListCategory(w, rq)
return
}
log.Println("Viewing category", catName)
views.CategoryPage(views.MetaFrom(w, rq), catName) views.CategoryPage(views.MetaFrom(w, rq), catName)
} }