Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Tweak theme to detect and use front matter "description" field #105

Merged
merged 2 commits into from Oct 13, 2021
Merged

Tweak theme to detect and use front matter "description" field #105

merged 2 commits into from Oct 13, 2021

Conversation

Qrbaker
Copy link
Contributor

@Qrbaker Qrbaker commented Oct 12, 2021

PR Summary

This proposed change allows this theme to use a description when it is specified in the front matter, falling back to an automatically generated summary otherwise.

Explanation

The Hugo .Summary var is okay, but it doesn't respect markdown well. For example, if your post is formatted like so:

# Title
Blog content text, blah blah

The summary object converts this to Title Blog context text, blah blah; squishing headings and body text together. A way to deal with this in many themes is to allow each post to specify a "description" in the front matter:

---
title: My Blog Post
description: A manual short summary of the blog content
date: 1970-01-01
draft: false
---
Blog Content...

This proposed change, based on a similar layout in the archie theme, does the following:

  1. Check the front matter for a "description" parameter.
  2. If it exists, use the .Description Hugo variable for the post summary
  3. Otherwise, use the .Summary variable as normal.

The addition of &hellip is just escaped HTML for the horizontal ellipsis character (…), to show the text continues beyond the summary shown.

@Mitrichius Mitrichius merged commit 8b3e9c7 into Mitrichius:master Oct 13, 2021
@Mitrichius
Copy link
Owner

Oh, so that's how this works :)
Thanks for the fix!

ambroisie added a commit to ambroisie/blog that referenced this pull request Oct 13, 2021
An up-coming change to my base theme will make use of those as a summary
of the posts [1] instead of using an extract of the post. This is not of
interest to me, and I realized I actually do not make use of the
descriptions anywhere.

[1]: Mitrichius/hugo-theme-anubis#105
@ambroisie
Copy link
Contributor

I think this should be toggleable, as I specifically write my posts so that the summary is enticing to the reader, and the description field makes sense to use as in #107.

@Qrbaker
Copy link
Contributor Author

Qrbaker commented Oct 19, 2021

I think this should be toggleable, as I specifically write my posts so that the summary is enticing to the reader, and the description field makes sense to use as in #107.

You can set the param disableSummary to true in your config:

params:
  disableSummary: true

Or do you want to specifically toggle the use of the Description field for summaries between this and the previous behavior? The problem with using the raw summary, as noted in the pr, is that it doesn't understand markdown headings.

@Qrbaker
Copy link
Contributor Author

Qrbaker commented Oct 19, 2021

Hmm, I did some more looking into Hugo's official reccomendations: https://gohugo.io/content-management/summaries/

I was not aware that you could simply directly override .Summary in the front matter; I had been working off how I had used it in archie.

It appears the archie theme is actually incorrect in this case. @Mitrichius I recommend based on @ambroisie's notes and Hugo's documentation that this PR be reverted. Sorry about that!

@ambroisie
Copy link
Contributor

You can set the param disableSummary to true in your configuration

On the contrary, I want to use the summary instead of the description when displaying the index of posts, instead of prioritizing the description field.

@Mitrichius
Copy link
Owner

Reverted

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

Successfully merging this pull request may close these issues.

None yet

3 participants