Skip to content

Commit 4acc893

Browse files
qzhou1607-zzalrra
authored andcommitted
Chore: Update update-content.js
Update `update-content.js` to grab and render the docs of the new monorepo architecture of the `sonarwhal` repository. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Close #390
1 parent 706a9c4 commit 4acc893

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const dirs = {
2121
// ---------------------------------------------------------------------
2222

2323
gulp.task('clean:before', (done) => {
24-
shelljs.rm('-rf', dirs.dist, dirs.tmp);
24+
shelljs.rm('-rf', dirs.dist, dirs.tmp, dirs.tmpContent);
2525

2626
done();
2727
});

helpers/update-content.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/* global config cp exec rm */
2-
1+
/* global config cp exec ls mv rm */
32
const shell = require('shelljs/global'); // eslint-disable-line no-unused-vars
43

54
const CLONE_URL = 'https://github.com/sonarwhal/sonarwhal.git'; // eslint-disable-line no-process-env
65
const SOURCE_DIR = 'src/content';
76
const TMP_DIR = require('./mktemp')();
7+
const PACKAGES_TMP_DIR = `${TMP_DIR}/packages`;
88

99
config.fatal = true;
1010

@@ -14,9 +14,18 @@ rm('-rf', `${SOURCE_DIR}/docs/contributor-guide`);
1414
rm('-rf', `${SOURCE_DIR}/docs/user-guide`);
1515
rm('-rf', `${SOURCE_DIR}/about`);
1616

17-
cp('-R', `${TMP_DIR}/docs/contributor-guide`, `${SOURCE_DIR}/docs/contributor-guide`);
18-
cp('-R', `${TMP_DIR}/docs/user-guide`, `${SOURCE_DIR}/docs/user-guide`);
19-
cp('-R', `${TMP_DIR}/docs/about`, `${SOURCE_DIR}`);
20-
cp(`${TMP_DIR}/CHANGELOG.md`, `${SOURCE_DIR}/about`);
17+
cp('-R', `${PACKAGES_TMP_DIR}/sonarwhal/docs/contributor-guide`, `${SOURCE_DIR}/docs/contributor-guide`);
18+
cp('-R', `${PACKAGES_TMP_DIR}/sonarwhal/docs/user-guide`, `${SOURCE_DIR}/docs/user-guide`);
19+
cp('-R', `${PACKAGES_TMP_DIR}/sonarwhal/docs/about`, `${SOURCE_DIR}`);
20+
cp(`${PACKAGES_TMP_DIR}/sonarwhal/CHANGELOG.md`, `${SOURCE_DIR}/about`);
21+
22+
const rules = ls('-R', `${PACKAGES_TMP_DIR}/rule-*/README.md`);
23+
24+
rules.forEach((rulePath) => {
25+
const ruleName = rulePath.split('/').reverse()[1];
26+
const destRulePath = `${SOURCE_DIR}/docs/user-guide/rules/${ruleName}.md`;
27+
28+
mv(rulePath, destRulePath);
29+
});
2130

2231
rm('-rf', TMP_DIR);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"lint:browser": "eslint -c .eslintrc --env browser src/sonarwhal-theme/source/**/*.js",
8080
"lint:js": "npm run lint:node && npm run lint:browser",
8181
"lint:md": "markdownlint README.md ./src/hexo/source",
82-
"lint:node": "eslint -c .eslintrc --env node **/*.js --ignore-pattern src/sonarwhal-theme/source/**/*.js --ignore-pattern dist/**/*.js",
82+
"lint:node": "eslint -c .eslintrc --env node **/*.js --ignore-pattern src/sonarwhal-theme/source/**/*.js --ignore-pattern src/sonarwhal-theme-optimized/**/*.js --ignore-pattern dist/**/*.js",
8383
"lint:styles": "stylelint src/hexo/themes/sonarwhal/source/**/*.css --config .stylelintrc",
8484
"start": "npm run build -- watch",
8585
"watch": "gulp watch",

src/sonarwhal-theme/scripts/link-filter.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ hexo.extend.filter.register('before_post_render', (data) => {
66
// - doesn't start with `http`, `https` or `ftp`
77
// - endes with `.md`
88
const mdUrlRegex = /\((?!(http|https|ftp):)([^(|)]+\.md)[^(|)]*\)/g;
9+
const ruleUrlRegex = /(?:..\/)*(rule-.*)\/README/i;
10+
const isRulePage = data.source.includes('rules');
911
let match;
1012

1113
while ((match = mdUrlRegex.exec(data.content)) !== null) {
@@ -22,6 +24,10 @@ hexo.extend.filter.register('before_post_render', (data) => {
2224
matchHtmlUrl = matchHtmlUrl.replace(/\((.*?)\)/g, '(../$1)');
2325
}
2426

25-
data.content = data.content.replace(matchMdUrl, matchHtmlUrl);
27+
// ../../../../rule-axe/README/ => rule-axe
28+
const matchRuleUrl = matchHtmlUrl.match(ruleUrlRegex);
29+
const newUrl = isRulePage && matchRuleUrl ? `(${matchRuleUrl.pop()})` : matchHtmlUrl;
30+
31+
data.content = data.content.replace(matchMdUrl, newUrl);
2632
}
2733
});

0 commit comments

Comments
 (0)