Use fallback title generated from summary in HTML HEAD title

pull/47/head
Jan-Lukas Else 1 month ago
parent 6a2642f25f
commit 8012691d7a

@ -86,12 +86,8 @@ func parseMicroformatsFromReader(u string, r io.Reader) (*microformatsResult, er
m.Title = ""
}
// Shorten content and title if too long
if cr := []rune(m.Content); len(cr) > 500 {
m.Content = string(cr[0:497]) + "…"
}
if tr := []rune(m.Title); len(tr) > 60 {
m.Title = string(tr[0:57]) + "…"
}
m.Content = truncateStringWithEllipsis(m.Content, 500)
m.Title = truncateStringWithEllipsis(m.Title, 60)
return m, nil
}

@ -128,6 +128,10 @@ func (a *goBlog) postSummary(p *post) (summary string) {
return
}
func (a *goBlog) fallbackTitle(p *post) string {
return truncateStringWithEllipsis(a.postSummary(p), 30)
}
func (a *goBlog) postTranslations(p *post) []*post {
translationkey := p.firstParameter("translationkey")
if translationkey == "" {

@ -887,7 +887,11 @@ func (a *goBlog) renderPost(hb *htmlbuilder.HtmlBuilder, rd *renderData) {
a.renderBase(
hb, rd,
func(hb *htmlbuilder.HtmlBuilder) {
a.renderTitleTag(hb, rd.Blog, p.RenderedTitle)
if p.RenderedTitle != "" {
a.renderTitleTag(hb, rd.Blog, p.RenderedTitle)
} else {
a.renderTitleTag(hb, rd.Blog, a.fallbackTitle(p))
}
hb.WriteElementOpen("link", "rel", "stylesheet", "href", a.assetFileName("css/chroma.css"))
a.renderPostHeadMeta(hb, p)
if su := a.shortPostURL(p); su != "" {

@ -403,3 +403,10 @@ func stringToInt(s string) int {
func loStringNotEmpty(s string, _ int) bool {
return s != ""
}
func truncateStringWithEllipsis(s string, l int) string {
if tr := []rune(s); len(tr) > l && l > 3 {
return string(tr[0:l-3]) + "…"
}
return s
}

Loading…
Cancel
Save