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

blog: Use standard summaryLength or explicit summary length (if set) #44

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ defaultContentLanguageInSubdir = false
googleanalytics = "UA-Not-Yet"
metaDataFormat = "toml"
pagination.pagerSize = 5
summaryLength = 25
theme = ["blog", "solus"]
enableInlineShortcodes = true

Expand Down
14 changes: 5 additions & 9 deletions themes/blog/layouts/blog/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@
<meta itemscope itemprop="mainEntityOfPage" itemType="https://schema.org/WebPage" itemid="{{ $firstBlog.Permalink | absURL }}"/>
<section>
{{ partial "blog/info.html" (dict "blog" $firstBlog "site" .Site) }}
{{ if ge (len $firstBlog.Summary) 397 }}
<p itemprop="description">{{- htmlUnescape (plainify (safeHTML (substr $firstBlog.Summary 0 187))) -}}...</p>
{{ else }}
<p itemprop="description">{{- htmlUnescape (plainify (safeHTML $firstBlog.Summary)) -}}</p>
{{ end }}
<div class="menu">
<nav>
<div itemprop="description">{{- safeHTML $firstBlog.Summary -}}</div>
Copy link
Member

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:

Suggested change
<div itemprop="description">{{- safeHTML $firstBlog.Summary -}}</div>
<p itemprop="description">{{- htmlUnescape (plainify (safeHTML $firstBlog.Summary)) -}}</p>

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about:

Suggested change
<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

Copy link
Member Author

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 ^^

Copy link
Member

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?

Copy link
Member Author

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)

<div class="menu">
<nav>
<a class="button inverse" href="{{ $firstBlog.Permalink }}">Read More</a>
</nav>
</div>
</nav>
</div>
</section>
{{ $url := (printf "%s/%s" $firstBlog.Params.url $firstBlog.Params.featuredimage) | absURL }}
<img alt="{{ $firstBlog.Title }}" src="{{ $url }}"></img>
Expand Down