From 5317ef12c64ca98d96e3645533f99fd80c014bed Mon Sep 17 00:00:00 2001 From: Jan-Lukas Else Date: Wed, 4 Aug 2021 22:48:50 +0200 Subject: [PATCH] Render titles using Goldmark, fix bug --- activityStreams.go | 2 +- feeds.go | 2 +- micropub.go | 3 +++ render.go | 5 +++-- telegram.go | 2 +- templates/base.gohtml | 10 +++++----- templates/blogroll.gohtml | 4 ++-- templates/blogstats.gohtml | 4 ++-- templates/captcha.gohtml | 2 +- templates/commentsadmin.gohtml | 2 +- templates/contact.gohtml | 2 +- templates/editor.gohtml | 2 +- templates/editorfiles.gohtml | 2 +- templates/footer.gohtml | 4 ++-- templates/geomap.gohtml | 2 +- templates/header.gohtml | 4 ++-- templates/index.gohtml | 10 +++++----- templates/login.gohtml | 2 +- templates/notificationsadmin.gohtml | 2 +- templates/photosummary.gohtml | 2 +- templates/post.gohtml | 4 ++-- templates/postactions.gohtml | 2 +- templates/postheadmeta.gohtml | 4 ++-- templates/postmeta.gohtml | 2 +- templates/posttax.gohtml | 4 ++-- templates/search.gohtml | 6 +++--- templates/statichome.gohtml | 2 +- templates/summary.gohtml | 2 +- templates/summaryandpostmeta.gohtml | 2 +- templates/taxonomy.gohtml | 4 ++-- templates/webmentionadmin.gohtml | 2 +- 31 files changed, 53 insertions(+), 49 deletions(-) diff --git a/activityStreams.go b/activityStreams.go index 7df4fa4..3b37d45 100644 --- a/activityStreams.go +++ b/activityStreams.go @@ -106,7 +106,7 @@ func (a *goBlog) toASNote(p *post) *asNote { AttributedTo: a.apIri(a.cfg.Blogs[p.Blog]), } // Name and Type - if title := p.Title(); title != "" { + if title := a.renderText(p.Title()); title != "" { as.Name = title as.Type = "Article" } else { diff --git a/feeds.go b/feeds.go index 825b44a..67ec340 100644 --- a/feeds.go +++ b/feeds.go @@ -42,7 +42,7 @@ func (a *goBlog) generateFeed(blog string, f feedType, w http.ResponseWriter, r } for _, p := range posts { feed.Add(&feeds.Item{ - Title: p.Title(), + Title: a.renderText(p.Title()), Link: &feeds.Link{Href: a.fullPostURL(p)}, Description: a.postSummary(p), Id: p.Path, diff --git a/micropub.go b/micropub.go index f6a7719..c3c17f0 100644 --- a/micropub.go +++ b/micropub.go @@ -324,6 +324,9 @@ func (a *goBlog) micropubParsePostParamsMfItem(entry *post, mf *microformatItem) } func (a *goBlog) computeExtraPostParameters(p *post) error { + if p.Parameters == nil { + p.Parameters = map[string][]string{} + } p.Content = regexp.MustCompile("\r\n").ReplaceAllString(p.Content, "\n") if split := strings.Split(p.Content, "---\n"); len(split) >= 3 && len(strings.TrimSpace(split[0])) == 0 { // Contains frontmatter diff --git a/render.go b/render.go index 1f56d17..95704e5 100644 --- a/render.go +++ b/render.go @@ -44,8 +44,9 @@ const ( func (a *goBlog) initRendering() error { a.templates = map[string]*template.Template{} templateFunctions := template.FuncMap{ - "md": a.safeRenderMarkdownAsHTML, - "html": wrapStringAsHTML, + "md": a.safeRenderMarkdownAsHTML, + "mdtext": a.renderText, + "html": wrapStringAsHTML, // Post specific "ps": postParameter, "content": a.postHtml, diff --git a/telegram.go b/telegram.go index 53171d9..63160ed 100644 --- a/telegram.go +++ b/telegram.go @@ -16,7 +16,7 @@ const telegramBaseURL = "https://api.telegram.org/bot" func (a *goBlog) initTelegram() { a.pPostHooks = append(a.pPostHooks, func(p *post) { if tg := a.cfg.Blogs[p.Blog].Telegram; tg.enabled() && p.isPublishedSectionPost() { - if html := tg.generateHTML(p.Title(), a.fullPostURL(p), a.shortPostURL(p)); html != "" { + if html := tg.generateHTML(a.renderText(p.Title()), a.fullPostURL(p), a.shortPostURL(p)); html != "" { if err := a.send(tg, html, "HTML"); err != nil { log.Printf("Failed to send post to Telegram: %v", err) } diff --git a/templates/base.gohtml b/templates/base.gohtml index dbde728..7b83896 100644 --- a/templates/base.gohtml +++ b/templates/base.gohtml @@ -6,11 +6,11 @@ {{ with .Canonical }}{{ end }} {{ block "title" . }} - {{ .Blog.Title }} + {{ mdtext .Blog.Title }} {{ end }} - - - + + + @@ -18,7 +18,7 @@ {{ with .User }}{{ range .Identities }}{{ end }}{{ end }} {{ $os := opensearch .Blog }} {{ if $os }} - + {{ end }} {{ include "header" . }} {{ block "main" . }}{{ end }} diff --git a/templates/blogroll.gohtml b/templates/blogroll.gohtml index 6b41058..6598935 100644 --- a/templates/blogroll.gohtml +++ b/templates/blogroll.gohtml @@ -1,10 +1,10 @@ {{ define "title" }} - {{ .Data.Title }} - {{ .Blog.Title }} + {{ mdtext .Data.Title }} - {{ mdtext .Blog.Title }} {{ end }} {{ define "main" }}
- {{ with .Data.Title }}

