Is there a “read more” for {{ .Content }}
? That is, a way to “break” a long post (without using {{ .Summary }}
).
You can mark a summary paragraph (the first) in your content with the more tag. Then, .Summary contains this paragraph and we can use it in a list template. When we range through the pages there, we can add a ‘Read more’ link after this .Summary.
I know I can use {{ .Sumary }}
. I am asking if it is possible without using it. For example, on Jekyll, one can do:
{% if post.content contains "<!-- more -->" -%}
{{ post.content | split:"<!-- more -->" | first }}
<div class="more">
<a href="{{ post.url }}#more”>Read more...</a>
</div>
{% else -%}
{{ post.content }}
{% endif -%}
Can that be done in Hugo?
I haven’t tried, but you would need to apply the manual split on .RawContent. I would rather not go down this path.
Found a way to do what I was looking for. For anyone that is the “same boat”, I found this on this site[0]:
{{ $parts := split .Content "<!-- readmore -->" }}
{{ $summary := index $parts 0 }}
{{ $summaryHTML := safeHTML $summary }}
{{ if eq $summaryHTML .Content }}
{{ .Content }}
{{ else }}
{{ $summaryHTML }}
<a href="{{ .Permalink }}”>Read more...</a>
{{ end }}
[0] How to show the full post unless there’s a user defined summary in Hugo · Elliot Jackson
@Fastidious - I think you are looking for .Truncated
For example:
{{ .Summary }}
{{ if .Truncated }}
<div class="read-more-link">
<a href="{{ .RelPermalink }}">Read More…</a>
</div>
{{ end }}
this is code from https://github.com/lukeorth/poison/blob/9348267ecf29174cd4f2e5a5ba9eeb9d06edadec/layouts/index.html#L6
No, I want {{ .Content }}
, not {{ .Summary }}
. The first is rich (all HTML and markdown glory), the second isn’t. Just as the original author, I want to randomly split {{ .Content }}
, like so:
---
title: "Example title"
date: 2017-08-09T12:45:27+02:00
categories: [Hugo]
---
This is the first paragraph in the post. It will be shown on the home page as it's before the summary separator.
<!-- readmore -->
On the homepage, this content won't be shown as it's after the summary separator.
With that snippet, I can.
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.