I have a blog where I sometimes want to replace the full contents of a blog post with the existing version from a different language.
The way I’m doing this right now is by adding a shortcode that looks like this:
{{ with .Site.GetPage (.Get 0) }}
{{ $alternative_version := index (.Translations) 0 }}
{{ $alternative_version.RawContent }}
{{ end }}
Then in the actual markdown file for the affected post, I simply add this below the header:
{{% include_alternative_version "/blog/my-post" %}}
I initially tried to use .Content
, but that would break things like the Table of Contents, so I switched to .RawContent
. Now the Table of Contents is working again, however I still have two problems:
- In the list of posts that is shown in my homepage, manual summaries generated with
<!--more-->
tags are not working for “included” posts. Instead, an automatic summary is shown. - The
<!--more-->
tag now becomes visible in the actual body of the post, which is obviously not desired.
I can obviously solve #2 by simply adding | safeHTML
to the shortcode definition:
{{ with .Site.GetPage (.Get 0) }}
{{ $alternative_version := index (.Translations) 0 }}
{{ $alternative_version.RawContent | safeHTML}}
{{ end }}
But this takes me further away from making manual summaries actually work, as the tag isn’t even present in the included content anymore.
Is there any way to make manual summaries work when the post contents have been inserted from a different file?