Has anyone been able to get truncated posts in newsletters working? My use case is that I have posts with Hugo shortcodes for YouTube videos or iframes for Bandcamp embeds. I can’t leave those in the posts when the newsletter is sent. I used this code to try and truncate posts with a more tag:
{{ if ne .Summary .Content }}
<p><a href="{{ .permalink }}" class="read-more">Read more...</a></p>
{{ end }}
Nothing showed up in the newsletter preview, so I ditched the effort temporarily.
I would expect that to work. Can you share an example post with the embed and “more” tag? Hugo shortcodes don’t work in newsletters so that might be something else that will need to change.
I did, but the preview came up blank. Unfortunately, I was out and about and couldn’t really mess with it too much on mobile before send, so I just took out the code.
Exactly, I’m trying to truncate those posts that have any embeds, since I know they won’t come though in the newsletter. I’ll play around with it some more this weekend and then I’ll send some examples.
The idea and logic are solid, but the issue is that .Summary and .Content aren’t exactly equal, even when they seem the same. There’s usually some leftover HTML or whitespace that needs to be stripped before any comparison.
Since we don’t have access to Hugo’s plainify and similar functions, that makes things a bit tricky.
A simple, though maybe not the most elegant, workaround is to skip the check and always show the Read more… link, but label it differently, like Read post on blog…
This might be a tangent, but… Should Micro.blog newsletters support plainify and some other basic Hugo functions? We basically have to re-implement them for newsletters but I think adding a few helper functions would be convenient.