File tree Expand file tree Collapse file tree 5 files changed +34
-7
lines changed
Expand file tree Collapse file tree 5 files changed +34
-7
lines changed Original file line number Diff line number Diff line change 1515<script src =" //unpkg.com/docsify" data-ga =" UA-XXXXX-Y" ></script >
1616<script src =" //unpkg.com/docsify/lib/plugins/ga.js" ></script >
1717```
18+
1819## 2.1.0
1920### Features
2021- Add search plugin
Original file line number Diff line number Diff line change 77</ head >
88< body >
99 < nav >
10- < a href ="#/ "> En </ a >
10+ < a href ="#/ "> en </ a >
1111 < a href ="#/zh-cn "> 中文</ a >
12+ < a href ="#/changelog "> Changlog</ a >
1213 </ nav >
1314 < div id ="app "> </ div >
1415</ body >
1516< script >
1617 window . $docsify = {
18+ alias : {
19+ '/changelog' : 'https://github.com/QingWei-Li/docsify/master/CHANGELOG'
20+ } ,
1721 search : {
1822 maxAge : 0
1923 }
Original file line number Diff line number Diff line change 1212 < nav >
1313 < a href ="#/ "> En</ a >
1414 < a href ="#/zh-cn "> 中文</ a >
15+ < a href ="#/changelog "> Changlog</ a >
1516 </ nav >
1617 < div id ="app "> </ div >
1718</ body >
19+ < script >
20+ window . $docsify = {
21+ alias : {
22+ '/changelog' : 'https://github.com/QingWei-Li/docsify/master/CHANGELOG'
23+ }
24+ }
25+ </ script >
1826< script
1927 src ="//unpkg.com/docsify/lib/docsify.min.js "
2028 data-max-level ="4 "
Original file line number Diff line number Diff line change @@ -47,18 +47,24 @@ let cacheRoute = null
4747let cacheXhr = null
4848
4949const mainRender = function ( cb ) {
50- const route = OPTIONS . basePath + utils . getRoute ( )
50+ let page
51+ let route = utils . getRoute ( )
5152 if ( cacheRoute === route ) return cb ( )
5253
53- let basePath = cacheRoute = route
54+ let basePath = cacheRoute = OPTIONS . basePath + route
5455
5556 if ( ! / \/ / . test ( basePath ) ) {
5657 basePath = ''
5758 } else if ( basePath && ! / \/ $ / . test ( basePath ) ) {
5859 basePath = basePath . match ( / ( \S * \/ ) [ ^ \/ ] + $ / ) [ 1 ]
5960 }
6061
61- let page
62+ // replace route
63+ if ( OPTIONS . alias && OPTIONS . alias [ '/' + route ] ) {
64+ route = OPTIONS . alias [ '/' + route ]
65+ } else {
66+ route = OPTIONS . basePath + route
67+ }
6268
6369 if ( ! route ) {
6470 page = OPTIONS . homepage || 'README.md'
Original file line number Diff line number Diff line change @@ -44,8 +44,7 @@ const getAllPaths = function () {
4444/**
4545 * return file path
4646 */
47- const genFilePath = function ( path ) {
48- const basePath = window . $docsify . basePath
47+ const genFilePath = function ( path , basePath = window . $docsify . basePath ) {
4948 let filePath = / \/ $ / . test ( path ) ? `${ path } README.md` : `${ path } .md`
5049
5150 filePath = basePath + filePath
@@ -294,15 +293,24 @@ const searchPlugin = function () {
294293 const paths = isAuto ? getAllPaths ( ) : CONFIG . paths
295294 const len = paths . length
296295 const { load, marked, slugify } = window . Docsify . utils
296+ const alias = window . $docsify . alias
297297 const done = ( ) => {
298298 localStorage . setItem ( 'docsify.search.expires' , Date . now ( ) + CONFIG . maxAge )
299299 localStorage . setItem ( 'docsify.search.index' , JSON . stringify ( INDEXS ) )
300300 }
301301
302302 paths . forEach ( path => {
303303 if ( INDEXS [ path ] ) return count ++
304+ let route
304305
305- load ( genFilePath ( path ) ) . then ( content => {
306+ // replace route
307+ if ( alias && alias [ path ] ) {
308+ route = genFilePath ( alias [ path ] || path , '' )
309+ } else {
310+ route = genFilePath ( path )
311+ }
312+
313+ load ( route ) . then ( content => {
306314 genIndex ( path , marked ( content ) )
307315 slugify . clear ( )
308316 count ++
You can’t perform that action at this time.
0 commit comments