Skip to content

Commit e3a972c

Browse files
committed
feat: add alias
1 parent 01b142e commit e3a972c

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 = () =>
@@ -34,6 +64,9 @@ window.$docsify = {
3464
auto2top: true,
3565
subMaxLevel: 2,
3666
alias: {
67+
'^/javascript_solution/(.*)': '/solution/$1',
68+
'^/shell_solution/(.*)': '/solution/$1',
69+
'^/database_solution/(.*)': '/solution/$1',
3770
'/lcs/.*/summary.md': '/lcs/summary.md',
3871
'/lcp/.*/summary.md': '/lcp/summary.md',
3972
'/lcci/.*/summary.md': '/lcci/summary.md',
@@ -128,6 +161,7 @@ window.$docsify = {
128161
const github = `[GitHub](${url})`;
129162
const gitee = `[Gitee](${url.replace('github', 'gitee')})`;
130163
html = cleanedHtml(html);
164+
html = replaceHref(html);
131165
const editHtml = isEn()
132166
? `:memo: Edit on ${github} / ${gitee}\n`
133167
: `:memo: 在 ${github} / ${gitee} 编辑\n`;

0 commit comments

Comments
 (0)