Render titles using Goldmark, fix bug

This commit is contained in:
Jan-Lukas Else 2021-08-04 22:48:50 +02:00
parent ba4c32b40b
commit 5317ef12c6
31 changed files with 53 additions and 49 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -6,11 +6,11 @@
<link rel="stylesheet" href="{{ asset "css/styles.css" }}">
{{ with .Canonical }}<link rel="canonical" href="{{ . }}">{{ end }}
{{ block "title" . }}
<title>{{ .Blog.Title }}</title>
<title>{{ mdtext .Blog.Title }}</title>
{{ end }}
<link rel="alternate" type="application/rss+xml" title="RSS ({{ .Blog.Title }})" href="{{ .Blog.Path }}.rss"/>
<link rel="alternate" type="application/atom+xml" title="Atom ({{ .Blog.Title }})" href="{{ .Blog.Path }}.atom"/>
<link rel="alternate" type="application/feed+json" title="JSON Feed ({{ .Blog.Title }})" href="{{ .Blog.Path }}.json"/>
<link rel="alternate" type="application/rss+xml" title="RSS ({{ mdtext .Blog.Title }})" href="{{ .Blog.Path }}.rss"/>
<link rel="alternate" type="application/atom+xml" title="Atom ({{ mdtext .Blog.Title }})" href="{{ .Blog.Path }}.atom"/>
<link rel="alternate" type="application/feed+json" title="JSON Feed ({{ mdtext .Blog.Title }})" href="{{ .Blog.Path }}.json"/>
<link rel="webmention" href="{{ absolute "/webmention" }}" />
<link rel="micropub" href="/micropub" />
<link rel="authorization_endpoint" href="/indieauth" />
@ -18,7 +18,7 @@
{{ with .User }}{{ range .Identities }}<link rel="me" href="{{ . }}" />{{ end }}{{ end }}
{{ $os := opensearch .Blog }}
{{ if $os }}
<link rel="search" type="application/opensearchdescription+xml" href="{{ $os }}" title="{{ .Blog.Title }}" />
<link rel="search" type="application/opensearchdescription+xml" href="{{ $os }}" title="{{ mdtext .Blog.Title }}" />
{{ end }}
{{ include "header" . }}
{{ block "main" . }}{{ end }}

View File

@ -1,10 +1,10 @@
{{ define "title" }}
<title>{{ .Data.Title }} - {{ .Blog.Title }}</title>
<title>{{ mdtext .Data.Title }} - {{ mdtext .Blog.Title }}</title>
{{ end }}
{{ define "main" }}
<main>
{{ with .Data.Title }}<h1>{{ . }}</h1>{{ end }}
{{ with .Data.Title }}<h1>{{ mdtext . }}</h1>{{ end }}
{{ with .Data.Description }}{{ md . }}{{ end }}
<p><a href="{{ .Blog.RelativePath .Data.Download }}" class="button" download>{{ string .Blog.Lang "download" }}</a></p>
{{ $lang := .Blog.Lang }}

View File

@ -1,10 +1,10 @@
{{ define "title" }}
<title>{{ with .Blog.BlogStats.Title }}{{ . }} - {{ end }}{{ .Blog.Title }}</title>
<title>{{ with .Blog.BlogStats.Title }}{{ mdtext . }} - {{ end }}{{ mdtext .Blog.Title }}</title>
{{ end }}
{{ define "main" }}
<main>
{{ with .Blog.BlogStats.Title }}<h1>{{ . }}</h1>{{ end }}
{{ with .Blog.BlogStats.Title }}<h1>{{ mdtext . }}</h1>{{ end }}
{{ with .Blog.BlogStats.Description }}{{ md . }}{{ end }}
<p id="loading" data-table="{{.Data.TableUrl}}">{{ string .Blog.Lang "loading" }}</p>
<script defer src="{{ asset "js/blogstats.js" }}"></script>

View File