{{ . }}

{{ end }} + {{ with .Data.Title }}

{{ mdtext . }}

{{ end }} {{ with .Data.Description }}{{ md . }}{{ end }}

{{ string .Blog.Lang "download" }}

{{ $lang := .Blog.Lang }} diff --git a/templates/blogstats.gohtml b/templates/blogstats.gohtml index d4ca75b..ededd84 100644 --- a/templates/blogstats.gohtml +++ b/templates/blogstats.gohtml @@ -1,10 +1,10 @@ {{ define "title" }} - {{ with .Blog.BlogStats.Title }}{{ . }} - {{ end }}{{ .Blog.Title }} + {{ with .Blog.BlogStats.Title }}{{ mdtext . }} - {{ end }}{{ mdtext .Blog.Title }} {{ end }} {{ define "main" }}
- {{ with .Blog.BlogStats.Title }}

{{ . }}

{{ end }} + {{ with .Blog.BlogStats.Title }}

{{ mdtext . }}

{{ end }} {{ with .Blog.BlogStats.Description }}{{ md . }}{{ end }}

{{ string .Blog.Lang "loading" }}

diff --git a/templates/captcha.gohtml b/templates/captcha.gohtml index b743786..4307f15 100644 --- a/templates/captcha.gohtml +++ b/templates/captcha.gohtml @@ -1,5 +1,5 @@ {{ define "title" }} - {{ string .Blog.Lang "captcha" }} - {{ .Blog.Title }} + {{ string .Blog.Lang "captcha" }} - {{ mdtext .Blog.Title }} {{ end }} {{ define "main" }} diff --git a/templates/commentsadmin.gohtml b/templates/commentsadmin.gohtml index 64adabf..7b0496b 100644 --- a/templates/commentsadmin.gohtml +++ b/templates/commentsadmin.gohtml @@ -1,5 +1,5 @@ {{ define "title" }} - {{ string .Blog.Lang "comments" }} - {{ .Blog.Title }} + {{ string .Blog.Lang "comments" }} - {{ mdtext .Blog.Title }} {{ end }} {{ define "main" }} diff --git a/templates/contact.gohtml b/templates/contact.gohtml index 71a2f48..d6edd0f 100644 --- a/templates/contact.gohtml +++ b/templates/contact.gohtml @@ -7,7 +7,7 @@ {{ if .Data.sent }}

{{ string .Blog.Lang "messagesent" }}

{{ else }} - {{ with .Data.title }}

{{ . }}

{{ end }} + {{ with .Data.title }}

{{ mdtext . }}

{{ end }} {{ with .Data.description }}{{ md . }}{{ end }}
diff --git a/templates/editor.gohtml b/templates/editor.gohtml index 12f2d48..154bc63 100644 --- a/templates/editor.gohtml +++ b/templates/editor.gohtml @@ -1,5 +1,5 @@ {{ define "title" }} - {{ string .Blog.Lang "editor" }} - {{ .Blog.Title }} + {{ string .Blog.Lang "editor" }} - {{ mdtext .Blog.Title }} {{ end }} {{ define "main" }} diff --git a/templates/editorfiles.gohtml b/templates/editorfiles.gohtml index 050e314..b88051a 100644 --- a/templates/editorfiles.gohtml +++ b/templates/editorfiles.gohtml @@ -1,5 +1,5 @@ {{ define "title" }} - {{ string .Blog.Lang "mediafiles" }} - {{ .Blog.Title }} + {{ string .Blog.Lang "mediafiles" }} - {{ mdtext .Blog.Title }} {{ end }} {{ define "main" }} diff --git a/templates/footer.gohtml b/templates/footer.gohtml index 25afcac..849eb59 100644 --- a/templates/footer.gohtml +++ b/templates/footer.gohtml @@ -1,10 +1,10 @@ {{ define "footer" }}