Search code examples
eleventy

How do i filter the processed files by a front-matter variable (Eleventy / 11ty)?


Actually, i want to prevent all content files (in our case markdown files) with a version set to draft to be processed by eleventy (so not rendered / copied to the output directory).


Solution

  • Taking an example from this blog post (https://rusingh.com/2020/05/14/eleventy-exclude-draft-collection-items-programmatically/), you can use a directory data file that examines the front matter and when drafts === 'version', returns false for permalink. This worked for me:

    module.exports = {
    
        eleventyComputed: {
            permalink: (data) => {
                if(data.version && data.version === 'draft') return false;
                return;
            }
        }
    }