Skip to content

Commit

Permalink
ref: only parse modified file
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverBehave committed May 3, 2020
1 parent a75cd71 commit 5b0d2a3
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 417 deletions.
48 changes: 41 additions & 7 deletions docs/format.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,75 @@
const file = require('./.format/file');
const sgf = require('staged-git-files');
const path = require('path');
const sortByHeading = require('./.format/sortByHeading');
const chineseFormat = require('./.format/chineseFormat');

const processors = [sortByHeading, chineseFormat];

const loopSideBar = (children, type, lang) =>
const loopSideBar = (children, type, lang, prefix) =>
children
.filter((e) => e !== '')
.map((x) => ({
path: path.resolve(__dirname, `./${x}.md`),
path: path.resolve(__dirname, prefix, `./${x}.md`),
type,
lang,
}));

const loopType = (sidebar, lang) => loopSideBar(sidebar[0].children, file.GUIDE_TYPE, lang).concat(loopSideBar(sidebar[1].children, file.ROUTE_TYPE, lang));
const loopType = (sidebar, lang, prefix) => loopSideBar(sidebar[0].children, file.GUIDE_TYPE, lang, prefix).concat(loopSideBar(sidebar[1].children, file.ROUTE_TYPE, lang, prefix));

const buildFileList = () => {
const buildFileList = async () => {
const config = require(`./.vuepress/config`);
let fileList = [];
Object.keys(config.themeConfig.locales).forEach((key) => {
const locale = config.themeConfig.locales[key];
if (locale.hasOwnProperty('sidebar')) {
if (locale.sidebar['/']) {
fileList = fileList.concat(loopType(locale.sidebar['/'], file.LANG_CN));
fileList = fileList.concat(loopType(locale.sidebar['/'], file.LANG_CN, ''));
} else if (locale.sidebar['/en/']) {
fileList = fileList.concat(loopType(locale.sidebar['/en/'], file.LANG_EN));
fileList = fileList.concat(loopType(locale.sidebar['/en/'], file.LANG_EN, 'en/'));
}
}
});

return fileList;
};

const buildStagedList = async () => {
const stagedFiles = await sgf();
const stagedFileList = [];
stagedFiles.forEach((e) => {
if (e.filename.endsWith('.md')) {
stagedFileList.push(e.filename);
}
});
const fullFileList = await buildFileList();
const result = [];
stagedFileList.forEach((e) => {
const f = fullFileList.find((x) => x.path.indexOf(e) !== -1);
if (f) {
result.push(f);
}
});

return result;
};

// Entry
// Usage: node format.js --full/--staged
(async () => {
const fileList = buildFileList();
// Mode
const flag = process.argv[2] || '--full';
let fileList = [];
switch (flag) {
case '--staged':
fileList = await buildStagedList();
break;
case '--full':
default:
fileList = await buildFileList();
}

// Processors
for (const processor of processors) {
// We don't want to mix up processor
/* eslint-disable no-await-in-loop */
Expand Down
6 changes: 3 additions & 3 deletions docs/multimedia.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ pageClass: routes

帖子 id 查找办法:

打开想跟踪的帖子,比如:[http://t66y.com/htm_data/20/1811/3286088.html其中 \`3286088\` 就是帖子 id。](http://t66y.com/htm_data/20/1811/3286088.html。其中`3286088`就是帖子id。)
打开想跟踪的帖子,比如:<http://t66y.com/htm_data/20/1811/3286088.html> 其中 `3286088` 就是帖子 id。

:::

Expand Down Expand Up @@ -441,8 +441,8 @@ pageClass: routes

目前支持泛用型播客订阅的[输出格式](https://docs.rsshub.app/#输出格式)中标明的格式只有 rss 支持, 也就是说你**只能使用**以下类型的链接来订阅播客:

- <https://rsshub.app/ximalaya/album/>\*
- <https://rsshub.app/ximalaya/album/*.rss>
- `https://rsshub.app/ximalaya/album/*`
- `https://rsshub.app/ximalaya/album/*.rss`

:::

Expand Down
2 changes: 1 addition & 1 deletion docs/shopping.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Transform any search into a feed.

<Route author="Platane" example="/leboncoin/ad/category=10&locations=Paris_75015" path="/leboncoin/ad/:query" :paramsDesc="['search page querystring']">

For instance, in <https://www.leboncoin.fr/recherche/?**category=10&locations=Paris_75015>**, the query is **category=10&locations=Paris_75015\*\*
For instance, in <https://www.leboncoin.fr/recherche/?**category=10&locations=Paris_75015>, the query is `category=10&locations=Paris_75015`

</Route>

Expand Down
2 changes: 1 addition & 1 deletion docs/social-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ Tiny Tiny RSS 会给所有 iframe 元素添加 `sandbox="allow-scripts"` 属性

::: tip 提示

官方提供了用户时间线 RSS: https&#x3A;//**:instance**/users/**:username**.atom 或 https&#x3A;//**:instance**/users/**:username**.rss
官方提供了用户时间线 RSS: `https://**:instance**/users/**:username**.atom``https://**:instance**/users/**:username**.rss`

例如:<https://pawoo.net/users/pawoo_support.atom><https://pawoo.net/users/pawoo_support.rss>

Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"docs:dev": "vuepress dev docs",
"docs:build": "vuepress build docs",
"format": "eslint \"**/*.js\" --fix && node docs/format.js && prettier \"**/*.{js,json,md}\" --write",
"format:staged": "eslint \"**/*.js\" --fix && node docs/format.js && pretty-quick --staged --verbose --pattern \"**/*.{js,json,md}\"",
"format:staged": "eslint \"**/*.js\" --fix && node docs/format.js --staged && pretty-quick --staged --verbose --pattern \"**/*.{js,json,md}\"",
"format:check": "eslint \"**/*.js\" && prettier-check \"**/*.{js,json,md}\"",
"test": "npm run format:check && cross-env NODE_ENV=test jest --coverage --runInBand --forceExit",
"jest": "cross-env NODE_ENV=test jest --runInBand --forceExit"
Expand Down Expand Up @@ -57,10 +57,8 @@
"remark": "12.0.0",
"remark-frontmatter": "2.0.0",
"remark-pangu": "1.0.1",
"remark-preset-lint-consistent": "3.0.0",
"remark-preset-lint-recommended": "4.0.0",
"remark-preset-prettier": "0.4.0",
"retext-sentence-spacing": "4.0.0",
"staged-git-files": "1.2.0",
"string-width": "4.2.0",
"supertest": "4.0.2",
"vuepress": "1.4.1",
Expand Down
Loading

0 comments on commit 5b0d2a3

Please sign in to comment.