A GitHub Action that lints the frontmatter of markdown files. Write your own rules in js
or just stick with the defaults for a quick and easy solution.
- Install packages
yarn install
- Build with ncc
yarn build
Currently, as this is built using TS we need to run yarn build
before pushing.
To use this GitHub action, you'll need to create a .flinter/config.json
file. See the below table for information. (Scroll a bit further for an example config.json
)
Put these fields inside a defaults
section
Field | Type | Required | Information |
---|---|---|---|
markdownFileExtensions |
Array | ✅ | A list of markdown file extensions to lint against |
frontmatter |
Array | ✅ | A list of all fields to lint. If you add directories these fields won't be checked. See below for more information on the frontmatter object. |
directories |
Array | ❌ | If you have a specific directories where you only want to lint against those specific markdown files. |
Field | Type | Required | Information |
---|---|---|---|
field |
String | ✅ | The name of the frontmatter field to lint |
required |
Boolean | ❌ | If true, will return an error if the value is null |
type |
String | ❌ | TODO: Implement basic type checking |
rule |
String | ❌ | name of the custom rule to run. e.g. "custom.js" |
To write custom rules.
- Create a new folder
./flinter/linters/
- Create a
.js
file and export an async function calledrun
. See the template below. - Return a FlinterResult [Boolean,String]
- Add the file name to the Frontmatter field's
rule
.
// This must return a boolean value.
/**
* @param {{field: string, value?: string}} params
* @returns {{result: boolean, error?: string}}
*/
export async function run(params) {
return {
result: true,
};
}
{
"defaults": {
"markdownFileExtensions": ["md", "mdx"],
"frontmatter": [
{
"field": "title",
"type": "text",
"required": true
}
]
},
"rules": {
"frontmatter": [
{
"field": "title",
"type": "text",
"required": true,
"rule": "title.js"
},
{
"field": "authors",
"type": "object",
"rule": "authors.js"
}
]
}
}
Note
To enable debug logging, setDEBUG
totrue
where the Flinter action is used
e.g.steps: - name: Flinter.md uses: JackDevAU/[email protected] with: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} DEBUG: true
This builds on from the awesome work over @ lint-md-fm.