mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-11-07 11:03:03 +00:00
Create system for adding data attributes to Base body
This commit is contained in:
11
auth/web.go
11
auth/web.go
@@ -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))))
|
w.Write([]byte(viewutil.Base(viewutil.MetaFrom(w, rq), lc.Get("ui.users_title"), UserList(lc), []string{})))
|
||||||
}
|
}
|
||||||
|
|
||||||
func handlerLock(w http.ResponseWriter, rq *http.Request) {
|
func handlerLock(w http.ResponseWriter, rq *http.Request) {
|
||||||
@@ -57,6 +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{},
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
@@ -81,6 +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{},
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
@@ -111,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)),
|
viewutil.Base(viewutil.MetaFrom(w, rq), lc.Get("auth.logout_title"), Logout(can, lc), []string{}),
|
||||||
)
|
)
|
||||||
} else if rq.Method == http.MethodPost {
|
} else if rq.Method == http.MethodPost {
|
||||||
user.LogoutFromRequest(w, rq)
|
user.LogoutFromRequest(w, rq)
|
||||||
@@ -131,6 +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{},
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
} else if rq.Method == http.MethodPost {
|
} else if rq.Method == http.MethodPost {
|
||||||
@@ -142,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)))
|
_, _ = io.WriteString(w, viewutil.Base(viewutil.MetaFrom(w, rq), err.Error(), LoginError(err.Error(), lc), []string{}))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
http.Redirect(w, rq, "/", http.StatusSeeOther)
|
http.Redirect(w, rq, "/", http.StatusSeeOther)
|
||||||
@@ -189,6 +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{},
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
@@ -209,6 +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{},
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -125,6 +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{},
|
||||||
))
|
))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
|||||||
@@ -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}}">
|
<body data-rrh-addr="{{if .Addr}}{{.Addr}}{{else}}{{.Meta.Addr}}{{end}}"{{range .ExtraData}} data-rrh-{{.}}=""{{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">
|
||||||
|
|||||||
@@ -22,6 +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{},
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,6 +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
|
||||||
|
ExtraData []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bd *BaseData) withBaseValues(meta Meta, headerLinks []HeaderLink, commonScripts []string) {
|
func (bd *BaseData) withBaseValues(meta Meta, headerLinks []HeaderLink, commonScripts []string) {
|
||||||
@@ -108,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, headElements ...string) string {
|
func Base(meta Meta, title, body string, extraData []string, headElements ...string) string {
|
||||||
var w strings.Builder
|
var w strings.Builder
|
||||||
meta.W = &w
|
meta.W = &w
|
||||||
t := localizedBaseWithWeirdBody(meta)
|
t := localizedBaseWithWeirdBody(meta)
|
||||||
@@ -119,6 +120,7 @@ func Base(meta Meta, title, body string, headElements ...string) string {
|
|||||||
HeaderLinks: HeaderLinks,
|
HeaderLinks: HeaderLinks,
|
||||||
CommonScripts: cfg.CommonScripts,
|
CommonScripts: cfg.CommonScripts,
|
||||||
Body: body,
|
Body: body,
|
||||||
|
ExtraData: extraData,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
|||||||
@@ -49,7 +49,9 @@ func handlerRemoveMedia(w http.ResponseWriter, rq *http.Request) {
|
|||||||
viewutil.Base(
|
viewutil.Base(
|
||||||
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{},
|
||||||
|
))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch h := h.(type) {
|
switch h := h.(type) {
|
||||||
@@ -175,7 +177,8 @@ func handlerEdit(w http.ResponseWriter, rq *http.Request) {
|
|||||||
viewutil.Base(
|
viewutil.Base(
|
||||||
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{}))
|
||||||
}
|
}
|
||||||
|
|
||||||
// handlerUploadText uploads a new text part for the hypha.
|
// handlerUploadText uploads a new text part for the hypha.
|
||||||
@@ -213,7 +216,9 @@ func handlerUploadText(w http.ResponseWriter, rq *http.Request) {
|
|||||||
textData,
|
textData,
|
||||||
message,
|
message,
|
||||||
"",
|
"",
|
||||||
mycomarkup.BlocksToHTML(ctx, mycomarkup.BlockTree(ctx)))))
|
mycomarkup.BlocksToHTML(ctx, mycomarkup.BlockTree(ctx))),
|
||||||
|
[]string{},
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
http.Redirect(w, rq, "/hypha/"+hyphaName, http.StatusSeeOther)
|
http.Redirect(w, rq, "/hypha/"+hyphaName, http.StatusSeeOther)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,9 @@ func handlerMedia(w http.ResponseWriter, rq *http.Request) {
|
|||||||
viewutil.Base(
|
viewutil.Base(
|
||||||
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{},
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
// handlerRevisionText sends Mycomarkup text of the hypha at the given revision. See also: handlerRevision, handlerText.
|
// handlerRevisionText sends Mycomarkup text of the hypha at the given revision. See also: handlerRevision, handlerText.
|
||||||
@@ -141,6 +143,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{},
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -191,6 +194,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{},
|
||||||
openGraph))
|
openGraph))
|
||||||
case hyphae.ExistingHypha:
|
case hyphae.ExistingHypha:
|
||||||
fileContentsT, errT := os.ReadFile(h.TextFilePath())
|
fileContentsT, errT := os.ReadFile(h.TextFilePath())
|
||||||
@@ -206,11 +210,13 @@ func handlerHypha(w http.ResponseWriter, rq *http.Request) {
|
|||||||
contents = mycoopts.Media(h, lc) + contents
|
contents = mycoopts.Media(h, lc) + contents
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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),
|
||||||
|
[]string{},
|
||||||
openGraph))
|
openGraph))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user