@ -1,5 +1,5 @@
{{ define "title" }}
<title>{{ string .Blog.Lang "captcha" }} - {{ .Blog.Title }}</title>
<title>{{ string .Blog.Lang "captcha" }} - {{ mdtext .Blog.Title }}</title>
{{ end }}
{{ define "main" }}

View File

@ -1,5 +1,5 @@
{{ define "title" }}
<title>{{ string .Blog.Lang "comments" }} - {{ .Blog.Title }}</title>
<title>{{ string .Blog.Lang "comments" }} - {{ mdtext .Blog.Title }}</title>
{{ end }}
{{ define "main" }}

View File

@ -7,7 +7,7 @@
{{ if .Data.sent }}
<p>{{ string .Blog.Lang "messagesent" }}</p>
{{ else }}
{{ with .Data.title }}<h1>{{ . }}</h1>{{ end }}
{{ with .Data.title }}<h1>{{ mdtext . }}</h1>{{ end }}
{{ with .Data.description }}{{ md . }}{{ end }}
<form class="fw p" method="post">
<input type="text" name="name" placeholder="{{ string .Blog.Lang "nameopt" }}">

View File

@ -1,5 +1,5 @@
{{ define "title" }}
<title>{{ string .Blog.Lang "editor" }} - {{ .Blog.Title }}</title>
<title>{{ string .Blog.Lang "editor" }} - {{ mdtext .Blog.Title }}</title>
{{ end }}
{{ define "main" }}

View File

@ -1,5 +1,5 @@
{{ define "title" }}
<title>{{ string .Blog.Lang "mediafiles" }} - {{ .Blog.Title }}</title>
<title>{{ string .Blog.Lang "mediafiles" }} - {{ mdtext .Blog.Title }}</title>
{{ end }}
{{ define "main" }}

View File

@ -1,10 +1,10 @@
{{ define "footer" }}
<footer>
{{ with index .Blog.Menus "footer" }}
<nav>{{ range $i, $item := .Items }}{{ if ne $i 0 }} &bull; {{ end }}<a href="{{ $item.Link }}">{{ $item.Title }}</a>{{ end }}
<nav>{{ range $i, $item := .Items }}{{ if ne $i 0 }} &bull; {{ end }}<a href="{{ $item.Link }}">{{ mdtext $item.Title }}</a>{{ end }}
</nav>
{{ end }}
<p translate="no">&copy; {{ dateformat now "2006" }} {{ with .User.Name }}{{ . }}{{ else }}{{ .Blog.Title }}{{ end }}</p>
<p translate="no">&copy; {{ dateformat now "2006" }} {{ with .User.Name }}{{ . }}{{ else }}{{ mdtext .Blog.Title }}{{ end }}</p>
{{ if .TorUsed }}
<p id="tor">🔐 {{ string .Blog.Lang "connectedviator" }}</p>
{{ else }}

View File

@ -1,5 +1,5 @@
{{ define "title" }}
<title>{{ .Blog.Title }}</title>
<title>{{ mdtext .Blog.Title }}</title>
{{ if not .Data.nolocations }}
<link rel="stylesheet" href="{{ .Data.mappath }}/leaflet/leaflet.css"/>
<script src="{{ .Data.mappath }}/leaflet/leaflet.js"></script>

View File

@ -1,10 +1,10 @@
{{ define "header" }}
<header>
<h1><a href="{{ .Blog.RelativePath "/" }}" rel="home" title="{{ .Blog.Title }}" translate="no">{{ .Blog.Title }}</a></h1>
<h1><a href="{{ .Blog.RelativePath "/" }}" rel="home" title="{{ mdtext .Blog.Title }}" translate="no">{{ mdtext .Blog.Title }}</a></h1>
{{ with .Blog.Description }}<p><i>{{ . }}</i></p>{{ end }}
<nav>
{{ with index .Blog.Menus "main" }}
{{ range $i, $item := .Items }}{{ if ne $i 0 }} &bull; {{ end }}<a href="{{ $item.Link }}">{{ $item.Title }}</a>{{ end }}
{{ range $i, $item := .Items }}{{ if ne $i 0 }} &bull; {{ end }}<a href="{{ $item.Link }}">{{ mdtext $item.Title }}</a>{{ end }}
{{ end }}
</nav>
{{ if .LoggedIn }}

