From 9e164d4f173bdbb41cc2787f53c50e894034a46f Mon Sep 17 00:00:00 2001 From: Jan-Lukas Else Date: Sat, 31 Jul 2021 14:19:37 +0200 Subject: [PATCH] Improve editor template --- editor.go | 57 ++++++++++++++++++++++++++++++++++ render.go | 32 ++++++++++--------- templates/editor.gohtml | 12 ++----- templates/strings/de.yaml | 2 ++ templates/strings/default.yaml | 2 ++ 5 files changed, 80 insertions(+), 25 deletions(-) diff --git a/editor.go b/editor.go index 880aaf3..9fa3777 100644 --- a/editor.go +++ b/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() +} diff --git a/render.go b/render.go index e2ec902..0d7abaf 100644 --- a/render.go +++ b/render.go @@ -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 { diff --git a/templates/editor.gohtml b/templates/editor.gohtml index d81d0fc..aa0260c 100644 --- a/templates/editor.gohtml +++ b/templates/editor.gohtml @@ -6,18 +6,10 @@

{{ string .Blog.Lang "editor" }}

{{ string .Blog.Lang "create" }}

+ {{ md (editormoreparams .BlogString) }}
- +

{{ string .Blog.Lang "update" }}

diff --git a/templates/strings/de.yaml b/templates/strings/de.yaml index ed9ac17..19c485a 100644 --- a/templates/strings/de.yaml +++ b/templates/strings/de.yaml @@ -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" diff --git a/templates/strings/default.yaml b/templates/strings/default.yaml index fa7170c..0417cbf 100644 --- a/templates/strings/default.yaml +++ b/templates/strings/default.yaml @@ -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"