Making Hugo Post List Summaries Plain Text with plainify

Removing HTML tags from article summaries in Hugo using plainify

The summary display in the article list on the top page was being shown with the HTML notation still left in it, which felt wrong, so I fixed it ↓

Stripping the HTML also looks better for SEO, so I made the following change

layouts/partials/post_preview.html

<article class="post-preview">
    <a href="{{ .Permalink }}">
        <h2 class="post-title">{{ .Title }}</h2>
        {{ if .Params.subtitle }}
        <h3 class="post-subtitle">
            {{ .Params.subtitle }}
        </h3>
        {{ end }}
        {{ if .Params.image }}
        <img src="{{ .Params.image }}" alt="{{ .Title }}" class="img-title" />
        {{ end }}
        {{ if .Params.video }}
        <video loop autoplay muted playsinline class="img-title">
            <source src="{{ .Params.video }}">
        </video>
        {{ end }}
    </a>

    <p class="post-meta">
        {{ partial "post_meta.html" . }}
    </p>
    <div class="post-entry">
        {{ if or (.Truncated) (.Params.summary) }}
        {{ .Summary | plainify }}
        <a href="{{ .Permalink }}" class="post-read-more">[{{ i18n "readMore" }}]</a>
        {{ else }}
        {{ .Content }}
        {{ end }}
    </div>

    {{ if .Params.tags }}
    <div class="blog-tags">
        {{ range .Params.tags }}
       <a href="{{"tags" | absLangURL}}/{{ . | urlize }}/">{{ . }}</a>&nbsp;
        {{ end }} 
    </div>
    {{ end }}

</article>

Test markdown

Each post also has a subtitle

You can write regular markdown here and Jekyll will automatically convert it to a nice webpage. I strongly encourage you to take 5 minutes to learn how to write in markdown - it’ll teach you how to transform regular text into bold/italics/headings/tables/etc. Here is some bold text Here is a secondary heading Here’s a useless table: Number Next number Previous number Five Six Four Ten Eleven Nine Seven Eight Six Two Three One How about a yummy crepe? [Read More]