1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-07-26 04:22:48 +00:00

Turn BodyAttributes into a map

BodyAttributes is now a map of attribute name -> attribute value. This
was done because attribute names have a restricted set of characters,
but attribute values are much less restrictive
This commit is contained in:
kez 2022-08-14 15:36:55 -07:00 committed by Timur Ismagilov
parent e0f2868d34
commit c1946d8849
7 changed files with 22 additions and 25 deletions

View File

@ -39,7 +39,7 @@ func handlerUserList(w http.ResponseWriter, rq *http.Request) {
lc := l18n.FromRequest(rq) lc := l18n.FromRequest(rq)
w.Header().Set("Content-Type", mime.TypeByExtension(".html")) w.Header().Set("Content-Type", mime.TypeByExtension(".html"))
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
w.Write([]byte(viewutil.Base(viewutil.MetaFrom(w, rq), lc.Get("ui.users_title"), UserList(lc), []string{}))) w.Write([]byte(viewutil.Base(viewutil.MetaFrom(w, rq), lc.Get("ui.users_title"), UserList(lc), map[string]string{})))
} }
func handlerLock(w http.ResponseWriter, rq *http.Request) { func handlerLock(w http.ResponseWriter, rq *http.Request) {
@ -57,7 +57,7 @@ func handlerRegister(w http.ResponseWriter, rq *http.Request) {
viewutil.MetaFrom(w, rq), viewutil.MetaFrom(w, rq),
lc.Get("auth.register_title"), lc.Get("auth.register_title"),
Register(rq), Register(rq),
[]string{}, map[string]string{},
), ),
) )
return return
@ -82,7 +82,7 @@ func handlerRegister(w http.ResponseWriter, rq *http.Request) {
err.Error(), err.Error(),
lc.Get("auth.try_again"), lc.Get("auth.try_again"),
), ),
[]string{}, map[string]string{},
), ),
) )
return return
@ -113,7 +113,7 @@ func handlerLogout(w http.ResponseWriter, rq *http.Request) {
} }
_, _ = io.WriteString( _, _ = io.WriteString(
w, w,
viewutil.Base(viewutil.MetaFrom(w, rq), lc.Get("auth.logout_title"), Logout(can, lc), []string{}), viewutil.Base(viewutil.MetaFrom(w, rq), lc.Get("auth.logout_title"), Logout(can, lc), map[string]string{}),
) )
} else if rq.Method == http.MethodPost { } else if rq.Method == http.MethodPost {
user.LogoutFromRequest(w, rq) user.LogoutFromRequest(w, rq)
@ -133,7 +133,7 @@ func handlerLogin(w http.ResponseWriter, rq *http.Request) {
viewutil.MetaFrom(w, rq), viewutil.MetaFrom(w, rq),
lc.Get("auth.login_title"), lc.Get("auth.login_title"),
Login(lc), Login(lc),
[]string{}, map[string]string{},
), ),
) )
} else if rq.Method == http.MethodPost { } else if rq.Method == http.MethodPost {
@ -145,7 +145,7 @@ func handlerLogin(w http.ResponseWriter, rq *http.Request) {
if err != nil { if err != nil {
w.Header().Set("Content-Type", "text/html;charset=utf-8") w.Header().Set("Content-Type", "text/html;charset=utf-8")
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
_, _ = io.WriteString(w, viewutil.Base(viewutil.MetaFrom(w, rq), err.Error(), LoginError(err.Error(), lc), []string{})) _, _ = io.WriteString(w, viewutil.Base(viewutil.MetaFrom(w, rq), err.Error(), LoginError(err.Error(), lc), map[string]string{}))
return return
} }
http.Redirect(w, rq, "/", http.StatusSeeOther) http.Redirect(w, rq, "/", http.StatusSeeOther)
@ -192,7 +192,7 @@ func handlerTelegramLogin(w http.ResponseWriter, rq *http.Request) {
err.Error(), err.Error(),
lc.Get("auth.go_login"), lc.Get("auth.go_login"),
), ),
[]string{}, map[string]string{},
), ),
) )
return return
@ -213,7 +213,7 @@ func handlerTelegramLogin(w http.ResponseWriter, rq *http.Request) {
err.Error(), err.Error(),
lc.Get("auth.go_login"), lc.Get("auth.go_login"),
), ),
[]string{}, map[string]string{},
), ),
) )
return return

