You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My front page shows excerpts of recent posts, some of which are markdown, some nunjucks. If I filter the content with safe {{ post.data.page.excerpt | safe }} the njk excerpts display correctly, but md excerpts are not processed into html. If I add a markdown filter {{ post.data.page.excerpt | md | safe }}, the md excerpts display correctly, but njk do not; because the html code in njk files are indented, the excerpts are converted to code blocks.
Is this the right way to handle this? Is there another way I don't know about, maybe a way to determine file type instead of checking the end of the source file extension?
The text was updated successfully, but these errors were encountered:
Neat, I didn't know you could do {% if post.inputPath.endsWith(".md") %} in Nunjucks.
I think this is a great solution. Only alternative I could think of would be adding mdExcerpt frontmatter to files that you want preprocessed by your custom "md" filter, then you could do something like this if you're looping over a collection or whatever:
My other suggestions would be worse, like a filter named "maybeMd" that takes the input string and a boolean value on whether it should return the raw input string or a markdown-ified version:
Neat, I didn't know you could do {% if post.inputPath.endsWith(".md") %} in Nunjucks.
Neither did I 'til I tried it. I found it in a thread about filters, and decided to blindly give it a go. :)
For now, at least, I'll stick with checking the extension. Otherwise, I'd have to remember to add an mdExcerpt item to the front matter of all posts, but only when the post is written in markdown.
My front page shows excerpts of recent posts, some of which are markdown, some nunjucks. If I filter the content with safe
{{ post.data.page.excerpt | safe }}
the njk excerpts display correctly, but md excerpts are not processed into html. If I add a markdown filter{{ post.data.page.excerpt | md | safe }}
, the md excerpts display correctly, but njk do not; because the html code in njk files are indented, the excerpts are converted tocode
blocks.To solve this, I write this code in my layout:
Is this the right way to handle this? Is there another way I don't know about, maybe a way to determine file type instead of checking the end of the source file extension?
The text was updated successfully, but these errors were encountered: