mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-01-05 17:40: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:
parent
9200739bf8
commit
d7b4ea9002
@ -51,6 +51,7 @@ func viewBacklinks(meta viewutil.Meta, hyphaName string, backlinks []string) {
|
||||
if err := chain.Get(meta).ExecuteTemplate(meta.W, "page", backlinksData{
|
||||
BaseData: viewutil.BaseData{
|
||||
Meta: meta,
|
||||
Addr: "/backlinks/" + hyphaName,
|
||||
HeaderLinks: cfg.HeaderLinks,
|
||||
CommonScripts: cfg.CommonScripts,
|
||||
},
|
||||
|
@ -53,9 +53,9 @@ type cardData struct {
|
||||
func CategoryCard(meta viewutil.Meta, hyphaName string) string {
|
||||
var buf strings.Builder
|
||||
err := viewCardChain.Get(meta).ExecuteTemplate(&buf, "category card", cardData{
|
||||
hyphaName,
|
||||
categoriesWithHypha(hyphaName),
|
||||
meta.U.CanProceed("add-to-category"),
|
||||
HyphaName: hyphaName,
|
||||
Categories: categoriesWithHypha(hyphaName),
|
||||
GivenPermissionToModify: meta.U.CanProceed("add-to-category"),
|
||||
})
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
@ -76,6 +76,7 @@ func categoryPage(meta viewutil.Meta, catName string) {
|
||||
Meta: meta,
|
||||
HeaderLinks: cfg.HeaderLinks,
|
||||
CommonScripts: cfg.CommonScripts,
|
||||
Addr: "/category/" + catName,
|
||||
},
|
||||
CatName: catName,
|
||||
Hyphae: hyphaeInCategory(catName),
|
||||
|
@ -73,12 +73,12 @@ func handlerHelp(w http.ResponseWriter, rq *http.Request) {
|
||||
content, err := Get(articlePath)
|
||||
if err != nil && strings.HasPrefix(err.Error(), "open") {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
viewHelp(meta, lang, "")
|
||||
viewHelp(meta, lang, "", articlePath)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
viewHelp(meta, lang, err.Error())
|
||||
viewHelp(meta, lang, err.Error(), articlePath)
|
||||
return
|
||||
}
|
||||
|
||||
@ -87,7 +87,7 @@ func handlerHelp(w http.ResponseWriter, rq *http.Request) {
|
||||
ast := mycomarkup.BlockTree(ctx)
|
||||
result := mycomarkup.BlocksToHTML(ctx, ast)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
viewHelp(meta, lang, result)
|
||||
viewHelp(meta, lang, result, articlePath)
|
||||
}
|
||||
|
||||
type helpData struct {
|
||||
@ -96,12 +96,13 @@ type helpData struct {
|
||||
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{
|
||||
BaseData: viewutil.BaseData{
|
||||
Meta: meta,
|
||||
HeaderLinks: cfg.HeaderLinks,
|
||||
CommonScripts: cfg.CommonScripts,
|
||||
Addr: "/help/" + articlePath,
|
||||
},
|
||||
ContentsHTML: contentsHTML,
|
||||
Lang: lang,
|
||||
|
@ -10,7 +10,7 @@
|
||||
<script src="/static/shortcuts.js"></script>
|
||||
{{range .HeadElements}}{{.}}{{end}}
|
||||
</head>
|
||||
<body>
|
||||
<body data-rrh-addr="{{if .Addr}}{{.Addr}}{{else}}{{.Meta.Addr}}{{end}}">
|
||||
<header>
|
||||
<nav class="main-width top-bar">
|
||||
<ul class="top-bar__wrapper">
|
||||
|
@ -9,17 +9,19 @@ import (
|
||||
|
||||
// Meta is a bundle of common stuffs used by views, templates.
|
||||
type Meta struct {
|
||||
Lc *l18n.Localizer
|
||||
U *user.User
|
||||
W io.Writer
|
||||
Lc *l18n.Localizer
|
||||
U *user.User
|
||||
W io.Writer
|
||||
Addr string
|
||||
}
|
||||
|
||||
// MetaFrom makes a Meta from the given data. You are meant to further modify it.
|
||||
func MetaFrom(w http.ResponseWriter, rq *http.Request) Meta {
|
||||
return Meta{
|
||||
Lc: l18n.FromRequest(rq),
|
||||
U: user.FromRequest(rq),
|
||||
W: w,
|
||||
Lc: l18n.FromRequest(rq),
|
||||
U: user.FromRequest(rq),
|
||||
W: w,
|
||||
Addr: rq.URL.Path,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,6 +65,7 @@ type BaseData struct {
|
||||
HeadElements []string
|
||||
HeaderLinks []cfg.HeaderLink
|
||||
CommonScripts []string
|
||||
Addr string
|
||||
Title string // TODO: remove
|
||||
Body string // TODO: remove
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user