Browse Source

only update script and stuff

main
Nat Alison 6 years ago
parent
commit
6a50996b7f
  1. 3
      package.json
  2. 12
      scripts/generateHeadingIDs.js

3
package.json

@ -72,12 +72,13 @@
},
"scripts": {
"build": "gatsby build",
"check-all": "npm-run-all prettier --parallel lint flow",
"check-all": "npm-run-all prettier generate-ids --parallel lint flow",
"ci-check": "npm-run-all prettier:diff --parallel lint flow",
"dev": "gatsby develop -H 0.0.0.0",
"flow": "flow",
"format:source": "prettier --config .prettierrc --write \"{gatsby-*.js,{flow-typed,plugins,src}/**/*.js}\"",
"format:examples": "prettier --config examples/.prettierrc --write \"examples/**/*.js\"",
"generate-ids": "node scripts/generateHeadingIDs.js content",
"lint": "eslint .",
"netlify": "yarn --version && rimraf node_modules && yarn install --frozen-lockfile --check-files && yarn build",
"nit:source": "prettier --config .prettierrc --list-different \"{gatsby-*.js,{flow-typed,plugins,src}/**/*.js}\"",

12
scripts/generateHeaderIDs.js → scripts/generateHeadingIDs.js

@ -26,9 +26,13 @@ function generateID(text) {
function addHeaderID(line) {
// check if we're a header at all
if (!line.startsWith('#')) return line;
if (!line.startsWith('#')) {
return line;
}
// check if it already has an id
if (/\{#[-A-Za-z0-9]+\}/.test(line)) return line;
if (/\{#[-A-Za-z0-9]+\}/.test(line)) {
return line;
}
const headingText = line.slice(line.indexOf(' ')).trim();
const headingLevel = line.slice(0, line.indexOf(' '));
return `${headingLevel} ${headingText} {#${generateID(headingText)}}`;
@ -58,7 +62,9 @@ const [path] = process.argv.slice(2);
const files = walk(path);
files.forEach(file => {
if (!file.endsWith('.md')) return;
if (!file.endsWith('.md')) {
return;
}
const content = fs.readFileSync(file, 'utf8');
const lines = content.split('\n');
Loading…
Cancel
Save