Skip to content

Commit 5cb59de

Browse files
committed
feat: add alias
1 parent 527b641 commit 5cb59de

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

main.js

+35-1
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,44 @@ 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 isJavascript = () => /^#\/javascript_solution\/.*$/.test(location.hash);
6+
7+
const isDatabase = () => /^#\/database_solution\/.*$/.test(location.hash);
8+
9+
const isShell = () => /^#\/shell_solution\/.*$/.test(location.hash);
10+
11+
const sidebar = () => {
12+
if (isRoot()) {
13+
return false;
14+
}
15+
if (isJavascript()) {
16+
return isEn() ? 'javascript_summary_en.md' : 'javascript_summary.md';
17+
} else if (isDatabase()) {
18+
return isEn() ? 'javascript_summary_en.md' : 'javascript_summary.md';
19+
} else if (isShell()) {
20+
return isEn() ? 'javascript_summary_en.md' : 'javascript_summary.md';
21+
}
22+
return isEn() ? 'summary_en.md' : 'summary.md';
23+
};
624

725
const cleanedHtml = html => {
826
return html.replace(/<pre>([\s\S]*?)<\/pre>/g, (_, group) => {
927
return '<pre>' + group.replace(/<code>([\s\S]*?)<\/code>/g, '$1') + '</pre>';
1028
});
1129
};
1230

31+
const replaceHref = html => {
32+
let res;
33+
if (isJavascript()) {
34+
res = 'javascript_solution';
35+
} else if (isDatabase()) {
36+
res = 'database_solution';
37+
} else if (isShell()) {
38+
res = 'shell_solution';
39+
}
40+
return res ? html.replace(/\/solution\//g, `/${res}/`) : html;
41+
};
42+
1343
const getLang = () => (isEn() ? 'en' : 'zh-CN');
1444

1545
const giscusTheme = () =>
@@ -54,6 +84,9 @@ window.$docsify = {
5484
auto2top: true,
5585
subMaxLevel: 2,
5686
alias: {
87+
'^/javascript_solution/(.*)': '/solution/$1',
88+
'^/shell_solution/(.*)': '/solution/$1',
89+
'^/database_solution/(.*)': '/solution/$1',
5790
'/lcs/.*/summary.md': '/lcs/summary.md',
5891
'/lcp/.*/summary.md': '/lcp/summary.md',
5992
'/lcci/.*/summary.md': '/lcci/summary.md',
@@ -132,6 +165,7 @@ window.$docsify = {
132165
const github = `[GitHub](${url})`;
133166
const gitee = `[Gitee](${url.replace('github', 'gitee')})`;
134167
html = cleanedHtml(html);
168+
html = replaceHref(html);
135169
const editHtml = isEn()
136170
? `:memo: Edit on ${github} / ${gitee}\n`
137171
: `:memo: 在 ${github} / ${gitee} 编辑\n`;

0 commit comments

Comments
 (0)