Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better Post Description #62

Open
tosoikea opened this issue Sep 20, 2018 · 1 comment
Open

Better Post Description #62

tosoikea opened this issue Sep 20, 2018 · 1 comment

Comments

@tosoikea
Copy link

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

@CSaratakij
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants