From 55fa3421f9ead2bdc7a5cf8042c935ffc98b0378 Mon Sep 17 00:00:00 2001 From: Jan-Lukas Else Date: Sun, 1 Aug 2021 19:27:21 +0200 Subject: [PATCH] Show possible states for post status --- editor.go | 30 +++++++++++++++++++----------- render.go | 34 +++++++++++++++++----------------- templates/editor.gohtml | 2 +- templates/strings/de.yaml | 3 +-- templates/strings/default.yaml | 3 +-- 5 files changed, 39 insertions(+), 33 deletions(-) diff --git a/editor.go b/editor.go index de20351..24c3302 100644 --- a/editor.go +++ b/editor.go @@ -3,6 +3,7 @@ package main import ( "bytes" "encoding/json" + "fmt" "io" "net/http" "net/http/httptest" @@ -126,12 +127,10 @@ func (a *goBlog) editorPostTemplate(blog string) string { return builder.String() } -func (a *goBlog) editorMoreParams(blog string) string { - var builder strings.Builder +func (a *goBlog) editorPostDesc(blog string) string { bc := a.cfg.Blogs[blog] - builder.WriteString(a.ts.GetTemplateStringVariant(bc.Lang, "emptyparams")) - builder.WriteByte(' ') - builder.WriteString(a.ts.GetTemplateStringVariant(bc.Lang, "moreparams")) + t := a.ts.GetTemplateStringVariant(bc.Lang, "editorpostdesc") + var paramBuilder, statusBuilder strings.Builder for i, param := range []string{ "summary", "translationkey", @@ -150,12 +149,21 @@ func (a *goBlog) editorMoreParams(blog string) string { continue } if i > 0 { - builder.WriteString(", ") + paramBuilder.WriteString(", ") } - builder.WriteByte('`') - builder.WriteString(param) - builder.WriteByte('`') + paramBuilder.WriteByte('`') + paramBuilder.WriteString(param) + paramBuilder.WriteByte('`') } - builder.WriteByte('.') - return builder.String() + for i, status := range []postStatus{ + statusDraft, statusPublished, statusUnlisted, statusPrivate, + } { + if i > 0 { + statusBuilder.WriteString(", ") + } + statusBuilder.WriteByte('`') + statusBuilder.WriteString(string(status)) + statusBuilder.WriteByte('`') + } + return fmt.Sprintf(t, paramBuilder.String(), "status", statusBuilder.String()) } diff --git a/render.go b/render.go index 0d7abaf..1015f16 100644 --- a/render.go +++ b/render.go @@ -61,23 +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, - "editortemplate": a.editorPostTemplate, - "editormoreparams": a.editorMoreParams, + "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, + "editorpostdesc": a.editorPostDesc, } 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 aa0260c..12f2d48 100644 --- a/templates/editor.gohtml +++ b/templates/editor.gohtml @@ -6,7 +6,7 @@

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

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

- {{ md (editormoreparams .BlogString) }} + {{ md (editorpostdesc .BlogString) }}
diff --git a/templates/strings/de.yaml b/templates/strings/de.yaml index 19c485a..38ada37 100644 --- a/templates/strings/de.yaml +++ b/templates/strings/de.yaml @@ -13,8 +13,8 @@ docomment: "Kommentieren" download: "Herunterladen" drafts: "Entwürfe" editor: "Editor" +editorpostdesc: "Leere Parameter werden automatisch entfernt. Mehr mögliche Parameter: %s. Mögliche Zustände für `%s`: %s." 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." @@ -27,7 +27,6 @@ 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 0417cbf..416fb6a 100644 --- a/templates/strings/default.yaml +++ b/templates/strings/default.yaml @@ -18,8 +18,8 @@ docomment: "Comment" download: "Download" drafts: "Drafts" editor: "Editor" +editorpostdesc: "Empty parameters are removed automatically. More possible parameters: %s. Possible states for `%s`: %s." emailopt: "Email (optional)" -emptyparams: "Empty parameters will be removed automatically." feed: "Feed" fileuses: "file uses" indieauth: "IndieAuth" @@ -36,7 +36,6 @@ logout: "Logout" mediafiles: "Media files" message: "Message" messagesent: "Message sent" -moreparams: "More parameters: " nameopt: "Name (optional)" next: "Next" nofiles: "No files"