Block build if "my error" occur

Hello there,

In my frontmatter I have an ID property. As the name suggest, ID should be unique, but given the nature of MM, it can be easy while copying and pasting from previous pages creating a duplicate.

I was wondering whether it is possible create a custom method that during the build parse all the ID and block the execution if a duplicate is found.

Creating the array maybe not that complicate. I assume I can get access to the sitemap object and read the property from the YAML. But how to step into the build process is a total different story for which I don’t have a clue.

Any idea is appreciated.
Thanks
Andrea

A simple way of doing it would be to use after_build to start a snippet of code that walks your build directory, parses the pages and alers you if there is a duplicate id.

Thanks. Am I right thinking you would traverse the sitemap object for this?

Any chance to pass a little snippet?

Thanks

No need to use the sitemap, or any Middleman-specific code. All you need is to look at the generated html-files in the build folder, once Middleman has finished generating the files.

Just walk the build directory, looking for html-files (I have no code snippet for you, but I’m sure you will have no trouble finding code for this on the web), and then parse the files, looking for duplicate id’s (this also you should be able to find example code for).