Skip to content

Commit

Permalink
Add util to list frontmatter from all
Browse files Browse the repository at this point in the history
  • Loading branch information
kategengler committed Nov 15, 2022
1 parent 0df230b commit 4dd16f3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"parserOptions": {
"ecmaVersion": 2020
},
},
"overrides": [
{
"files": "test/**/*.js",
Expand Down
25 changes: 25 additions & 0 deletions list-frontmatter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const argv = require('yargs').command('* [paths..]', 'list frontmatter from files', (yargs) => {
return yargs
.positional('paths', {
describe: 'file paths to list frontmatter from',
type: 'array',
})
.demandOption('paths');
}).argv;

const frontmatter = require('@github-docs/frontmatter');
const { readFileSync } = require('fs');

let results = [];
for (let path of argv.paths) {
let markdown = readFileSync(path, 'utf8');
const { data, errors } = frontmatter(markdown);
if (errors.length) {
console.error(JSON.stringify(errors));
process.exitCode = 1;
return;
}
results.push({ name: path, ...data });
}

console.log(JSON.stringify(results, null, 2));
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
"semver": "^7.3.2",
"simple-git": "^3.12.0",
"yargs": "^16.0.3"
},
"engines": {
"node": ">= 12"
}
}

0 comments on commit 4dd16f3

Please sign in to comment.