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": { "scripts": {
"build": "gatsby build", "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", "ci-check": "npm-run-all prettier:diff --parallel lint flow",
"dev": "gatsby develop -H 0.0.0.0", "dev": "gatsby develop -H 0.0.0.0",
"flow": "flow", "flow": "flow",
"format:source": "prettier --config .prettierrc --write \"{gatsby-*.js,{flow-typed,plugins,src}/**/*.js}\"", "format:source": "prettier --config .prettierrc --write \"{gatsby-*.js,{flow-typed,plugins,src}/**/*.js}\"",
"format:examples": "prettier --config examples/.prettierrc --write \"examples/**/*.js\"", "format:examples": "prettier --config examples/.prettierrc --write \"examples/**/*.js\"",
"generate-ids": "node scripts/generateHeadingIDs.js content",
"lint": "eslint .", "lint": "eslint .",
"netlify": "yarn --version && rimraf node_modules && yarn install --frozen-lockfile --check-files && yarn build", "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}\"", "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) { function addHeaderID(line) {
// check if we're a header at all // 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 // 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 headingText = line.slice(line.indexOf(' ')).trim();
const headingLevel = line.slice(0, line.indexOf(' ')); const headingLevel = line.slice(0, line.indexOf(' '));
return `${headingLevel} ${headingText} {#${generateID(headingText)}}`; return `${headingLevel} ${headingText} {#${generateID(headingText)}}`;
@ -58,7 +62,9 @@ const [path] = process.argv.slice(2);
const files = walk(path); const files = walk(path);
files.forEach(file => { files.forEach(file => {
if (!file.endsWith('.md')) return; if (!file.endsWith('.md')) {
return;
}
const content = fs.readFileSync(file, 'utf8'); const content = fs.readFileSync(file, 'utf8');
const lines = content.split('\n'); const lines = content.split('\n');
Loading…
Cancel
Save