From f3437d93c85ff925822f073e9da2a248127ec0cd Mon Sep 17 00:00:00 2001 From: kez Date: Sat, 13 Aug 2022 05:03:21 -0700 Subject: [PATCH] Add hypha categories to Base body data attributes --- categories/categories.go | 4 ++-- categories/views.go | 2 +- web/readers.go | 7 ++++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/categories/categories.go b/categories/categories.go index 3981e04..4a093f5 100644 --- a/categories/categories.go +++ b/categories/categories.go @@ -33,8 +33,8 @@ func listOfCategories() (categoryList []string) { return categoryList } -// categoriesWithHypha returns what categories have the given hypha. The hypha name must be canonical. -func categoriesWithHypha(hyphaName string) (categoryList []string) { +// CategoriesWithHypha returns what categories have the given hypha. The hypha name must be canonical. +func CategoriesWithHypha(hyphaName string) (categoryList []string) { mutex.RLock() defer mutex.RUnlock() if node, ok := hyphaToCategories[hyphaName]; ok { diff --git a/categories/views.go b/categories/views.go index 15ebe07..9292ede 100644 --- a/categories/views.go +++ b/categories/views.go @@ -52,7 +52,7 @@ func CategoryCard(meta viewutil.Meta, hyphaName string) string { var buf strings.Builder err := viewCardChain.Get(meta).ExecuteTemplate(&buf, "category card", cardData{ HyphaName: hyphaName, - Categories: categoriesWithHypha(hyphaName), + Categories: CategoriesWithHypha(hyphaName), GivenPermissionToModify: meta.U.CanProceed("add-to-category"), }) if err != nil { diff --git a/web/readers.go b/web/readers.go index cd48f86..3b9dfcd 100644 --- a/web/readers.go +++ b/web/readers.go @@ -7,6 +7,7 @@ import ( views2 "github.com/bouncepaw/mycorrhiza/hypview" "github.com/bouncepaw/mycorrhiza/mycoopts" "github.com/bouncepaw/mycorrhiza/viewutil" + "github.com/bouncepaw/mycorrhiza/categories" "io" "log" "net/http" @@ -210,13 +211,17 @@ func handlerHypha(w http.ResponseWriter, rq *http.Request) { contents = mycoopts.Media(h, lc) + contents } + cats := []string{} + for _, category := range categories.CategoriesWithHypha(h.CanonicalName()) { + cats = append(cats, "cat-" + category) + } util.HTTP200Page(w, viewutil.Base( viewutil.MetaFrom(w, rq), util.BeautifulName(hyphaName), views2.Hypha(viewutil.MetaFrom(w, rq), h, contents), - []string{}, + cats, openGraph)) } }