@@ -27,11 +27,13 @@ export default class ManualDocBuilder extends DocBuilder {
2727 const fileName = 'manual/index.html' ;
2828 const baseUrl = this . _getBaseUrl ( fileName ) ;
2929 this . _buildManualIndex ( manualConfig ) ;
30- ice . load ( 'content' , this . _buildManualIndex ( manualConfig , true ) , IceCap . MODE_WRITE ) ;
30+ ice . load ( 'content' , this . _buildManualCardIndex ( manualConfig ) , IceCap . MODE_WRITE ) ;
3131 ice . load ( 'nav' , this . _buildManualNav ( manualConfig ) , IceCap . MODE_WRITE ) ;
3232 ice . text ( 'title' , 'Manual' , IceCap . MODE_WRITE ) ;
3333 ice . attr ( 'baseUrl' , 'href' , baseUrl , IceCap . MODE_WRITE ) ;
34+ ice . attr ( 'rootContainer' , 'class' , ' manual-index' ) ;
3435 callback ( ice . html , fileName ) ;
36+ ice . attr ( 'rootContainer' , 'class' , ' manual-index' , IceCap . MODE_REMOVE ) ;
3537 }
3638
3739 for ( const item of manualConfig ) {
@@ -144,18 +146,77 @@ export default class ManualDocBuilder extends DocBuilder {
144146 return $root . html ( ) ;
145147 }
146148
149+ /**
150+ * built manual card style index.
151+ * @param {ManualConfigItem[] } manualConfig - target manual config.
152+ * @return {IceCap } built index.
153+ * @private
154+ */
155+ _buildManualCardIndex ( manualConfig ) {
156+ const cards = [ ] ;
157+ for ( const manualItem of manualConfig ) {
158+ if ( manualItem . references ) {
159+ const filePath = path . resolve ( this . _config . destination , 'identifiers.html' ) ;
160+ const html = fs . readFileSync ( filePath ) . toString ( ) ;
161+ const $ = cheerio . load ( html ) ;
162+ const card = $ ( '.content' ) . html ( ) ;
163+ cards . push ( { label : 'References' , link : 'identifiers.html' , card : card } ) ;
164+ continue ;
165+ }
166+
167+ for ( const filePath of manualItem . paths ) {
168+ const fileName = this . _getManualOutputFileName ( manualItem , filePath ) ;
169+ const html = this . _buildManual ( manualItem , filePath ) ;
170+ const $root = cheerio . load ( html ) . root ( ) ;
171+
172+ $root . find ( 'h1' ) . each ( ( i , el ) => {
173+ const $el = cheerio ( el ) ;
174+ const label = $el . text ( ) ;
175+ const link = `${ fileName } #${ $el . attr ( 'id' ) } ` ;
176+ let card = `<h1>${ label } </h1>` ;
177+ const nextAll = $el . nextAll ( ) ;
178+
179+ for ( let i = 0 ; i < nextAll . length ; i ++ ) {
180+ const next = nextAll . get ( i ) ;
181+ const tagName = next . tagName . toLowerCase ( ) ;
182+ if ( tagName === 'h1' ) return ;
183+ const $next = cheerio ( next ) ;
184+ card += `<${ tagName } >${ $next . html ( ) } </${ tagName } >` ;
185+ }
186+
187+ cards . push ( { label, link, card} ) ;
188+ } ) ;
189+ }
190+ }
191+
192+ const ice = new IceCap ( this . _readTemplate ( 'manualCardIndex.html' ) ) ;
193+ ice . loop ( 'cards' , cards , ( i , card , ice ) => {
194+ ice . text ( 'label' , card . label ) ;
195+ ice . attr ( 'link' , 'href' , card . link ) ;
196+ ice . load ( 'card' , card . card ) ;
197+ } ) ;
198+
199+ if ( this . _config . manual . index ) {
200+ const userIndex = this . _convertMDToHTML ( this . _config . manual . index ) ;
201+ ice . load ( 'manualUserIndex' , userIndex ) ;
202+ } else {
203+ ice . drop ( 'manualUserIndex' , true ) ;
204+ }
205+
206+ ice . drop ( 'manualBadge' , ! this . _config . manual . coverage ) ;
207+
208+ return ice ;
209+ }
210+
147211 /**
148212 * built manual index.
149213 * @param {ManualConfigItem[] } manualConfig - target manual config.
150- * @param {boolean } [badge=false] - show badge.
151214 * @return {IceCap } built index.
152215 * @private
153216 */
154- _buildManualIndex ( manualConfig , badge = false ) {
217+ _buildManualIndex ( manualConfig ) {
155218 const ice = new IceCap ( this . _readTemplate ( 'manualIndex.html' ) ) ;
156219
157- if ( ! badge ) ice . drop ( 'badge' ) ;
158-
159220 ice . loop ( 'manual' , manualConfig , ( i , item , ice ) => {
160221 const toc = [ ] ;
161222 if ( item . references ) {
0 commit comments