Skip to content

Commit d117485

Browse files
yanglbmethinkasany
andauthored
feat: generate sub category summary (#1699)
--------- Co-authored-by: thinkasany <480968828@qq.com>
1 parent b129642 commit d117485

22 files changed

+1461
-15
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
- [剑指 Offer(专项突击版)](/lcof2/README.md)
3232
- [程序员面试金典(第 6 版)](/lcci/README.md)
3333

34+
## 专项突破
35+
36+
- [JavaScript 专项练习](/solution/JAVASCRIPT_README.md)
37+
- [数据库专项练习](/solution/DATABASE_README.md)
38+
3439
## 算法提升专题
3540

3641
### 1. 基础算法

README_EN.md

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ The repository is maintained by the Doocs community, and please give us a [star]
3232
- [LCOF: Coding Interviews, 2nd Edition](/lcof/README_EN.md)
3333
- [LCCI: Cracking the Coding Interview, 6th Edition](/lcci/README_EN.md)
3434

35+
## JavaScript & Database Practice
36+
37+
- [JavaScript Practice](/solution/JAVASCRIPT_README_EN.md)
38+
- [Database Practice](/solution/DATABASE_README_EN.md)
39+
3540
## Topics
3641

3742
### 1. Basic Algorithms

lcci/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
列表所有题解均由 [开源社区 Doocs](https://github.com/doocs) 贡献者提供,正在完善中,欢迎贡献你的题解!
1010

11-
快速搜索题号、题解、标签等,请善用 <kbd>Control</kbd>+<kbd>F</kbd>(或者 <kbd>Command</kbd>+<kbd>F</kbd>)。
11+
快速搜索题号、题解、标签等,请善用 <kbd>Control</kbd> + <kbd>F</kbd>(或者 <kbd>Command</kbd> + <kbd>F</kbd>)。
1212

1313
| 题号 | 题解 | 标签 | 难度 |
1414
| --------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | --------------------------------------------- | ---- |

lcci/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ _Cracking the Coding Interview, 6th Edition_ is here to help you through this pr
66

77
## Solutions
88

9-
Press <kbd>Control</kbd>+<kbd>F</kbd>(or <kbd>Command</kbd>+<kbd>F</kbd> on the Mac) to search anything you want.
9+
Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on the Mac) to search anything you want.
1010

1111
| # | Solution | Tag | Difficulty |
1212
| --------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------ | ---------- |

lcof/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
列表所有题解均由 [开源社区 Doocs](https://github.com/doocs) 贡献者提供,正在完善中,欢迎贡献你的题解!
1212

13-
快速搜索题号、题解、标签等,请善用 <kbd>Control</kbd>+<kbd>F</kbd>(或者 <kbd>Command</kbd>+<kbd>F</kbd>)。
13+
快速搜索题号、题解、标签等,请善用 <kbd>Control</kbd> + <kbd>F</kbd>(或者 <kbd>Command</kbd> + <kbd>F</kbd>)。
1414

1515
| 题号 | 题解 | 标签 | 难度 |
1616
| ---------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ---- |

lcof/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Readers will improve their interview performance after reading this book. It wil
1212

1313
English Solutions is not available for the book. Please switch to Chinese version.
1414

15-
Press <kbd>Control</kbd>+<kbd>F</kbd>(or <kbd>Command</kbd>+<kbd>F</kbd> on the Mac) to search anything you want.
15+
Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on the Mac) to search anything you want.
1616

1717
## Copyright
1818

lcof2/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
列表所有题解均由 [开源社区 Doocs](https://github.com/doocs) 贡献者提供,正在完善中,欢迎贡献你的题解!
1010

11-
快速搜索题号、题解、标签等,请善用 <kbd>Control</kbd>+<kbd>F</kbd>(或者 <kbd>Command</kbd>+<kbd>F</kbd>)。
11+
快速搜索题号、题解、标签等,请善用 <kbd>Control</kbd> + <kbd>F</kbd>(或者 <kbd>Command</kbd> + <kbd>F</kbd>)。
1212

1313
| 题号 | 题解 | 标签 | 难度 | 备注 |
1414
| ------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- | ---- | ---- |

lcp/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
列表所有题解均由 [开源社区 Doocs](https://github.com/doocs) 贡献者提供,正在完善中,欢迎贡献你的题解!
66

7-
快速搜索题号、题解、标签等,请善用 <kbd>Control</kbd>+<kbd>F</kbd>(或者 <kbd>Command</kbd>+<kbd>F</kbd>)。
7+
快速搜索题号、题解、标签等,请善用 <kbd>Control</kbd> + <kbd>F</kbd>(或者 <kbd>Command</kbd> + <kbd>F</kbd>)。
88

99
| 题号 | 题解 | 标签 | 难度 |
1010
| -------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------- | ---- |

lcs/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
列表所有题解均由 [开源社区 Doocs](https://github.com/doocs) 贡献者提供,正在完善中,欢迎贡献你的题解!
66

7-
快速搜索题号、题解、标签等,请善用 <kbd>Control</kbd>+<kbd>F</kbd>(或者 <kbd>Command</kbd>+<kbd>F</kbd>)。
7+
快速搜索题号、题解、标签等,请善用 <kbd>Control</kbd> + <kbd>F</kbd>(或者 <kbd>Command</kbd> + <kbd>F</kbd>)。
88

99
| 题号 | 题解 | 标签 | 难度 | 备注 |
1010
| ---------------------------------------------- | -------------------------------------------------------------------------------------------------- | ---------------------------------------------------- | ---- | ---- |

main.js

+38-2
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,52 @@ const isEn = () => location.hash.includes('README_EN');
22

33
const isRoot = () => ['', '#/', '#/README', '#/README_EN'].includes(location.hash);
44

5-
const sidebar = () => (isRoot() ? false : isEn() ? 'summary_en.md' : 'summary.md');
5+
const categories = ['javascript', 'database'];
6+
7+
const getSolutionPrefix = url => {
8+
const res = categories.find(
9+
category =>
10+
url.includes(category + '-solution') ||
11+
url.includes(category.toUpperCase() + '_README'),
12+
);
13+
return res ? res + '-' : '';
14+
};
15+
16+
const sidebar = () => {
17+
if (isRoot()) {
18+
return false;
19+
}
20+
const prefix = getSolutionPrefix(location.hash);
21+
return isEn() ? `${prefix}summary_en.md` : `${prefix}summary.md`;
22+
};
623

724
const cleanedHtml = html => {
825
return html.replace(/<pre>([\s\S]*?)<\/pre>/g, (_, group) => {
926
return '<pre>' + group.replace(/<code>([\s\S]*?)<\/code>/g, '$1') + '</pre>';
1027
});
1128
};
1229

30+
const replaceHref = html => {
31+
const prefix = getSolutionPrefix(location.hash);
32+
return prefix ? html.replaceAll('(/solution/', '(/' + prefix + 'solution/') : html;
33+
};
34+
1335
const getLang = () => (isEn() ? 'en' : 'zh-CN');
1436

1537
const giscusTheme = () =>
1638
localStorage.getItem('DARK_LIGHT_THEME') === 'light' ? 'light' : 'noborder_dark';
1739

18-
const getTerm = () => decodeURI(location.hash.slice(1, location.hash.lastIndexOf('/')) || '/index');
40+
const getTerm = () => {
41+
let path = decodeURI(location.hash.slice(1, location.hash.lastIndexOf('/'))) || '/index';
42+
// restore original path
43+
for (const prefix of categories) {
44+
const s = `${prefix}-solution`;
45+
if (path.includes(s)) {
46+
path = path.replace(s, 'solution');
47+
}
48+
}
49+
return path;
50+
};
1951

2052
window.addEventListener('hashchange', () => {
2153
window.$docsify.loadSidebar = sidebar();
@@ -34,6 +66,9 @@ window.$docsify = {
3466
auto2top: true,
3567
subMaxLevel: 2,
3668
alias: {
69+
'^/javascript-solution/(.*)': '/solution/$1',
70+
'^/shell-solution/(.*)': '/solution/$1',
71+
'^/database-solution/(.*)': '/solution/$1',
3772
'/lcs/.*/summary.md': '/lcs/summary.md',
3873
'/lcp/.*/summary.md': '/lcp/summary.md',
3974
'/lcci/.*/summary.md': '/lcci/summary.md',
@@ -128,6 +163,7 @@ window.$docsify = {
128163
const github = `[GitHub](${url})`;
129164
const gitee = `[Gitee](${url.replace('github', 'gitee')})`;
130165
html = cleanedHtml(html);
166+
html = replaceHref(html);
131167
const editHtml = isEn()
132168
? `:memo: Edit on ${github} / ${gitee}\n`
133169
: `:memo: 在 ${github} / ${gitee} 编辑\n`;

0 commit comments

Comments
 (0)