Search code examples
jekyll

How to render two files from a single markdown


I have a collection of markdown files and I would like to render in two different set of files using two different layout files when building the page:

– html files for the website – xml files

Is it possible to do this? It seems that a markdown file can be only parsed once. Any suggestions? Many thanks


Solution

  • Instead of having a markdown file that points to a layout file, you're going to need two pages that point to the markdown post file.

    There are a number of ways to point to a post file. I like to use a where filter:

    {% assign post = site.posts | where:"url", include.url | first %}
    

    Now that you have a post, let's say you have fileOne.html that you want to put that post into. Here's how you'd approach that:

    ---
    layout:main
    ---
    
    <h1>Some html here</h1>
    
    {% assign post = site.posts | where:"url", include.url | first %}
    {{ post.content }}
    

    Then you could do the exact same thing in another file named fileTwo.html.