View File

@ -1,13 +1,13 @@
{{ define "title" }}
<title>{{ with .Data.Title }}{{ . }} - {{ end }}{{ .Blog.Title }}</title>
<link rel="alternate" type="application/rss+xml" title="RSS{{ with .Data.Title }} ({{ . }}){{ end }}" href="{{ .Data.First }}.rss"/>
<link rel="alternate" type="application/atom+xml" title="Atom{{ with .Data.Title }} ({{ . }}){{ end }}" href="{{ .Data.First }}.atom"/>
<link rel="alternate" type="application/feed+json" title="JSON Feed{{ with .Data.Title }} ({{ . }}){{ end }}" href="{{ .Data.First }}.json"/>
<title>{{ with .Data.Title }}{{ mdtext . }} - {{ end }}{{ mdtext .Blog.Title }}</title>
<link rel="alternate" type="application/rss+xml" title="RSS{{ with .Data.Title }} ({{ mdtext . }}){{ end }}" href="{{ .Data.First }}.rss"/>
<link rel="alternate" type="application/atom+xml" title="Atom{{ with .Data.Title }} ({{ mdtext . }}){{ end }}" href="{{ .Data.First }}.atom"/>
<link rel="alternate" type="application/feed+json" title="JSON Feed{{ with .Data.Title }} ({{ mdtext . }}){{ end }}" href="{{ .Data.First }}.json"/>
{{ end }}
{{ define "main" }}
<main class="h-feed">
{{ with .Data.Title }}<h1 class="p-name">{{ . }}</h1>{{ end }}
{{ with .Data.Title }}<h1 class="p-name">{{ mdtext . }}</h1>{{ end }}
{{ with .Data.Description }}{{ md . }}{{ end }}
{{ if (or .Data.Title .Data.Description) }}
<hr>

View File

@ -1,5 +1,5 @@
{{ define "title" }}
<title>{{ string .Blog.Lang "login" }} - {{ .Blog.Title }}</title>
<title>{{ string .Blog.Lang "login" }} - {{ mdtext .Blog.Title }}</title>
{{ end }}
{{ define "main" }}

View File

@ -1,5 +1,5 @@
{{ define "title" }}
<title>{{ string "notifications" }} - {{ .Blog.Title }}</title>
<title>{{ string "notifications" }} - {{ mdtext .Blog.Title }}</title>
{{ end }}
{{ define "main" }}

View File

@ -4,7 +4,7 @@
{{ if .Data.Title }}
<h2 class="p-name">
<a class="u-url" href="{{ .Data.Path }}">
{{ .Data.Title }}
{{ mdtext .Data.Title }}
</a>
</h2>
{{ end }}

View File

@ -1,5 +1,5 @@
{{ define "title" }}
<title>{{ with .Data.Title }}{{ . }} - {{end}}{{ .Blog.Title }}</title>
<title>{{ with .Data.Title }}{{ mdtext . }} - {{end}}{{ mdtext .Blog.Title }}</title>
{{ include "postheadmeta" . }}
{{ with shorturl .Data }}<link rel="shortlink" href="{{ . }}">{{ end }}
{{ end }}
@ -8,7 +8,7 @@
<main class=h-entry>
<article>
<data class="u-url hide" value="{{ absolute .Data.Path }}"></data>
{{ with .Data.Title }}<h1 class=p-name>{{ . }}</h1>{{ end }}
{{ with .Data.Title }}<h1 class=p-name>{{ mdtext . }}</h1>{{ end }}
{{ include "postmeta" . }}
{{ include "postactions" . }}
{{ if .Data.Content }}

