I have a shortcode which I use in my markdown files. It adds parametrized boilerplate content which I want to exclude (or render differently) in my full-text RSS feed.
Is there a way to do this? Maybe there are some variables which I can check in my shortcode?
Following your advice I attempted to use {{ with .Page.OutputFormats.Get "HTML" }} (to render the shortcode only in HTML), but it crashed Hugo with this error: can't evaluate field Site in type *hugolib.OutputFormat.
Then I changed it to use different statements and it seems to be working:
{{ if .Page.OutputFormats.Get "HTML" }}
...
{{ end }}
You’re talking about splitting .Content and making the check in the template.
That’s a bit involved but:
strings.Contains might help to search within .Content without splitting it (look it up in the forum, it’s not in the Docs -don’t know why-)
I vaguely remember someone posting about splitting .Content on GitHub. (search the closed Hugo Issues on GitHub).
Also if you feel like uploading a repository with a test project, it would help people who want to check out whether it is possible to exclude a shortcode from the RSS pages.
then my quote.rss.xml shortcode get picked up for rendering content inside RSS and it works as expected.
Unfortunately, this solution has one side effect - it generates additional per-page rss files which I do not want. Also each html post gets a link <link rel="alternate" type="application/rss+xml" ... to this RSS feed, which can confuse an RSS reader.
I think this is a bug - if RSS format is enabled for the home page, then when I render page Content in the rss.xml it should be considered to be part of the home page and inherit its format.
Basically I placed both rendering variants into the quote.html, surrounded by html comments, and then remove one variant and uncomment another.
This is ugly, because in the actual site I have multiple shortcodes which I want to render differently, and this leads to multiple replaceRE pipes. But so far it works and does not produce additional *.xml files for pages.
If you say that the home page should be output to RSS, we use any RSS-specific shortcode to render the shortcodes in the home page’s .Content. This currently does not extend to any page you include via where etc.
@bep Is it worth filing a bug on Github? So far in this thread I collected several other threads where people are trying to alter the content rendering for RSS feeds.
If you call it a feature request and not a bug, then yes.
Note that the “shortcode output format” support was added to support the AMP use case, so to speak. Where you set AMP as output format for all of your pages (not just the home page, as an example). In that case, you would have “output format variants” of every page. Doing the same for RSS would be wasteful.