Skip to content

front page filter by source file type #1635

@btrem

Description

@btrem

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions