Runs checks against markdown pages with YAML front matter. Useful for validating static sites published with systems like Jekyll or Hugo.
Markdown Page Checker is available on npm. Install it with the following command:
npm install markdown-page-checker
You can also install it globally with:
npm install -g markdown-page-checker
Markdown Page Checker supports use as a CLI or via the API.
First, create a configuration file to configure the checks and their settings, for example:
{
"modeConfig": {
"excludes": ".*(node_modules|README|_includes|_site|).*",
"includes": ".*\\.md"
},
"checks": [
{
"name": "DateRange",
"settings": {
"property": "lastReview",
"beforeOffset": 90,
"afterOffset": 90,
"includes": "[alerts|howto].*"
}
},
{
"name": "Readability",
"settings": {
"errorLimit": 12,
"warnLimit": 9
}
},
{
"name": "RequiredProperties",
"settings": {
"properties": ["title", "maintainer"]
},
},
{
"name": "RequiredProperties",
"settings": {
"properties": ["alertname"]
},
"includes": "alert/.*"
},
{
"name": "Spelling"
},
{
"name": "WriteGood"
}
]
}
Then, run with:
npx markdown-page-checker validate --config [config.json] --path [site-path] --format [output-format]
If you want to add custom checks or incorporate the validator into your code run:
npm install markdown-page-checker
And then you can import it with:
import {Validator} from 'markdown-page-checker'
const validator = new Validator();
const result = await validator.validate("./some/path", {
mode: Mode.Matching,
checks: [
{
name: "WriteGood",
},
{
name: "RequiredProperties",
settings: {
properties: [
"title",
{
property: "layout",
allowedValues: ["default"],
},
],
},
},
],
});
Markdown Page Checker includes the following checks:
Validates that a date field is between an offset range
Settings:
Validates that the body of a page is below a readability target
Validates that required properties (and optional valid values) exist in the YAML frontmatter of a page
Validates the spelling of the words in the body of a page
Validates common writing mistakes, see https://github.com/btford/write-good
You can add custom checks when using Markdown Page Checker via API Usage. To create a custom checker, first implement the Check interface and create your settings interface, for example:
import {Check, CheckResult, MarkdownFile, Status} from 'markdown-page-checker';
interface HappySettings {
happy: boolean
}
class MyHappyCheck implements Check<HappySettings> {
name: 'HappyCheck';
check(markdownFile: MarkdownFile, settings: HappySettings): Promise<CheckResult> {
return {
status: settings.happy ? Status.success : Status.error,
message: `Am I happy? ${settings.happy}`
check: this.name
}
}
}
Then pass the custom check into your validator:
import {Validator} from 'markdown-page-checker'
// from the code snippet above
const customCheck = new HappyCheck();
const validator = new Validator();
validator.addCheck(customCheck);