View File

@ -1,6 +1,6 @@
{{ define "postactions" }}
<div class="p flex" id="post-actions">
<a href="https://www.addtoany.com/share#url={{ absolute .Data.Path }}{{ with .Data.Title }}&title={{ . }}{{ end }}" target="_blank" rel="nofollow noopener noreferrer" class="button">{{ string .Blog.Lang "share" }}</a>&nbsp;
<a href="https://www.addtoany.com/share#url={{ absolute .Data.Path }}{{ with .Data.Title }}&title={{ mdtext . }}{{ end }}" target="_blank" rel="nofollow noopener noreferrer" class="button">{{ string .Blog.Lang "share" }}</a>&nbsp;
<a id="translateBtn" href="https://translate.google.com/translate?u={{ absolute .Data.Path }}" target="_blank" rel="nofollow noopener noreferrer" class="button">{{ string .Blog.Lang "translate" }}</a>&nbsp;
<script defer src="{{ asset "js/translate.js" }}"></script>
<button id="speakBtn" class="hide" data-speak="{{ string .Blog.Lang "speak" }}" data-stopspeak="{{ string .Blog.Lang "stopspeak" }}"></button>

View File

@ -4,8 +4,8 @@
<meta property="twitter:url" content="{{ . }}">
{{ end }}
{{ with .Data.Title }}
<meta property="og:title" content="{{ . }}">
<meta property="twitter:title" content="{{ . }}">
<meta property="og:title" content="{{ mdtext . }}">
<meta property="twitter:title" content="{{ mdtext . }}">
{{ end }}
{{ with summary .Data }}
<meta name="description" content="{{ . }}">

View File

@ -3,7 +3,7 @@
{{ include "summaryandpostmeta" . }}
{{ $translations := (translations .Data) }}
{{ if gt (len $translations) 0 }}
<div>{{ string .Blog.Lang "translations" }}: {{ $delimiter := "" }}{{ range $i, $t := $translations }}{{ $delimiter }}<a href="{{ $t.Path }}" translate="no">{{ $t.Title }}</a>{{ $delimiter = ", " }}{{ end }}</div>
<div>{{ string .Blog.Lang "translations" }}: {{ $delimiter := "" }}{{ range $i, $t := $translations }}{{ $delimiter }}<a href="{{ $t.Path }}" translate="no">{{ mdtext $t.Title }}</a>{{ $delimiter = ", " }}{{ end }}</div>
{{ end }}
{{ $short := shorturl .Data }}
{{ if $short }}<div>{{ string .Blog.Lang "shorturl" }} <a href="{{ $short }}" rel="shortlink">{{ $short }}</a></div>{{ end }}

View File

@ -4,9 +4,9 @@
{{ range $i, $tax := $blog.Taxonomies }}
{{ $tvs := sort (ps $post $tax.Name) }}
{{ if $tvs }}
<p><b>{{ $tax.Title }}</b>:
<p><b>{{ mdtext $tax.Title }}</b>:
{{ range $j, $tv := $tvs }}
<a class="p-category" rel="tag" href="{{ $blog.RelativePath ( printf "/%s/%s" $tax.Name (urlize $tv) ) }}">{{ $tv }}</a>
<a class="p-category" rel="tag" href="{{ $blog.RelativePath ( printf "/%s/%s" $tax.Name (urlize $tv) ) }}">{{ mdtext $tv }}</a>
{{ end }}
</p>
{{ end }}

View File

