Skip to content

Commit 6a50996

Browse files
committed
only update script and stuff
1 parent 0a45ebf commit 6a50996

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,13 @@
7272
},
7373
"scripts": {
7474
"build": "gatsby build",
75-
"check-all": "npm-run-all prettier --parallel lint flow",
75+
"check-all": "npm-run-all prettier generate-ids --parallel lint flow",
7676
"ci-check": "npm-run-all prettier:diff --parallel lint flow",
7777
"dev": "gatsby develop -H 0.0.0.0",
7878
"flow": "flow",
7979
"format:source": "prettier --config .prettierrc --write \"{gatsby-*.js,{flow-typed,plugins,src}/**/*.js}\"",
8080
"format:examples": "prettier --config examples/.prettierrc --write \"examples/**/*.js\"",
81+
"generate-ids": "node scripts/generateHeadingIDs.js content",
8182
"lint": "eslint .",
8283
"netlify": "yarn --version && rimraf node_modules && yarn install --frozen-lockfile --check-files && yarn build",
8384
"nit:source": "prettier --config .prettierrc --list-different \"{gatsby-*.js,{flow-typed,plugins,src}/**/*.js}\"",

scripts/generateHeaderIDs.js renamed to scripts/generateHeadingIDs.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@ function generateID(text) {
2626

2727
function addHeaderID(line) {
2828
// check if we're a header at all
29-
if (!line.startsWith('#')) return line;
29+
if (!line.startsWith('#')) {
30+
return line;
31+
}
3032
// check if it already has an id
31-
if (/\{#[-A-Za-z0-9]+\}/.test(line)) return line;
33+
if (/\{#[-A-Za-z0-9]+\}/.test(line)) {
34+
return line;
35+
}
3236
const headingText = line.slice(line.indexOf(' ')).trim();
3337
const headingLevel = line.slice(0, line.indexOf(' '));
3438
return `${headingLevel} ${headingText} {#${generateID(headingText)}}`;
@@ -58,7 +62,9 @@ const [path] = process.argv.slice(2);
5862

5963
const files = walk(path);
6064
files.forEach(file => {
61-
if (!file.endsWith('.md')) return;
65+
if (!file.endsWith('.md')) {
66+
return;
67+
}
6268

6369
const content = fs.readFileSync(file, 'utf8');
6470
const lines = content.split('\n');

0 commit comments

Comments
 (0)