File tree 5 files changed +34
-7
lines changed
5 files changed +34
-7
lines changed Original file line number Diff line number Diff line change 15
15
<script src =" //unpkg.com/docsify" data-ga =" UA-XXXXX-Y" ></script >
16
16
<script src =" //unpkg.com/docsify/lib/plugins/ga.js" ></script >
17
17
```
18
+
18
19
## 2.1.0
19
20
### Features
20
21
- Add search plugin
Original file line number Diff line number Diff line change 7
7
</ head >
8
8
< body >
9
9
< nav >
10
- < a href ="#/ "> En </ a >
10
+ < a href ="#/ "> en </ a >
11
11
< a href ="#/zh-cn "> 中文</ a >
12
+ < a href ="#/changelog "> Changlog</ a >
12
13
</ nav >
13
14
< div id ="app "> </ div >
14
15
</ body >
15
16
< script >
16
17
window . $docsify = {
18
+ alias : {
19
+ '/changelog' : 'https://raw.githubusercontent.com/QingWei-Li/docsify/master/CHANGELOG'
20
+ } ,
17
21
search : {
18
22
maxAge : 0
19
23
}
Original file line number Diff line number Diff line change 12
12
< nav >
13
13
< a href ="#/ "> En</ a >
14
14
< a href ="#/zh-cn "> 中文</ a >
15
+ < a href ="#/changelog "> Changlog</ a >
15
16
</ nav >
16
17
< div id ="app "> </ div >
17
18
</ body >
19
+ < script >
20
+ window . $docsify = {
21
+ alias : {
22
+ '/changelog' : 'https://raw.githubusercontent.com/QingWei-Li/docsify/master/CHANGELOG'
23
+ }
24
+ }
25
+ </ script >
18
26
< script
19
27
src ="//unpkg.com/docsify/lib/docsify.min.js "
20
28
data-max-level ="4 "
Original file line number Diff line number Diff line change @@ -47,18 +47,24 @@ let cacheRoute = null
47
47
let cacheXhr = null
48
48
49
49
const mainRender = function ( cb ) {
50
- const route = OPTIONS . basePath + utils . getRoute ( )
50
+ let page
51
+ let route = utils . getRoute ( )
51
52
if ( cacheRoute === route ) return cb ( )
52
53
53
- let basePath = cacheRoute = route
54
+ let basePath = cacheRoute = OPTIONS . basePath + route
54
55
55
56
if ( ! / \/ / . test ( basePath ) ) {
56
57
basePath = ''
57
58
} else if ( basePath && ! / \/ $ / . test ( basePath ) ) {
58
59
basePath = basePath . match ( / ( \S * \/ ) [ ^ \/ ] + $ / ) [ 1 ]
59
60
}
60
61
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
+ }
62
68
63
69
if ( ! route ) {
64
70
page = OPTIONS . homepage || 'README.md'
Original file line number Diff line number Diff line change @@ -44,8 +44,7 @@ const getAllPaths = function () {
44
44
/**
45
45
* return file path
46
46
*/
47
- const genFilePath = function ( path ) {
48
- const basePath = window . $docsify . basePath
47
+ const genFilePath = function ( path , basePath = window . $docsify . basePath ) {
49
48
let filePath = / \/ $ / . test ( path ) ? `${ path } README.md` : `${ path } .md`
50
49
51
50
filePath = basePath + filePath
@@ -294,15 +293,24 @@ const searchPlugin = function () {
294
293
const paths = isAuto ? getAllPaths ( ) : CONFIG . paths
295
294
const len = paths . length
296
295
const { load, marked, slugify } = window . Docsify . utils
296
+ const alias = window . $docsify . alias
297
297
const done = ( ) => {
298
298
localStorage . setItem ( 'docsify.search.expires' , Date . now ( ) + CONFIG . maxAge )
299
299
localStorage . setItem ( 'docsify.search.index' , JSON . stringify ( INDEXS ) )
300
300
}
301
301
302
302
paths . forEach ( path => {
303
303
if ( INDEXS [ path ] ) return count ++
304
+ let route
304
305
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 => {
306
314
genIndex ( path , marked ( content ) )
307
315
slugify . clear ( )
308
316
count ++
You can’t perform that action at this time.
0 commit comments