@@ -2,14 +2,44 @@ const isEn = () => location.hash.includes('README_EN');
2
2
3
3
const isRoot = ( ) => [ '' , '#/' , '#/README' , '#/README_EN' ] . includes ( location . hash ) ;
4
4
5
- const sidebar = ( ) => ( isRoot ( ) ? false : isEn ( ) ? 'summary_en.md' : 'summary.md' ) ;
5
+ const isJavascript = ( ) => / ^ # \/ j a v a s c r i p t _ s o l u t i o n \/ .* $ / . test ( location . hash ) ;
6
+
7
+ const isDatabase = ( ) => / ^ # \/ d a t a b a s e _ s o l u t i o n \/ .* $ / . test ( location . hash ) ;
8
+
9
+ const isShell = ( ) => / ^ # \/ s h e l l _ s o l u t i o n \/ .* $ / . 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
+ } ;
6
24
7
25
const cleanedHtml = html => {
8
26
return html . replace ( / < p r e > ( [ \s \S ] * ?) < \/ p r e > / g, ( _ , group ) => {
9
27
return '<pre>' + group . replace ( / < c o d e > ( [ \s \S ] * ?) < \/ c o d e > / g, '$1' ) + '</pre>' ;
10
28
} ) ;
11
29
} ;
12
30
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 ( / \/ s o l u t i o n \/ / g, `/${ res } /` ) : html ;
41
+ } ;
42
+
13
43
const getLang = ( ) => ( isEn ( ) ? 'en' : 'zh-CN' ) ;
14
44
15
45
const giscusTheme = ( ) =>
@@ -34,6 +64,9 @@ window.$docsify = {
34
64
auto2top : true ,
35
65
subMaxLevel : 2 ,
36
66
alias : {
67
+ '^/javascript_solution/(.*)' : '/solution/$1' ,
68
+ '^/shell_solution/(.*)' : '/solution/$1' ,
69
+ '^/database_solution/(.*)' : '/solution/$1' ,
37
70
'/lcs/.*/summary.md' : '/lcs/summary.md' ,
38
71
'/lcp/.*/summary.md' : '/lcp/summary.md' ,
39
72
'/lcci/.*/summary.md' : '/lcci/summary.md' ,
@@ -128,6 +161,7 @@ window.$docsify = {
128
161
const github = `[GitHub](${ url } )` ;
129
162
const gitee = `[Gitee](${ url . replace ( 'github' , 'gitee' ) } )` ;
130
163
html = cleanedHtml ( html ) ;
164
+ html = replaceHref ( html ) ;
131
165
const editHtml = isEn ( )
132
166
? `:memo: Edit on ${ github } / ${ gitee } \n`
133
167
: `:memo: 在 ${ github } / ${ gitee } 编辑\n` ;
0 commit comments