@@ -2447,8 +2447,8 @@ function corner (data) {
2447
2447
/**
2448
2448
* Render main content
2449
2449
*/
2450
- function main ( tpl ) {
2451
- var aside = tpl + "<aside class=\"sidebar\"></aside>" ;
2450
+ function main ( ) {
2451
+ var aside = ( toggle ( ) ) + "<aside class=\"sidebar\"></aside>" ;
2452
2452
2453
2453
return ( isMobile ( ) ? ( aside + "<main>" ) : ( "<main>" + aside ) ) +
2454
2454
"<section class=\"content\">\n <article class=\"markdown-section\"></article>\n </section>\n </main>"
@@ -2493,7 +2493,34 @@ function helper (className, content) {
2493
2493
return ( "<p class=\"" + className + "\">" + ( content . slice ( 5 ) . trim ( ) ) + "</p>" )
2494
2494
}
2495
2495
2496
- var OPTIONS$1 = { } ;
2496
+ function theme ( color ) {
2497
+ return ( "<style>:root{--theme-color: " + color + ";}</style>" )
2498
+ }
2499
+
2500
+ function replaceVar ( block ) {
2501
+ block . innerHTML = block . innerHTML . replace ( / v a r \( \s * - - t h e m e - c o l o r .* ?\) / g, __docsify__ . themeColor ) ;
2502
+ }
2503
+
2504
+ function cssVars ( ) {
2505
+ // variable support
2506
+ if ( window . CSS && window . CSS . supports && window . CSS . supports ( '(--foo: red)' ) ) { return }
2507
+
2508
+ var styleBlocks = document . querySelectorAll ( 'style:not(.inserted),link' ) ; [ ] . forEach . call ( styleBlocks , function ( block ) {
2509
+ if ( block . nodeName === 'STYLE' ) {
2510
+ replaceVar ( block ) ;
2511
+ } else if ( block . nodeName === 'LINK' ) {
2512
+ load ( block . getAttribute ( 'href' ) )
2513
+ . then ( function ( res ) {
2514
+ var style = document . createElement ( 'style' ) ;
2515
+
2516
+ style . innerHTML = res ;
2517
+ document . head . appendChild ( style ) ;
2518
+ replaceVar ( style ) ;
2519
+ } ) ;
2520
+ }
2521
+ } ) ;
2522
+ }
2523
+
2497
2524
var markdown = marked ;
2498
2525
var toc = [ ] ;
2499
2526
var CACHE = { } ;
@@ -2508,11 +2535,8 @@ var renderTo = function (dom, content) {
2508
2535
2509
2536
/**
2510
2537
* init render
2511
- * @param {Object } options
2512
2538
*/
2513
- function init ( options ) {
2514
- OPTIONS$1 = options ;
2515
-
2539
+ function init ( ) {
2516
2540
var renderer = new marked . Renderer ( ) ;
2517
2541
/**
2518
2542
* render anchor tag
@@ -2522,10 +2546,7 @@ function init (options) {
2522
2546
var slug = slugify ( text ) ;
2523
2547
var route = '' ;
2524
2548
2525
- if ( OPTIONS$1 . router ) {
2526
- route = "#/" + ( getRoute ( ) ) ;
2527
- }
2528
-
2549
+ route = "#/" + ( getRoute ( ) ) ;
2529
2550
toc . push ( { level : level , slug : ( route + "#" + ( encodeURIComponent ( slug ) ) ) , title : text } ) ;
2530
2551
2531
2552
return ( "<h" + level + " id=\"" + slug + "\"><a href=\"" + route + "#" + slug + "\" data-id=\"" + slug + "\" class=\"anchor\"><span>" + text + "</span></a></h" + level + ">" )
@@ -2539,7 +2560,7 @@ function init (options) {
2539
2560
return ( "<pre v-pre data-lang=\"" + lang + "\"><code class=\"lang-" + lang + "\">" + ( hl . replace ( / : / g, '__colon__' ) ) + "</code></pre>" )
2540
2561
} ;
2541
2562
renderer . link = function ( href , title , text ) {
2542
- if ( OPTIONS$1 . router && ! / : / . test ( href ) ) {
2563
+ if ( ! / : / . test ( href ) ) {
2543
2564
href = ( "#/" + href ) . replace ( / \/ \/ / g, '/' ) ;
2544
2565
}
2545
2566
@@ -2554,11 +2575,11 @@ function init (options) {
2554
2575
return ( "<p>" + text + "</p>" )
2555
2576
} ;
2556
2577
2557
- if ( typeof OPTIONS$1 . markdown === 'function' ) {
2578
+ if ( typeof __docsify__ . markdown === 'function' ) {
2558
2579
markdown . setOptions ( { renderer : renderer } ) ;
2559
- markdown = OPTIONS$1 . markdown . call ( this , markdown ) ;
2580
+ markdown = __docsify__ . markdown . call ( this , markdown ) ;
2560
2581
} else {
2561
- markdown . setOptions ( merge ( { renderer : renderer } , OPTIONS$1 . markdown ) ) ;
2582
+ markdown . setOptions ( merge ( { renderer : renderer } , __docsify__ . markdown ) ) ;
2562
2583
}
2563
2584
2564
2585
var md = markdown ;
@@ -2572,17 +2593,23 @@ function init (options) {
2572
2593
function renderApp ( dom , replace ) {
2573
2594
var nav = document . querySelector ( 'nav' ) || document . createElement ( 'nav' ) ;
2574
2595
2575
- if ( ! OPTIONS$1 . repo ) { nav . classList . add ( 'no-badge' ) ; }
2596
+ if ( ! __docsify__ . repo ) { nav . classList . add ( 'no-badge' ) ; }
2576
2597
2577
- dom [ replace ? 'outerHTML' : 'innerHTML' ] = corner ( OPTIONS$1 . repo ) +
2578
- ( OPTIONS$1 . coverpage ? cover ( ) : '' ) +
2579
- main ( OPTIONS$1 . sidebarToggle ? toggle ( ) : '' ) ;
2598
+ dom [ replace ? 'outerHTML' : 'innerHTML' ] = corner ( __docsify__ . repo ) +
2599
+ ( __docsify__ . coverpage ? cover ( ) : '' ) +
2600
+ main ( ) ;
2580
2601
document . body . insertBefore ( nav , document . body . children [ 0 ] ) ;
2581
2602
2603
+ // theme color
2604
+ if ( __docsify__ . themeColor ) {
2605
+ document . head . innerHTML += theme ( __docsify__ . themeColor ) ;
2606
+ cssVars ( ) ;
2607
+ }
2608
+
2582
2609
// bind toggle
2583
2610
bindToggle ( 'button.sidebar-toggle' ) ;
2584
2611
// bind sticky effect
2585
- if ( OPTIONS$1 . coverpage ) {
2612
+ if ( __docsify__ . coverpage ) {
2586
2613
! isMobile ( ) && window . addEventListener ( 'scroll' , sticky ) ;
2587
2614
} else {
2588
2615
document . body . classList . add ( 'sticky' ) ;
@@ -2594,7 +2621,7 @@ function renderApp (dom, replace) {
2594
2621
*/
2595
2622
function renderArticle ( content ) {
2596
2623
renderTo ( 'article' , content ? markdown ( content ) : 'not found' ) ;
2597
- if ( ! OPTIONS$1 . sidebar && ! OPTIONS$1 . loadSidebar ) { renderSidebar ( ) ; }
2624
+ if ( ! __docsify__ . loadSidebar ) { renderSidebar ( ) ; }
2598
2625
2599
2626
if ( content && typeof Vue !== 'undefined' ) {
2600
2627
CACHE . vm && CACHE . vm . $destroy ( ) ;
@@ -2611,7 +2638,7 @@ function renderArticle (content) {
2611
2638
: new Vue ( { el : 'main' } ) ; // eslint-disable-line
2612
2639
CACHE . vm && CACHE . vm . $nextTick ( function ( _ ) { return scrollActiveSidebar ( ) ; } ) ;
2613
2640
}
2614
- if ( OPTIONS$1 . auto2top ) { setTimeout ( function ( ) { return scroll2Top ( OPTIONS$1 . auto2top ) ; } , 0 ) ; }
2641
+ if ( __docsify__ . auto2top ) { setTimeout ( function ( ) { return scroll2Top ( __docsify__ . auto2top ) ; } , 0 ) ; }
2615
2642
}
2616
2643
2617
2644
/**
@@ -2635,13 +2662,11 @@ function renderSidebar (content) {
2635
2662
html = markdown ( content ) ;
2636
2663
// find url tag
2637
2664
html = html . match ( / < u l [ ^ > ] * > ( [ \s \S ] + ) < \/ u l > / g) [ 0 ] ;
2638
- } else if ( OPTIONS$1 . sidebar ) {
2639
- html = tree ( OPTIONS$1 . sidebar , '<ul>' ) ;
2640
2665
} else {
2641
- html = tree ( genTree ( toc , OPTIONS$1 . maxLevel ) , '<ul>' ) ;
2666
+ html = tree ( genTree ( toc , __docsify__ . maxLevel ) , '<ul>' ) ;
2642
2667
}
2643
2668
2644
- html = ( OPTIONS$1 . name ? ( "<h1><a href=\"" + ( OPTIONS$1 . nameLink ) + "\">" + ( OPTIONS$1 . name ) + "</a></h1>" ) : '' ) + html ;
2669
+ html = ( __docsify__ . name ? ( "<h1><a href=\"" + ( __docsify__ . nameLink ) + "\">" + ( __docsify__ . name ) + "</a></h1>" ) : '' ) + html ;
2645
2670
renderTo ( 'aside.sidebar' , html ) ;
2646
2671
var target = activeLink ( 'aside.sidebar' , true ) ;
2647
2672
if ( target ) { renderSubSidebar ( target ) ; }
@@ -2651,8 +2676,8 @@ function renderSidebar (content) {
2651
2676
}
2652
2677
2653
2678
function renderSubSidebar ( target ) {
2654
- if ( ! OPTIONS$1 . subMaxLevel ) { return }
2655
- target . parentNode . innerHTML += tree ( genTree ( toc , OPTIONS$1 . subMaxLevel ) , '<ul>' ) ;
2679
+ if ( ! __docsify__ . subMaxLevel ) { return }
2680
+ target . parentNode . innerHTML += tree ( genTree ( toc , __docsify__ . subMaxLevel ) , '<ul>' ) ;
2656
2681
}
2657
2682
2658
2683
/**
@@ -2735,16 +2760,14 @@ var OPTIONS = merge({
2735
2760
repo : '' ,
2736
2761
maxLevel : 6 ,
2737
2762
subMaxLevel : 0 ,
2738
- sidebar : '' ,
2739
- sidebarToggle : false ,
2740
2763
loadSidebar : null ,
2741
2764
loadNavbar : null ,
2742
- router : false ,
2743
2765
homepage : 'README.md' ,
2744
2766
coverpage : '' ,
2745
2767
basePath : '' ,
2746
2768
auto2top : false ,
2747
2769
name : '' ,
2770
+ themeColor : '' ,
2748
2771
nameLink : window . location . pathname
2749
2772
} , window . $docsify ) ;
2750
2773
var script = document . currentScript || [ ] . slice . call ( document . getElementsByTagName ( 'script' ) ) . pop ( ) ;
@@ -2760,9 +2783,11 @@ if (script) {
2760
2783
if ( OPTIONS . coverpage === true ) { OPTIONS . coverpage = '_coverpage.md' ; }
2761
2784
if ( OPTIONS . repo === true ) { OPTIONS . repo = '' ; }
2762
2785
if ( OPTIONS . name === true ) { OPTIONS . name = '' ; }
2763
- if ( OPTIONS . sidebar ) { OPTIONS . sidebar = window [ OPTIONS . sidebar ] ; }
2764
2786
}
2765
2787
2788
+ // utils
2789
+ window . __docsify__ = OPTIONS ;
2790
+
2766
2791
// load options
2767
2792
init ( OPTIONS ) ;
2768
2793
@@ -2833,10 +2858,8 @@ var Docsify = function () {
2833
2858
// Render app
2834
2859
renderApp ( dom , replace ) ;
2835
2860
main ( ) ;
2836
- if ( OPTIONS . router ) {
2837
- if ( ! / ^ # \/ / . test ( window . location . hash ) ) { window . location . hash = '#/' ; }
2838
- window . addEventListener ( 'hashchange' , main ) ;
2839
- }
2861
+ if ( ! / ^ # \/ / . test ( window . location . hash ) ) { window . location . hash = '#/' ; }
2862
+ window . addEventListener ( 'hashchange' , main ) ;
2840
2863
} ;
2841
2864
2842
2865
var index = Docsify ( ) ;
0 commit comments