Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linters allow inspection of content #225

Closed
zachleat opened this issue Sep 13, 2018 · 2 comments
Closed

Linters allow inspection of content #225

zachleat opened this issue Sep 13, 2018 · 2 comments
Assignees
Milestone

Comments

@zachleat
Copy link
Member

Option to test and throw warnings based on generated content result.

Examples:

@zachleat zachleat added this to the 0.5.4 milestone Sep 13, 2018
@zachleat zachleat self-assigned this Sep 13, 2018
@zachleat
Copy link
Member Author

Sample inclusive-language filter:

eleventyConfig.addLinter("inclusive-language", function(content, inputPath, outputPath) {
	let words = "simply,obviously,basically,of course,clearly,just,everyone knows,however,easy".split(",");
	if( inputPath.endsWith(".md") ) {
		let found = [];
		for( let word of words) {
			word = word.trim();
			let regexp = new RegExp("\\b" + word + "\\b", "gi");
			if(!!content.match(regexp)) {
				let split = content.split(regexp);
				for(let j = 0, k = split.length; j + 1 < k; j++) {
					found.push( split[j].substr(-30) + chalk.underline(word) + split[j+1].substr(0, 30));
				}
			}
		}

		if(found.length) {
			console.warn(chalk.yellow(`Inclusive Language Linter (${inputPath}):`));
			console.warn("    " + found.join("\n" + "    "));
		}
	}
});

Output:
image

@zachleat
Copy link
Member Author

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

No branches or pull requests

1 participant