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/httptest"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"go.goblog.app/app/pkgs/contenttype"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
const editorPath = "/editor"
|
||||
|
@ -101,3 +103,58 @@ func (a *goBlog) editorMicropubPost(w http.ResponseWriter, r *http.Request, medi
|
|||
_, _ = io.Copy(w, result.Body)
|
||||
_ = 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()
|
||||
}
|
||||
|
|
|
@ -76,6 +76,8 @@ func (a *goBlog) initRendering() error {
|
|||
"geolink": geoOSMLink,
|
||||
"opensearch": openSearchUrl,
|
||||
"mbytes": mBytesString,
|
||||
"editortemplate": a.editorPostTemplate,
|
||||
"editormoreparams": a.editorMoreParams,
|
||||
}
|
||||
baseTemplate, err := template.New("base").Funcs(templateFunctions).ParseFiles(path.Join(templatesDir, templateBase+templatesExt))
|
||||
if err != nil {
|
||||
|
|
|
@ -6,18 +6,10 @@
|
|||
<main>
|
||||
<h1>{{ string .Blog.Lang "editor" }}</h1>
|
||||
<h2>{{ string .Blog.Lang "create" }}</h2>
|
||||
{{ md (editormoreparams .BlogString) }}
|
||||
<form class="fw p" method="post">
|
||||
<input type="hidden" name="h" value="entry">
|
||||
<textarea name="content" class="monospace h400p formcache" id="create-input">---
|
||||
status: draft
|
||||
blog: {{ .BlogString }}
|
||||
section:
|
||||
slug:
|
||||
title:
|
||||
tags:
|
||||
-
|
||||
---
|
||||
</textarea>
|
||||
<textarea name="content" class="monospace h400p formcache" id="create-input">{{ editortemplate .BlogString }}</textarea>
|
||||
<input type="submit" value="{{ string .Blog.Lang "create" }}">
|
||||
</form>
|
||||
<h2 id="update">{{ string .Blog.Lang "update" }}</h2>
|
||||
|
|
|
@ -14,6 +14,7 @@ download: "Herunterladen"
|
|||
drafts: "Entwürfe"
|
||||
editor: "Editor"
|
||||
emailopt: "E-Mail (optional)"
|
||||
emptyparams: "Leere Parameter werden automatisch entfernt."
|
||||
fileuses: "Datei-Verwendungen"
|
||||
interactions: "Interaktionen & Kommentare"
|
||||
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"
|
||||
message: "Nachricht"
|
||||
messagesent: "Nachricht gesendet"
|
||||
moreparams: "Mehr Parameter: "
|
||||
next: "Weiter"
|
||||
nofiles: "Keine Dateien"
|
||||
nolocations: "Keine Posts mit Standorten"
|
||||
|
|
|
@ -19,6 +19,7 @@ download: "Download"
|
|||
drafts: "Drafts"
|
||||
editor: "Editor"
|
||||
emailopt: "Email (optional)"
|
||||
emptyparams: "Empty parameters will be removed automatically."
|
||||
feed: "Feed"
|
||||
fileuses: "file uses"
|
||||
indieauth: "IndieAuth"
|
||||
|
@ -35,6 +36,7 @@ logout: "Logout"
|
|||
mediafiles: "Media files"
|
||||
message: "Message"
|
||||
messagesent: "Message sent"
|
||||
moreparams: "More parameters: "
|
||||
nameopt: "Name (optional)"
|
||||
next: "Next"
|
||||
nofiles: "No files"
|
||||
|
|
Loading…
Reference in New Issue