mirror of https://github.com/jlelse/GoBlog
Improve editor template
This commit is contained in:
parent
5dafac827c
commit
9e164d4f17
57
editor.go
57
editor.go
|
@ -7,8 +7,10 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"go.goblog.app/app/pkgs/contenttype"
|
"go.goblog.app/app/pkgs/contenttype"
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
const editorPath = "/editor"
|
const editorPath = "/editor"
|
||||||
|
@ -101,3 +103,58 @@ func (a *goBlog) editorMicropubPost(w http.ResponseWriter, r *http.Request, medi
|
||||||
_, _ = io.Copy(w, result.Body)
|
_, _ = io.Copy(w, result.Body)
|
||||||
_ = result.Body.Close()
|
_ = result.Body.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *goBlog) editorPostTemplate(blog string) string {
|
||||||
|
var builder strings.Builder
|
||||||
|
marsh := func(param string, i interface{}) {
|
||||||
|
_ = yaml.NewEncoder(&builder).Encode(map[string]interface{}{
|
||||||
|
param: i,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
bc := a.cfg.Blogs[blog]
|
||||||
|
builder.WriteString("---\n")
|
||||||
|
marsh("blog", blog)
|
||||||
|
marsh("section", bc.DefaultSection)
|
||||||
|
marsh("status", statusDraft)
|
||||||
|
marsh("priority", 0)
|
||||||
|
marsh("slug", "")
|
||||||
|
marsh("title", "")
|
||||||
|
for _, t := range bc.Taxonomies {
|
||||||
|
marsh(t.Name, []string{""})
|
||||||
|
}
|
||||||
|
builder.WriteString("---\n")
|
||||||
|
return builder.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *goBlog) editorMoreParams(blog string) string {
|
||||||
|
var builder strings.Builder
|
||||||
|
builder.WriteString(a.ts.GetTemplateStringVariant(blog, "emptyparams"))
|
||||||
|
builder.WriteByte(' ')
|
||||||
|
builder.WriteString(a.ts.GetTemplateStringVariant(blog, "moreparams"))
|
||||||
|
for i, param := range []string{
|
||||||
|
"summary",
|
||||||
|
"translationkey",
|
||||||
|
"original",
|
||||||
|
a.cfg.Micropub.AudioParam,
|
||||||
|
a.cfg.Micropub.BookmarkParam,
|
||||||
|
a.cfg.Micropub.LikeParam,
|
||||||
|
a.cfg.Micropub.LikeTitleParam,
|
||||||
|
a.cfg.Micropub.LocationParam,
|
||||||
|
a.cfg.Micropub.PhotoParam,
|
||||||
|
a.cfg.Micropub.PhotoDescriptionParam,
|
||||||
|
a.cfg.Micropub.ReplyParam,
|
||||||
|
a.cfg.Micropub.ReplyTitleParam,
|
||||||
|
} {
|
||||||
|
if param == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if i > 0 {
|
||||||
|
builder.WriteString(", ")
|
||||||
|
}
|
||||||
|
builder.WriteByte('`')
|
||||||
|
builder.WriteString(param)
|
||||||
|
builder.WriteByte('`')
|
||||||
|
}
|
||||||
|
builder.WriteByte('.')
|
||||||
|
return builder.String()
|
||||||
|
}
|
||||||
|
|
32
render.go
32
render.go
|
@ -61,21 +61,23 @@ func (a *goBlog) initRendering() error {
|
||||||
"liketitle": a.likeTitle,
|
"liketitle": a.likeTitle,
|
||||||
"photolinks": a.photoLinks,
|
"photolinks": a.photoLinks,
|
||||||
// Others
|
// Others
|
||||||
"dateformat": dateFormat,
|
"dateformat": dateFormat,
|
||||||
"isodate": isoDateFormat,
|
"isodate": isoDateFormat,
|
||||||
"unixtodate": unixToLocalDateString,
|
"unixtodate": unixToLocalDateString,
|
||||||
"now": localNowString,
|
"now": localNowString,
|
||||||
"asset": a.assetFileName,
|
"asset": a.assetFileName,
|
||||||
"string": a.ts.GetTemplateStringVariantFunc(),
|
"string": a.ts.GetTemplateStringVariantFunc(),
|
||||||
"include": a.includeRenderedTemplate,
|
"include": a.includeRenderedTemplate,
|
||||||
"urlize": urlize,
|
"urlize": urlize,
|
||||||
"sort": sortedStrings,
|
"sort": sortedStrings,
|
||||||
"absolute": a.getFullAddress,
|
"absolute": a.getFullAddress,
|
||||||
"mentions": a.db.getWebmentionsByAddress,
|
"mentions": a.db.getWebmentionsByAddress,
|
||||||
"geotitle": a.geoTitle,
|
"geotitle": a.geoTitle,
|
||||||
"geolink": geoOSMLink,
|
"geolink": geoOSMLink,
|
||||||
"opensearch": openSearchUrl,
|
"opensearch": openSearchUrl,
|
||||||
"mbytes": mBytesString,
|
"mbytes": mBytesString,
|
||||||
|
"editortemplate": a.editorPostTemplate,
|
||||||
|
"editormoreparams": a.editorMoreParams,
|
||||||
}
|
}
|
||||||
baseTemplate, err := template.New("base").Funcs(templateFunctions).ParseFiles(path.Join(templatesDir, templateBase+templatesExt))
|
baseTemplate, err := template.New("base").Funcs(templateFunctions).ParseFiles(path.Join(templatesDir, templateBase+templatesExt))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -6,18 +6,10 @@
|
||||||
<main>
|
<main>
|
||||||
<h1>{{ string .Blog.Lang "editor" }}</h1>
|
<h1>{{ string .Blog.Lang "editor" }}</h1>
|
||||||
<h2>{{ string .Blog.Lang "create" }}</h2>
|
<h2>{{ string .Blog.Lang "create" }}</h2>
|
||||||
|
{{ md (editormoreparams .BlogString) }}
|
||||||
<form class="fw p" method="post">
|
<form class="fw p" method="post">
|
||||||
<input type="hidden" name="h" value="entry">
|
<input type="hidden" name="h" value="entry">
|
||||||
<textarea name="content" class="monospace h400p formcache" id="create-input">---
|
<textarea name="content" class="monospace h400p formcache" id="create-input">{{ editortemplate .BlogString }}</textarea>
|
||||||
status: draft
|
|
||||||
blog: {{ .BlogString }}
|
|
||||||
section:
|
|
||||||
slug:
|
|
||||||
title:
|
|
||||||
tags:
|
|
||||||
-
|
|
||||||
---
|
|
||||||
</textarea>
|
|
||||||
<input type="submit" value="{{ string .Blog.Lang "create" }}">
|
<input type="submit" value="{{ string .Blog.Lang "create" }}">
|
||||||
</form>
|
</form>
|
||||||
<h2 id="update">{{ string .Blog.Lang "update" }}</h2>
|
<h2 id="update">{{ string .Blog.Lang "update" }}</h2>
|
||||||
|
|
|
@ -14,6 +14,7 @@ download: "Herunterladen"
|
||||||
drafts: "Entwürfe"
|
drafts: "Entwürfe"
|
||||||
editor: "Editor"
|
editor: "Editor"
|
||||||
emailopt: "E-Mail (optional)"
|
emailopt: "E-Mail (optional)"
|
||||||
|
emptyparams: "Leere Parameter werden automatisch entfernt."
|
||||||
fileuses: "Datei-Verwendungen"
|
fileuses: "Datei-Verwendungen"
|
||||||
interactions: "Interaktionen & Kommentare"
|
interactions: "Interaktionen & Kommentare"
|
||||||
interactionslabel: "Hast du eine Antwort hierzu veröffentlicht? Füge hier die URL ein."
|
interactionslabel: "Hast du eine Antwort hierzu veröffentlicht? Füge hier die URL ein."
|
||||||
|
@ -26,6 +27,7 @@ locationnotsupported: "Die Standort-API wird von diesem Browser nicht unterstüt
|
||||||
mediafiles: "Medien-Dateien"
|
mediafiles: "Medien-Dateien"
|
||||||
message: "Nachricht"
|
message: "Nachricht"
|
||||||
messagesent: "Nachricht gesendet"
|
messagesent: "Nachricht gesendet"
|
||||||
|
moreparams: "Mehr Parameter: "
|
||||||
next: "Weiter"
|
next: "Weiter"
|
||||||
nofiles: "Keine Dateien"
|
nofiles: "Keine Dateien"
|
||||||
nolocations: "Keine Posts mit Standorten"
|
nolocations: "Keine Posts mit Standorten"
|
||||||
|
|
|
@ -19,6 +19,7 @@ download: "Download"
|
||||||
drafts: "Drafts"
|
drafts: "Drafts"
|
||||||
editor: "Editor"
|
editor: "Editor"
|
||||||
emailopt: "Email (optional)"
|
emailopt: "Email (optional)"
|
||||||
|
emptyparams: "Empty parameters will be removed automatically."
|
||||||
feed: "Feed"
|
feed: "Feed"
|
||||||
fileuses: "file uses"
|
fileuses: "file uses"
|
||||||
indieauth: "IndieAuth"
|
indieauth: "IndieAuth"
|
||||||
|
@ -35,6 +36,7 @@ logout: "Logout"
|
||||||
mediafiles: "Media files"
|
mediafiles: "Media files"
|
||||||
message: "Message"
|
message: "Message"
|
||||||
messagesent: "Message sent"
|
messagesent: "Message sent"
|
||||||
|
moreparams: "More parameters: "
|
||||||
nameopt: "Name (optional)"
|
nameopt: "Name (optional)"
|
||||||
next: "Next"
|
next: "Next"
|
||||||
nofiles: "No files"
|
nofiles: "No files"
|
||||||
|
|
Loading…
Reference in New Issue