nodejh / hugo-theme-mini

A fast, minimalist and responsive hugo theme for bloggers.

Home Page:http://nodejh.github.io/hugo-theme-mini

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Better Post Description

tosoikea opened this issue · comments

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) "[&hellip;] ") | plainify | truncate (default 200 .Site.Params.summary_length) (default " &hellip;" .Site.Params.text.truncated ) | replaceRE "&amp;" "&" | safeHTML) }}
   		{{ end }}
   		<h2>{{ $.Scratch.Get "summary" }}</h2>
                   {{ end }}
               </a>
           </li>
       {{ end }}
   {{ end }}
</ul>

Before
image

Afterwards
image

@tosoikea Thank you :), Feels a lot natural~