@@ -2,20 +2,52 @@ const isEn = () => location.hash.includes('README_EN');
22
33const 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
724const cleanedHtml = html => {
825 return html . replace ( / < p r e > ( [ \s \S ] * ?) < \/ p r e > / g, ( _ , group ) => {
926 return '<pre>' + group . replace ( / < c o d e > ( [ \s \S ] * ?) < \/ c o d e > / 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+ 1335const getLang = ( ) => ( isEn ( ) ? 'en' : 'zh-CN' ) ;
1436
1537const 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
2052window . 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