1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-01-07 10:20:26 +00:00

Embed data-rrh-addr attribute on all pages

You can define the attribute more precisely if you want to
This commit is contained in:
Timur Ismagilov 2022-04-23 21:53:15 +03:00
parent 9200739bf8
commit d7b4ea9002
6 changed files with 20 additions and 14 deletions

View File

@ -51,6 +51,7 @@ func viewBacklinks(meta viewutil.Meta, hyphaName string, backlinks []string) {
if err := chain.Get(meta).ExecuteTemplate(meta.W, "page", backlinksData{ if err := chain.Get(meta).ExecuteTemplate(meta.W, "page", backlinksData{
BaseData: viewutil.BaseData{ BaseData: viewutil.BaseData{
Meta: meta, Meta: meta,
Addr: "/backlinks/" + hyphaName,
HeaderLinks: cfg.HeaderLinks, HeaderLinks: cfg.HeaderLinks,
CommonScripts: cfg.CommonScripts, CommonScripts: cfg.CommonScripts,
}, },

View File

@ -53,9 +53,9 @@ type cardData struct {
func CategoryCard(meta viewutil.Meta, hyphaName string) string { func CategoryCard(meta viewutil.Meta, hyphaName string) string {
var buf strings.Builder var buf strings.Builder
err := viewCardChain.Get(meta).ExecuteTemplate(&buf, "category card", cardData{ err := viewCardChain.Get(meta).ExecuteTemplate(&buf, "category card", cardData{
hyphaName, HyphaName: hyphaName,
categoriesWithHypha(hyphaName), Categories: categoriesWithHypha(hyphaName),
meta.U.CanProceed("add-to-category"), GivenPermissionToModify: meta.U.CanProceed("add-to-category"),
}) })
if err != nil { if err != nil {
log.Println(err) log.Println(err)
@ -76,6 +76,7 @@ func categoryPage(meta viewutil.Meta, catName string) {
Meta: meta, Meta: meta,
HeaderLinks: cfg.HeaderLinks, HeaderLinks: cfg.HeaderLinks,
CommonScripts: cfg.CommonScripts, CommonScripts: cfg.CommonScripts,
Addr: "/category/" + catName,
}, },
CatName: catName, CatName: catName,
Hyphae: hyphaeInCategory(catName), Hyphae: hyphaeInCategory(catName),

View File

@ -73,12 +73,12 @@ func handlerHelp(w http.ResponseWriter, rq *http.Request) {
content, err := Get(articlePath) content, err := Get(articlePath)
if err != nil && strings.HasPrefix(err.Error(), "open") { if err != nil && strings.HasPrefix(err.Error(), "open") {
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
viewHelp(meta, lang, "") viewHelp(meta, lang, "", articlePath)
return return
} }
if err != nil { if err != nil {
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
viewHelp(meta, lang, err.Error()) viewHelp(meta, lang, err.Error(), articlePath)
return return
} }
@ -87,7 +87,7 @@ func handlerHelp(w http.ResponseWriter, rq *http.Request) {
ast := mycomarkup.BlockTree(ctx) ast := mycomarkup.BlockTree(ctx)
result := mycomarkup.BlocksToHTML(ctx, ast) result := mycomarkup.BlocksToHTML(ctx, ast)
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
viewHelp(meta, lang, result) viewHelp(meta, lang, result, articlePath)
} }
type helpData struct { type helpData struct {
@ -96,12 +96,13 @@ type helpData struct {
Lang string Lang string
} }
func viewHelp(meta viewutil.Meta, lang, contentsHTML string) { func viewHelp(meta viewutil.Meta, lang, contentsHTML, articlePath string) {
if err := chain.Get(meta).ExecuteTemplate(meta.W, "page", helpData{ if err := chain.Get(meta).ExecuteTemplate(meta.W, "page", helpData{
BaseData: viewutil.BaseData{ BaseData: viewutil.BaseData{
Meta: meta, Meta: meta,
HeaderLinks: cfg.HeaderLinks, HeaderLinks: cfg.HeaderLinks,
CommonScripts: cfg.CommonScripts, CommonScripts: cfg.CommonScripts,
Addr: "/help/" + articlePath,
}, },
ContentsHTML: contentsHTML, ContentsHTML: contentsHTML,
Lang: lang, Lang: lang,

View File

@ -10,7 +10,7 @@
<script src="/static/shortcuts.js"></script> <script src="/static/shortcuts.js"></script>
{{range .HeadElements}}{{.}}{{end}} {{range .HeadElements}}{{.}}{{end}}
</head> </head>
<body> <body data-rrh-addr="{{if .Addr}}{{.Addr}}{{else}}{{.Meta.Addr}}{{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

@ -9,17 +9,19 @@ import (
// Meta is a bundle of common stuffs used by views, templates. // Meta is a bundle of common stuffs used by views, templates.
type Meta struct { type Meta struct {
Lc *l18n.Localizer Lc *l18n.Localizer
U *user.User U *user.User
W io.Writer W io.Writer
Addr string
} }
// MetaFrom makes a Meta from the given data. You are meant to further modify it. // MetaFrom makes a Meta from the given data. You are meant to further modify it.
func MetaFrom(w http.ResponseWriter, rq *http.Request) Meta { func MetaFrom(w http.ResponseWriter, rq *http.Request) Meta {
return Meta{ return Meta{
Lc: l18n.FromRequest(rq), Lc: l18n.FromRequest(rq),
U: user.FromRequest(rq), U: user.FromRequest(rq),
W: w, W: w,
Addr: rq.URL.Path,
} }
} }

View File

@ -65,6 +65,7 @@ type BaseData struct {
HeadElements []string HeadElements []string
HeaderLinks []cfg.HeaderLink HeaderLinks []cfg.HeaderLink
CommonScripts []string CommonScripts []string
Addr string
Title string // TODO: remove Title string // TODO: remove
Body string // TODO: remove Body string // TODO: remove
} }