-
Notifications
You must be signed in to change notification settings - Fork 8
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
blog: Use standard summaryLength or explicit summary length (if set) #44
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Thomas Staudinger <[email protected]>
Note: I could also add a conditional to check whether the summary is truncated or contains the whole post content, and only if it is truncated render the "Read More" button, but I'm not sure if that wouldn't be overkill, since it would have to be a very short blog post to fit into it as a whole. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing, otherwise, LGTM.
{{ end }} | ||
<div class="menu"> | ||
<nav> | ||
<div itemprop="description">{{- safeHTML $firstBlog.Summary -}}</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turning this element into a div
and removing the unescape/plainify makes summaries with formatting (e.g., italics) display weird. This appears to work:
<div itemprop="description">{{- safeHTML $firstBlog.Summary -}}</div> | |
<p itemprop="description">{{- htmlUnescape (plainify (safeHTML $firstBlog.Summary)) -}}</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, thanks, I see the problem with italics now after testing. Unfortunately this also loses paragraph separation for long summaries like in the current Hacktoberfest one. (I think that's why I originally turned it into a <div>
)
I'll play around with it a bit more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about:
<div itemprop="description">{{- safeHTML $firstBlog.Summary -}}</div> | |
{{ $summaryParagraphs := split $firstBlog.Summary "<p>" }} | |
{{range $summaryParagraphs }} | |
{{ if eq . "" }} | |
{{ continue }} | |
{{ end }} | |
<p itemprop="description">{{ htmlUnescape (plainify (safeHTML .)) }}</p> | |
{{end}} |
This keeps the paragraphs separated, while escaping/removing other formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, that formatting looks ass here ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the formatting is because of tabs vs spaces xD
That said, I'm not entirely sure what that snippet is doing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Splitting the summary along paragraphs, then inserting those paragraphs as separate elements, but with all formatting inside of them plainified.
(and that one if is there to exclude that one empty element of the slice this split creates; maybe I'll find a more elegant solution)
This removes some custom overrides of the summary length for blog posts and instead relies on the
summaryLength
hugo parameter where it's not manually set, and uses the manually set summary length set in single blog posts (set via<!--more-->
).Also allow paragraph html elements in the summary
25 seemed a good value for the default summary length in my testing
Resolves #41