💾 Archived View for gmi.bacardi55.io › blog › 2024 › 03 › 04 › displaying-featured-posts-on-hugo-hom… captured on 2024-08-24 at 23:54:53. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2024-03-21)

-=-=-=-=-=-=-

Displaying featured posts on hugo homepage

Posted on 2024-03-04

During the last set of [blog updates of February], I decided to change my homepage to make it leaner (by removing most of the text), but I also changed the content lists displayed.

The homepage now display:

The last 2 are just a change in the number of items being retrieved, whereas the first two are a changed of which items are retrieved.

Before this update, the 5 latest blog posts and gemlog entries were displayed here. It meant that, while always up to date, I didn't have control of what was displayed. I thought about it for some time, and decided that the homepage should display what I want first time visitors to see first. The full lists are one click away for people to see all articles. But I like to highlight specific ones on the homepage.

The new rule is will display the last 5 posts tagged as `featured'. I can mark posts as `featured = 1' in the frontmatter area (see [example]) if I decide they should "make the frontpage". Only the 5 latest with the feature tag are displayed. If one day I want to resurface an old post, I'll have to remove newer `featured' posts. A good mix between control and automation I believe.

Anyway, to tag a post (or gemlog or page) as `featured', all I need is to add in the `frontmatter' part of my markdown content `featured: 1'.

Then, on the homepage, I have a loop displaying only the 5 latest featured:

<ul>
    {{ range first 5 (where (where site.RegularPages "Section" "posts") "Params.featured" "eq" 1) }}
        <li>
            <div class="post-title">
                {{ .Date.Format "2006-01-02" }} <a href="{{ .RelPermalink }}">{{ .Title }}</a>
            </div>
        </li>
    {{ end }}
</ul>

Change the `posts' in the `where' clause to `gemlog' and you have the list of the latest 5 `featured' gemlog entries.

You can see the full code of my [homepage partial template on sourcehut].

blog updates of February

blog posts

gemlog entries

bookmarks

page

example

homepage partial template on sourcehut

/gemlog/

Send me a gemini mention

send me an email!