Hi All,
I am trying to use <meta name="description" content="{{ .Description }}">, if I do not set a description to the page, I hope to use the contents in the page. However, if my page has shortcodes, the shortcodes will also be included in the meta.
I know I can try to find all “{{< >}}” then remove them by my customized function, but I wonder if there is already a built-in fast way/function to do so?
Thanks!
Then if I just want to remove the shortcodes in the middle of the contents while keeping other contents,
for example:
some text...
{{< shortcodes >}}
some other text...
If I just want to filter out shortcodes and use the plain text, I think I need to append the rest contents.
I also find trim might be useful, but if we have several shortcodes within the contents, it’s a little bit more complex to filter.
like:
some text...
{{< shortcodes >}}
some other text...
{{< anotherShortcodes >}}
some more text...
But for now, truncate and trim seems good. It would be great if it can detect all the shortcodes I am using, just like what it does to filter out all HTML tags.
On list pages you can hide the rendered shortcode content with a condition like: {{ if eq $.Page.Kind "page" }} -from within the shortcode-.
To hide the rendered shortcodes in a description meta tag at the head of the content file that contains them, you would have to resort to RegEx -as you know-:
{{ .RawContent | replaceRE `{{.*?}}` `` }}
In the above, the .RawContent variable fetches the raw markdown content with the unprocessed shortcodes and the replaceRE function will remove everything between the curled brackets.
I have another issue then, seems .RawContent only works with Page. If mine is:
{{ with .Description | default .Summary }}
Cannot with them. When I use .Description or .Summary, it’s already a string that cannot be parsed by RawContent. I probably need to think of other ways how I want to use it.