View File

@ -125,7 +125,7 @@ func handlerAbout(w http.ResponseWriter, rq *http.Request) {
viewutil.MetaFrom(w, rq), viewutil.MetaFrom(w, rq),
title, title,
AboutHTML(lc), AboutHTML(lc),
[]string{}, map[string]string{},
)) ))
if err != nil { if err != nil {
log.Println(err) log.Println(err)

View File

@ -15,7 +15,7 @@
<script src="/static/shortcuts.js"></script> <script src="/static/shortcuts.js"></script>
{{range .HeadElements}}{{.}}{{end}} {{range .HeadElements}}{{.}}{{end}}
</head> </head>
<body data-rrh-addr="{{if .Addr}}{{.Addr}}{{else}}{{.Meta.Addr}}{{end}}"{{range .BodyAttributes}} data-rrh-{{.}}=""{{end}}> <body data-rrh-addr="{{if .Addr}}{{.Addr}}{{else}}{{.Meta.Addr}}{{end}}"{{range $key, $value := .BodyAttributes}} data-rrh-{{$key}}="{{$value}}"{{end}}>
<header> <header>
<nav class="main-width top-bar"> <nav class="main-width top-bar">
<ul class="top-bar__wrapper"> <ul class="top-bar__wrapper">

View File

@ -22,7 +22,7 @@ func HttpErr(meta Meta, status int, name, errMsg string) {
name, name,
meta.Lc.Get("ui.error_go_back"), meta.Lc.Get("ui.error_go_back"),
), ),
[]string{}, map[string]string{},
), ),
) )
} }

View File

