@@ -9,6 +9,7 @@ import stylesheet from './stylesheet.css'
99const DEFAULT_OPTIONS = {
1010 previousText : 'PREVIOUS' ,
1111 nextText : 'NEXT' ,
12+ crossChapter : false ,
1213}
1314const CONTAINER_CLASSNAME = 'docsify-pagination-container'
1415
@@ -18,8 +19,8 @@ const CONTAINER_CLASSNAME = 'docsify-pagination-container'
1819function toArray ( elements ) {
1920 return Array . prototype . slice . call ( elements )
2021}
21- function findHyperlink ( li ) {
22- return query ( 'a' , li )
22+ function findHyperlink ( element ) {
23+ return element . href ? element : query ( 'a' , element )
2324}
2425function isALinkTo ( path , element ) {
2526 if ( arguments . length === 1 ) {
@@ -50,20 +51,25 @@ class Link {
5051 }
5152}
5253
53- function pagination ( vm ) {
54+ function pagination ( vm , crossChapter ) {
5455 try {
5556 const path = vm . route . path
5657 const all = toArray ( query . all ( '.sidebar li a' ) ) . filter ( ( element ) => ! matches ( element , '.section-link' ) )
5758 const active = all . find ( isALinkTo ( path ) )
5859 const group = toArray ( ( closest ( active , 'ul' ) || { } ) . children )
5960 . filter ( ( element ) => element . tagName . toUpperCase ( ) === 'LI' )
60- const index = group . findIndex ( ( item ) => {
61- const hyperlink = findHyperlink ( item )
62- return hyperlink && isALinkTo ( path , hyperlink )
63- } )
61+ const index = crossChapter
62+ ? all . findIndex ( isALinkTo ( path ) )
63+ : group . findIndex ( ( item ) => {
64+ const hyperlink = findHyperlink ( item )
65+ return hyperlink && isALinkTo ( path , hyperlink )
66+ } )
67+
68+ const links = crossChapter ? all : group
69+
6470 return {
65- prev : new Link ( group [ index - 1 ] ) . toJSON ( ) ,
66- next : new Link ( group [ index + 1 ] ) . toJSON ( ) ,
71+ prev : new Link ( links [ index - 1 ] ) . toJSON ( ) ,
72+ next : new Link ( links [ index + 1 ] ) . toJSON ( ) ,
6773 }
6874 } catch ( error ) {
6975 return { }
@@ -118,7 +124,7 @@ export function install (hook, vm) {
118124 if ( ! container ) {
119125 return
120126 }
121- container . innerHTML = template . inner ( pagination ( vm ) , options )
127+ container . innerHTML = template . inner ( pagination ( vm , options . crossChapter ) , options )
122128 }
123129
124130 hook . afterEach ( ( html ) => html + template . container ( ) )
0 commit comments