@ -1,16 +1,16 @@
{{ define "title" }}
<title>{{ with .Blog.Search.Title }}{{ . }} - {{ end }}{{ .Blog.Title }}</title>
<title>{{ with .Blog.Search.Title }}{{ mdtext . }} - {{ end }}{{ mdtext .Blog.Title }}</title>
{{ end }}
{{ define "main" }}
<main>
{{ with .Blog.Search.Title }}<h1>{{ . }}</h1>{{ end }}
{{ with .Blog.Search.Title }}<h1>{{ mdtext . }}</h1>{{ end }}
{{ with .Blog.Search.Description }}{{ md . }}{{ end }}
{{ if (or .Blog.Search.Title .Blog.Search.Description) }}
<hr>
{{ end }}
<form class="fw p" method="post">
<input type="text" name="q" {{ with .Blog.Search.Placeholder }}placeholder="{{ . }}"{{ end }}>
<input type="text" name="q" {{ with .Blog.Search.Placeholder }}placeholder="{{ mdtext . }}"{{ end }}>
<input type="submit" value="🔍 {{ string .Blog.Lang "search" }}">
</form>
</main>

View File

@ -1,5 +1,5 @@
{{ define "title" }}
<title>{{ .Blog.Title }}</title>
<title>{{ mdtext .Blog.Title }}</title>
{{ include "postheadmeta" . }}
{{ end }}

View File

@ -4,7 +4,7 @@
{{ if .Data.Title }}
<h2 class="p-name">
<a class="u-url" href="{{ .Data.Path }}">
{{ .Data.Title }}
{{ mdtext .Data.Title }}
</a>
</h2>
{{ end }}

View File

@ -1,6 +1,6 @@
{{ define "summaryandpostmeta" }}
{{ $section := (index .Blog.Sections .Data.Section) }}
{{ if .Data.Published }}<div>{{ string .Blog.Lang "publishedon" }} <time class="dt-published" datetime="{{ dateformat .Data.Published "2006-01-02T15:04:05Z07:00"}}">{{ isodate .Data.Published }}</time>{{ if $section }} in <a href="{{ .Blog.RelativePath $section.Name }}">{{ $section.Title }}</a>{{ end }}</div>{{ end }}
{{ if .Data.Published }}<div>{{ string .Blog.Lang "publishedon" }} <time class="dt-published" datetime="{{ dateformat .Data.Published "2006-01-02T15:04:05Z07:00"}}">{{ isodate .Data.Published }}</time>{{ if $section }} in <a href="{{ .Blog.RelativePath $section.Name }}">{{ mdtext $section.Title }}</a>{{ end }}</div>{{ end }}
{{ if .Data.Updated }}<div>{{ string .Blog.Lang "updatedon" }} <time class="dt-updated" datetime="{{ dateformat .Data.Updated "2006-01-02T15:04:05Z07:00"}}">{{ isodate .Data.Updated }}</time></div>{{ end }}
{{ if replylink .Data }}
<div>{{ string .Blog.Lang "replyto" }}: <a class="u-in-reply-to" href="{{ replylink .Data }}" target="_blank" rel="noopener">{{ with (replytitle .Data) }}{{ . }}{{ else }}{{ replylink .Data }}{{ end }}</a></div>

View File

@ -1,10 +1,10 @@
{{ define "title" }}
<title>{{ .Data.Taxonomy.Title }} - {{ .Blog.Title }}</title>
<title>{{ mdtext .Data.Taxonomy.Title }} - {{ mdtext .Blog.Title }}</title>
{{ end }}
{{ define "main" }}
<main>
{{ with .Data.Taxonomy.Title }}<h1>{{ . }}</h1>{{ end }}
{{ with .Data.Taxonomy.Title }}<h1>{{ mdtext . }}</h1>{{ end }}
{{ with .Data.Taxonomy.Description }}{{ md . }}{{ end }}
{{ $blog := .Blog }}
{{ $taxonomy := .Data.Taxonomy.Name }}

View File

@ -1,5 +1,5 @@
{{ define "title" }}
<title>{{ string .Blog.Lang "webmentions" }} - {{ .Blog.Title }}</title>
<title>{{ string .Blog.Lang "webmentions" }} - {{ mdtext .Blog.Title }}</title>
{{ end }}
{{ define "main" }}