@ -98,7 +98,7 @@ type BaseData struct {
Addr string Addr string
Title string // TODO: remove Title string // TODO: remove
Body string // TODO: remove Body string // TODO: remove
BodyAttributes []string BodyAttributes map[string]string
} }
func (bd *BaseData) withBaseValues(meta Meta, headerLinks []HeaderLink, commonScripts []string) { func (bd *BaseData) withBaseValues(meta Meta, headerLinks []HeaderLink, commonScripts []string) {
@ -109,7 +109,7 @@ func (bd *BaseData) withBaseValues(meta Meta, headerLinks []HeaderLink, commonSc
// Base is a temporary wrapper around BaseEn and BaseRu, meant to facilitate the migration from qtpl. // Base is a temporary wrapper around BaseEn and BaseRu, meant to facilitate the migration from qtpl.
// TODO: get rid of this // TODO: get rid of this
func Base(meta Meta, title, body string, extraData []string, headElements ...string) string { func Base(meta Meta, title, body string, bodyAttributes map[string]string, headElements ...string) string {
var w strings.Builder var w strings.Builder
meta.W = &w meta.W = &w
t := localizedBaseWithWeirdBody(meta) t := localizedBaseWithWeirdBody(meta)
@ -120,7 +120,7 @@ func Base(meta Meta, title, body string, extraData []string, headElements ...str
HeaderLinks: HeaderLinks, HeaderLinks: HeaderLinks,
CommonScripts: cfg.CommonScripts, CommonScripts: cfg.CommonScripts,
Body: body, Body: body,
BodyAttributes: extraData, BodyAttributes: bodyAttributes,
}) })
if err != nil { if err != nil {
log.Println(err) log.Println(err)

View File

@ -50,7 +50,7 @@ func handlerRemoveMedia(w http.ResponseWriter, rq *http.Request) {
meta, meta,
fmt.Sprintf(lc.Get("ui.ask_remove_media"), util.BeautifulName(h.CanonicalName())), fmt.Sprintf(lc.Get("ui.ask_remove_media"), util.BeautifulName(h.CanonicalName())),
hypview.RemoveMediaAsk(rq, h.CanonicalName()), hypview.RemoveMediaAsk(rq, h.CanonicalName()),
[]string{}, map[string]string{},
)) ))
return return
} }
@ -178,7 +178,7 @@ func handlerEdit(w http.ResponseWriter, rq *http.Request) {
meta, meta,
fmt.Sprintf(lc.Get("edit.title"), util.BeautifulName(hyphaName)), fmt.Sprintf(lc.Get("edit.title"), util.BeautifulName(hyphaName)),
hypview.Editor(rq, hyphaName, textAreaFill, warning), hypview.Editor(rq, hyphaName, textAreaFill, warning),
[]string{})) map[string]string{}))
} }
// handlerUploadText uploads a new text part for the hypha. // handlerUploadText uploads a new text part for the hypha.
@ -217,7 +217,7 @@ func handlerUploadText(w http.ResponseWriter, rq *http.Request) {
message, message,
"", "",
mycomarkup.BlocksToHTML(ctx, mycomarkup.BlockTree(ctx))), mycomarkup.BlocksToHTML(ctx, mycomarkup.BlockTree(ctx))),
[]string{}, map[string]string{},
)) ))
} else { } else {
http.Redirect(w, rq, "/hypha/"+hyphaName, http.StatusSeeOther) http.Redirect(w, rq, "/hypha/"+hyphaName, http.StatusSeeOther)

View File

@ -50,7 +50,7 @@ func handlerMedia(w http.ResponseWriter, rq *http.Request) {
viewutil.MetaFrom(w, rq), viewutil.MetaFrom(w, rq),
lc.Get("ui.media_title", &l18n.Replacements{"name": util.BeautifulName(hyphaName)}), lc.Get("ui.media_title", &l18n.Replacements{"name": util.BeautifulName(hyphaName)}),
views2.MediaMenu(rq, h, u), views2.MediaMenu(rq, h, u),
[]string{}, map[string]string{},
)) ))
} }
@ -144,7 +144,7 @@ func handlerRevision(w http.ResponseWriter, rq *http.Request) {
viewutil.MetaFrom(w, rq), viewutil.MetaFrom(w, rq),
lc.Get("ui.revision_title", &l18n.Replacements{"name": util.BeautifulName(hyphaName), "rev": revHash}), lc.Get("ui.revision_title", &l18n.Replacements{"name": util.BeautifulName(hyphaName), "rev": revHash}),
page, page,
[]string{}, map[string]string{},
), ),
) )
} }
@ -195,7 +195,7 @@ func handlerHypha(w http.ResponseWriter, rq *http.Request) {
viewutil.MetaFrom(w, rq), viewutil.MetaFrom(w, rq),
util.BeautifulName(hyphaName), util.BeautifulName(hyphaName),
views2.Hypha(viewutil.MetaFrom(w, rq), h, contents), views2.Hypha(viewutil.MetaFrom(w, rq), h, contents),
[]string{}, map[string]string{},
openGraph)) openGraph))
case hyphae.ExistingHypha: case hyphae.ExistingHypha:
fileContentsT, errT := os.ReadFile(h.TextFilePath()) fileContentsT, errT := os.ReadFile(h.TextFilePath())
@ -211,17 +211,14 @@ func handlerHypha(w http.ResponseWriter, rq *http.Request) {
contents = mycoopts.Media(h, lc) + contents contents = mycoopts.Media(h, lc) + contents
} }
cats := []string{} category_list := ":" + strings.Join(categories.CategoriesWithHypha(h.CanonicalName()), ":") + ":"
for _, category := range categories.CategoriesWithHypha(h.CanonicalName()) {
cats = append(cats, "cat-" + category)
}
util.HTTP200Page(w, util.HTTP200Page(w,
viewutil.Base( viewutil.Base(
viewutil.MetaFrom(w, rq), viewutil.MetaFrom(w, rq),
util.BeautifulName(hyphaName), util.BeautifulName(hyphaName),
views2.Hypha(viewutil.MetaFrom(w, rq), h, contents), views2.Hypha(viewutil.MetaFrom(w, rq), h, contents),
cats, map[string]string{"cats": category_list},
openGraph)) openGraph))
} }
} }