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.
To solve this, I write this code in my layout:
{% if post.inputPath.endsWith(".md") %}
{{ post.data.page.excerpt | md | safe }}
{% else %}
{{ post.data.page.excerpt | safe }}
{% endif %}
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?
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 tocodeblocks.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?