Skip to content

Instantly share code, notes, and snippets.

Last active Jul 9, 2021
What would you like to do?
Eleventy URL Linter to check for changed URLs when swapping from `slug` to `slugify` filters (via @pdehaan)
const assert = require("assert");
const inspect = require("util").inspect;
module.exports= (eleventyConfig) => {
// ever so slightly modified from @pdehaan’s original:
const slugFn = eleventyConfig.getFilter("slug");
const slugifyFn = eleventyConfig.getFilter("slugify");
const slugErrors = new Set();
eleventyConfig.addFilter("slug", function (str="") {
const slugValue = slugFn(str);
try {
assert.strictEqual(slugValue, slugifyFn(str));
} catch (err) {
// Only display a unique error once.
if (!slugErrors.has(err.message)) {
console.error(`\nslug-vs-slugify filter mismatch for ${inspect(str)}\n${err.message}`);
process.exitCode = 2;
} finally {
return slugValue;
Copy link

zachleat commented Jul 9, 2021

This is now bundled into the Eleventy Upgrade Helper plugin:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment