diff --git a/README.md b/README.md index 2ef5bb3..257340a 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,8 @@ package = "netlify-plugin-a11y" ] # # optional config + # ignoreDirectories = ['/admin'] # explicitly ignore these directories + # resultMode = "warn" # is "error" by default # # Developer only diff --git a/manifest.yml b/manifest.yml index df5c2b8..441706e 100644 --- a/manifest.yml +++ b/manifest.yml @@ -2,6 +2,8 @@ name: netlify-plugin-a11y inputs: - name: checkPaths required: true + - name: ignoreDirectories + required: false - name: resultMode default: error - name: debugMode diff --git a/plugin/index.js b/plugin/index.js index b93e243..36d6cee 100644 --- a/plugin/index.js +++ b/plugin/index.js @@ -9,12 +9,13 @@ const pluginCore = require('./pluginCore'); module.exports = { async onPostBuild({ - inputs: { checkPaths, resultMode, debugMode }, + inputs: { checkPaths, ignoreDirectories, resultMode, debugMode }, constants: { PUBLISH_DIR }, utils: { build } }) { const htmlFilePaths = await pluginCore.generateFilePaths({ fileAndDirPaths: checkPaths, + ignoreDirectories: ignoreDirectories || [], PUBLISH_DIR }); if (debugMode) { diff --git a/plugin/pluginCore.js b/plugin/pluginCore.js index 9d30b55..6eda87f 100644 --- a/plugin/pluginCore.js +++ b/plugin/pluginCore.js @@ -27,19 +27,29 @@ exports.runPa11y = async function({ htmlFilePaths, testMode, debugMode }) { exports.generateFilePaths = async function({ fileAndDirPaths, // array, mix of html and directories + ignoreDirectories = [], PUBLISH_DIR, testMode, debugMode }) { + const excludeDirGlobs = ignoreDirectories.map( + // add ! and strip leading slash + (dir) => `!${dir.replace(/^\/+/, "")}` + ); const htmlFilePaths = await Promise.all( - fileAndDirPaths.map(fileAndDirPath => findHtmlFiles(`${PUBLISH_DIR}/${fileAndDirPath}`)) + fileAndDirPaths.map(fileAndDirPath => + findHtmlFiles(`${PUBLISH_DIR}${fileAndDirPath}`, excludeDirGlobs) + ) ) return [].concat(...htmlFilePaths) }; -const findHtmlFiles = async function(fileAndDirPath) { +const findHtmlFiles = async function (fileAndDirPath, directoryFilter) { if (await isDirectory(fileAndDirPath)) { - const fileInfos = await readdirp.promise(fileAndDirPath, { fileFilter: '*.html' }) + const fileInfos = await readdirp.promise(fileAndDirPath, { + fileFilter: '*.html', + directoryFilter + }) return fileInfos.map(({ fullPath }) => fullPath) } diff --git a/tests/generateFilePaths/publishDir/admin/index.html b/tests/generateFilePaths/publishDir/admin/index.html new file mode 100644 index 0000000..63b4887 --- /dev/null +++ b/tests/generateFilePaths/publishDir/admin/index.html @@ -0,0 +1,10 @@ + + +
+ + + +