Improve editor template

This commit is contained in:
Jan-Lukas Else 2021-07-31 14:19:37 +02:00
parent 5dafac827c
commit 9e164d4f17
5 changed files with 80 additions and 25 deletions

View File

@ -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()
}

View File

@ -61,21 +61,23 @@ func (a *goBlog) initRendering() error {
"liketitle": a.likeTitle,
"photolinks": a.photoLinks,
// Others
"dateformat": dateFormat,
"isodate": isoDateFormat,
"unixtodate": unixToLocalDateString,
"now": localNowString,
"asset": a.assetFileName,
"string": a.ts.GetTemplateStringVariantFunc(),
"include": a.includeRenderedTemplate,
"urlize": urlize,
"sort": sortedStrings,
"absolute": a.getFullAddress,
"mentions": a.db.getWebmentionsByAddress,
"geotitle": a.geoTitle,
"geolink": geoOSMLink,
"opensearch": openSearchUrl,
"mbytes": mBytesString,
"dateformat": dateFormat,
"isodate": isoDateFormat,
"unixtodate": unixToLocalDateString,
"now": localNowString,
"asset": a.assetFileName,
"string": a.ts.GetTemplateStringVariantFunc(),
"include": a.includeRenderedTemplate,
"urlize": urlize,
"sort": sortedStrings,
"absolute": a.getFullAddress,
"mentions": a.db.getWebmentionsByAddress,
"geotitle": a.geoTitle,
"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 {

View File

@ -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>

View File

@ -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"

View File

@ -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"