From 1a6e9263f7022c3d6b7e51552427f8d35ba80f99 Mon Sep 17 00:00:00 2001 From: Wilco Fiers Date: Thu, 3 Jun 2021 14:27:00 +0200 Subject: [PATCH 1/2] add proposed rule option to taskforce-markdown.js --- build/taskforce-markdown.js | 4 +++- build/taskforce-rule-page/get-rule-metadata.js | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/build/taskforce-markdown.js b/build/taskforce-markdown.js index 94d3aa2927..3dcc95ea29 100644 --- a/build/taskforce-markdown.js +++ b/build/taskforce-markdown.js @@ -13,6 +13,7 @@ program .option('-o, --outDir ', 'Path to output dir') .option('-r, --rulesDir ', 'Path to _rules directory') .option('-g, --glossaryDir ', 'Path to glossary directory') + .option('-p, --proposed', 'List the rule with the Proposed rule template') .parse(process.argv) taskforceMarkdown(program) @@ -30,6 +31,7 @@ async function taskforceMarkdown({ glossaryDir = glossaryDirDefault, ruleIds = [], outDir = './content/', + proposed = false, }) { const rulesData = getMarkdownData(rulesDir) const glossary = getMarkdownData(glossaryDir) @@ -39,7 +41,7 @@ async function taskforceMarkdown({ if (ruleIds.length && !ruleIds.includes(ruleData.frontmatter.id)) { continue } - const { filepath, content } = buildTfRuleFile(ruleData, glossary) + const { filepath, content } = buildTfRuleFile({ ...ruleData, proposed }, glossary) await createFile(path.resolve(outDir, filepath), content) const definitions = parseDefinitions(content) diff --git a/build/taskforce-rule-page/get-rule-metadata.js b/build/taskforce-rule-page/get-rule-metadata.js index 6874b5edf7..c7eb1adcf2 100644 --- a/build/taskforce-rule-page/get-rule-metadata.js +++ b/build/taskforce-rule-page/get-rule-metadata.js @@ -3,7 +3,7 @@ const { getAccessibilityRequirement } = require('../../src/rule/get-accessibilit module.exports = getRuleMetadata -function getRuleMetadata({ frontmatter }) { +function getRuleMetadata({ frontmatter, proposed }) { const metadata = [ 'Rule Type:\n' + toDfnTerm(frontmatter.rule_type), 'Rule ID:\n' + toDfnTerm(frontmatter.id), @@ -12,6 +12,9 @@ function getRuleMetadata({ frontmatter }) { inputAspects(frontmatter), inputRules(frontmatter), ] + if (proposed) { + metadata.unshift('{% include_relative _proposed-banner.html %}') + } return metadata.filter(str => str !== '').join('\n\n') } From ec556b09f5af0b6317edeb44ec638d9946ddd74d Mon Sep 17 00:00:00 2001 From: Wilco Fiers Date: Mon, 14 Jun 2021 15:36:44 +0200 Subject: [PATCH 2/2] feat(tfmd): update wcag-mapping.json --- build/taskforce-markdown.js | 61 ++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/build/taskforce-markdown.js b/build/taskforce-markdown.js index 3dcc95ea29..e406f7ba5e 100644 --- a/build/taskforce-markdown.js +++ b/build/taskforce-markdown.js @@ -3,6 +3,7 @@ const getMarkdownData = require('../utils/get-markdown-data') const createFile = require('../utils/create-file') const getRuleContent = require('./taskforce-rule-page/get-rule-content') const getDefinitionContent = require('./taskforce-rule-page/get-definition-content') +const { getWcagCriterion } = require('../src/rule/get-wcag-criterion') const program = require('commander') const rulesDirDefault = path.resolve(__dirname, '../node_modules/act-rules-community/_rules') @@ -36,13 +37,19 @@ async function taskforceMarkdown({ const rulesData = getMarkdownData(rulesDir) const glossary = getMarkdownData(glossaryDir) const glossaryFiles = new Set() + let wcagMapping = require(path.resolve(outDir, 'wcag-mapping.json')) - for (const ruleData of rulesData) { + for (let ruleData of rulesData) { + ruleData = { ...ruleData, proposed } if (ruleIds.length && !ruleIds.includes(ruleData.frontmatter.id)) { continue } - const { filepath, content } = buildTfRuleFile({ ...ruleData, proposed }, glossary) - await createFile(path.resolve(outDir, filepath), content) + + wcagMapping['act-rules'] = updateWcagMapping(wcagMapping['act-rules'], ruleData) + console.log(`Updated ${ruleLink(ruleData)}`) + + const { filepath, content } = buildTfRuleFile(ruleData, glossary) + await createFile(path.resolve(outDir, 'content', filepath), content) const definitions = parseDefinitions(content) definitions.forEach(dfn => glossaryFiles.add(dfn)) @@ -52,6 +59,9 @@ async function taskforceMarkdown({ const { filepath, content } = buildTfDefinitionFile(definition, glossary) await createFile(path.resolve(outDir, filepath), content) } + + await createFile(path.resolve(outDir, 'wcag-mapping.json'), JSON.stringify(wcagMapping, null, 2)) + console.log('\nUpdated wcag-mapping.json') } function buildTfRuleFile(ruleData, glossary) { @@ -63,7 +73,7 @@ function buildTfRuleFile(ruleData, glossary) { function buildTfDefinitionFile(definitionKey, glossary) { return { - filepath: `glossary/${definitionKey}.md`, + filepath: `content/glossary/${definitionKey}.md`, content: getDefinitionContent(definitionKey, glossary), } } @@ -79,3 +89,46 @@ function parseDefinitions(content) { }) return definitionKeys } + +function ruleLink({ frontmatter, filename }) { + return `[${frontmatter.name}](${ruleUrl(filename)})` +} + +function updateWcagMapping(wcagMapping, { frontmatter, filename, proposed }) { + const { id } = frontmatter + wcagMapping = wcagMapping.filter(({ permalink }) => !permalink.includes('-' + id)) + const { successCriteria, wcagTechniques } = getRequirements(frontmatter) + + wcagMapping.push({ + title: frontmatter.name.replace(/`/gi, ''), + permalink: ruleUrl(filename), + successCriteria, + wcagTechniques, + proposed, + }) + return wcagMapping +} + +function ruleUrl(filename) { + return `/standards-guidelines/act/rules/${filename.replace('.md', '')}/` +} + +function getRequirements({ accessibility_requirements: requirements }) { + const successCriteria = [] + const wcagTechniques = [] + Object.keys(requirements || {}).forEach(id => { + const [standard, key] = id.split(':') + if (standard === 'wcag-technique') { + wcagTechniques.push(key) + } + + if (standard.indexOf('wcag2') === 0) { + const scId = getWcagCriterion(key).url.split('#')[1] + if (scId) { + successCriteria.push(scId) + } + return + } + }) + return { successCriteria, wcagTechniques } +}