mirror of https://github.com/jlelse/GoBlog
Use fallback title generated from summary in HTML HEAD title
This commit is contained in:
parent
6a2642f25f
commit
8012691d7a
|
@ -86,12 +86,8 @@ func parseMicroformatsFromReader(u string, r io.Reader) (*microformatsResult, er
|
||||||
m.Title = ""
|
m.Title = ""
|
||||||
}
|
}
|
||||||
// Shorten content and title if too long
|
// Shorten content and title if too long
|
||||||
if cr := []rune(m.Content); len(cr) > 500 {
|
m.Content = truncateStringWithEllipsis(m.Content, 500)
|
||||||
m.Content = string(cr[0:497]) + "…"
|
m.Title = truncateStringWithEllipsis(m.Title, 60)
|
||||||
}
|
|
||||||
if tr := []rune(m.Title); len(tr) > 60 {
|
|
||||||
m.Title = string(tr[0:57]) + "…"
|
|
||||||
}
|
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -128,6 +128,10 @@ func (a *goBlog) postSummary(p *post) (summary string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *goBlog) fallbackTitle(p *post) string {
|
||||||
|
return truncateStringWithEllipsis(a.postSummary(p), 30)
|
||||||
|
}
|
||||||
|
|
||||||
func (a *goBlog) postTranslations(p *post) []*post {
|
func (a *goBlog) postTranslations(p *post) []*post {
|
||||||
translationkey := p.firstParameter("translationkey")
|
translationkey := p.firstParameter("translationkey")
|
||||||
if translationkey == "" {
|
if translationkey == "" {
|
||||||
|
|
6
ui.go
6
ui.go
|
@ -887,7 +887,11 @@ func (a *goBlog) renderPost(hb *htmlbuilder.HtmlBuilder, rd *renderData) {
|
||||||
a.renderBase(
|
a.renderBase(
|
||||||
hb, rd,
|
hb, rd,
|
||||||
func(hb *htmlbuilder.HtmlBuilder) {
|
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"))
|
hb.WriteElementOpen("link", "rel", "stylesheet", "href", a.assetFileName("css/chroma.css"))
|
||||||
a.renderPostHeadMeta(hb, p)
|
a.renderPostHeadMeta(hb, p)
|
||||||
if su := a.shortPostURL(p); su != "" {
|
if su := a.shortPostURL(p); su != "" {
|
||||||
|
|
7
utils.go
7
utils.go
|
@ -403,3 +403,10 @@ func stringToInt(s string) int {
|
||||||
func loStringNotEmpty(s string, _ int) bool {
|
func loStringNotEmpty(s string, _ int) bool {
|
||||||
return s != ""
|
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…
Reference in New Issue