-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds
meta name="generator"
check to upgrade plugin
- Loading branch information
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const chalk = require("kleur"); | ||
|
||
module.exports = async function(eleventyConfig) { | ||
const { default: matchHelper } = await import("posthtml-match-helper"); | ||
|
||
let htmlTemplatesMissingMetaGenerator = new Set(); | ||
let found = 0; | ||
|
||
eleventyConfig.on("eleventy.before", () => { | ||
htmlTemplatesMissingMetaGenerator = new Set(); | ||
found = 0; | ||
}); | ||
|
||
eleventyConfig.on("eleventy.after", () => { | ||
if(htmlTemplatesMissingMetaGenerator.size > 0) { | ||
console.log(chalk.blue(`[11ty/eleventy-upgrade-help] NOTICE`), `Your project has .html output files (×${htmlTemplatesMissingMetaGenerator.size}) that don’t have a populated <meta name="generator" content> tag. It would be helpful to Eleventy if you added it (but isn’t required). Applicable input files: ${Array.from(htmlTemplatesMissingMetaGenerator).join(", ")} Read more: https://www.11ty.dev/docs/data-eleventy-supplied/#use-with-meta-namegenerator`); | ||
} else { | ||
console.log(chalk.green(`[11ty/eleventy-upgrade-help] PASSED`), `All of your project’s .html output files (×${found}) are using <meta name="generator" content="Eleventy …">`); | ||
} | ||
}); | ||
|
||
eleventyConfig.htmlTransformer.addPosthtmlPlugin( | ||
"html", | ||
function (options) { | ||
return function (tree) { | ||
let missing = 1; | ||
|
||
tree.match(matchHelper(`meta[name="generator"]`), function (node) { | ||
if (node.attrs?.content && (node.attrs?.content || "").toLowerCase().startsWith("eleventy")) { | ||
missing--; | ||
} | ||
|
||
return node; | ||
}); | ||
|
||
if(missing > 0) { | ||
htmlTemplatesMissingMetaGenerator.add(options.page.inputPath); | ||
} else { | ||
found++; | ||
} | ||
}; | ||
} | ||
); | ||
}; |