Is it possible to create an "include" shortcode that allows manual summaries to continue working?

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:

  1. 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.
  2. 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?

Can you use the summary field in front matter?

The answer to this is no. Manual summary determination is performed during parsing, before shortcodes are evaluated.

Thanks @jmooring for such a prompt response!

Yes, I’m aware I could use the summary field in front matter, but that would mean I have to write (and maintain) a manual summary for the “copied” posts as well. I also personally like using the first 1-2 paragraphs of each post as a general introduction, so I’ve always found the <!--more--> tag to be a more elegant and convenient solution for me.

Anyway, not a big deal. I guess I’ll deal with it on a case by case basis, adding a front matter summary only when the automatic one looks too different/awkward compared to the manual one from the original post.

Thanks again!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.