@@ -14,6 +14,11 @@ https://github.com/dtolnay/cxx\
1414</a>\
1515</li>` ;
1616
17+ const htmljs = `\
18+ var html = document.querySelector('html');
19+ html.classList.remove('no-js');
20+ html.classList.add('js');` ;
21+
1722const dirs = [ 'build' ] ;
1823while ( dirs . length ) {
1924 const dir = dirs . pop ( ) ;
@@ -32,7 +37,11 @@ while (dirs.length) {
3237 const index = fs . readFileSync ( path , 'utf8' ) ;
3338 const $ = cheerio . load ( index , { decodeEntities : false } ) ;
3439
40+ $ ( 'script:nth-of-type(3)' ) . text ( htmljs ) ;
3541 $ ( 'nav#sidebar ol.chapter' ) . append ( githublink ) ;
42+ $ ( 'head link[href="tomorrow-night.css"]' ) . attr ( 'disabled' , true ) ;
43+ $ ( 'head link[href="ayu-highlight.css"]' ) . attr ( 'disabled' , true ) ;
44+ $ ( 'button#theme-toggle' ) . attr ( 'style' , 'display:none' ) ;
3645 $ ( 'pre code' ) . each ( function ( ) {
3746 const node = $ ( this ) ;
3847 const langClass = node . attr ( 'class' ) . split ( ' ' , 2 ) [ 0 ] ;
@@ -44,21 +53,29 @@ while (dirs.length) {
4453 const boring = lines . map ( ( line ) =>
4554 line . includes ( '<span class="boring">' )
4655 ) ;
56+ const ellipsis = lines . map ( ( line ) => line . includes ( '// ...' ) ) ;
4757 const target = entities . decode ( node . text ( ) ) ;
4858 const highlighted = hljs . highlight ( lang , target ) . value ;
4959 const result = highlighted
5060 . split ( '\n' )
5161 . map ( function ( line , i ) {
5262 if ( boring [ i ] ) {
5363 line = '<span class="boring">' + line ;
64+ } else if ( ellipsis [ i ] ) {
65+ line = '<span class="ellipsis">' + line ;
5466 }
55- if ( i > 0 && boring [ i - 1 ] ) {
67+ if ( i > 0 && ( boring [ i - 1 ] || ellipsis [ i - 1 ] ) ) {
5668 line = '</span>' + line ;
5769 }
5870 return line ;
5971 } )
6072 . join ( '\n' ) ;
61- node . text ( result ) . removeClass ( langClass ) . addClass ( 'hidelines' ) ;
73+ node . text ( result ) ;
74+ node . removeClass ( langClass ) ;
75+ if ( ! node . hasClass ( 'focuscomment' ) ) {
76+ node . addClass ( 'hidelines' ) ;
77+ node . addClass ( 'hide-boring' ) ;
78+ }
6279 } ) ;
6380 $ ( 'code' ) . each ( function ( ) {
6481 $ ( this ) . addClass ( 'hljs' ) ;
@@ -68,3 +85,10 @@ while (dirs.length) {
6885 fs . writeFileSync ( path , out ) ;
6986 } ) ;
7087}
88+
89+ fs . copyFileSync ( 'build/highlight.css' , 'build/tomorrow-night.css' ) ;
90+ fs . copyFileSync ( 'build/highlight.css' , 'build/ayu-highlight.css' ) ;
91+
92+ var bookjs = fs . readFileSync ( 'build/book.js' , 'utf8' ) ;
93+ bookjs = bookjs . replace ( 'set_theme(theme, false);' , '' ) ;
94+ fs . writeFileSync ( 'build/book.js' , bookjs ) ;
0 commit comments