Better Post Description
tosoikea opened this issue · 1 comments
tosoikea commented
Hello,
based on https://yihui.name/en/2017/08/hugo-post-summary/ I changed \layouts\partials\post_list.
This results in a more natural feeling description of the single posts if no manual description can be found.
The length of the single posts can be changed inside the config via summary_length.
<ul id="post-list">
{{ range where .Paginator.Pages "Params.hidden" "ne" "true" }}
{{ $url := replace .Permalink .Site.BaseURL "" }}
{{ if ne $url "about/" }}
<li>
<aside class="dates">{{ .Date.Format "Jan 2" }}</aside>
<a href='{{ .Permalink }}'>
{{ .Title }}
{{ if .Site.Params.enableSummary }}
{{ with .Description }}
{{ $.Scratch.Set "summary" (markdownify .) }}
{{ else }}
{{ $.Scratch.Set "summary" ((delimit (findRE "(<p.*?>(.|\n)*?</p>\\s*)+" .Content) "[…] ") | plainify | truncate (default 200 .Site.Params.summary_length) (default " …" .Site.Params.text.truncated ) | replaceRE "&" "&" | safeHTML) }}
{{ end }}
<h2>{{ $.Scratch.Get "summary" }}</h2>
{{ end }}
</a>
</li>
{{ end }}
{{ end }}
</ul>
CSaratakij commented
@tosoikea Thank you :), Feels a lot natural~