|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +// Build all.html by combining the generated toc and apicontent from each |
| 4 | +// of the generated html files. |
| 5 | + |
| 6 | +constfs=require('fs'); |
| 7 | + |
| 8 | +constsource=`${__dirname}/../../out/doc/api`; |
| 9 | + |
| 10 | +// Get a list of generated API documents. |
| 11 | +consthtmlFiles=fs.readdirSync(source,'utf8') |
| 12 | +.filter((name)=>name.includes('.html')&&name!=='all.html'); |
| 13 | + |
| 14 | +// Read the table of contents. |
| 15 | +consttoc=fs.readFileSync(source+'/_toc.html','utf8'); |
| 16 | + |
| 17 | +// Extract (and concatenate) the toc and apicontent from each document. |
| 18 | +letcontents=''; |
| 19 | +letapicontent=''; |
| 20 | + |
| 21 | +// Identify files that should be skipped. As files are processed, they |
| 22 | +// are added to this list to prevent dupes. |
| 23 | +constseen={ |
| 24 | +'all.html': true, |
| 25 | +'index.html': true |
| 26 | +}; |
| 27 | + |
| 28 | +for(constlinkoftoc.match(/<a.*?>/g)){ |
| 29 | +consthref=/href="(.*?)"/.exec(link)[1]; |
| 30 | +if(!htmlFiles.includes(href)||seen[href])continue; |
| 31 | +constdata=fs.readFileSync(source+'/'+href,'utf8'); |
| 32 | + |
| 33 | +// Split the doc. |
| 34 | +constmatch=/(<\/ul>\s*)?<\/div>\s*<divid="apicontent">/.exec(data); |
| 35 | + |
| 36 | +contents+=data.slice(0,match.index) |
| 37 | +.replace(/[\s\S]*?<divid="toc">\s*<h2>.*?<\/h2>\s*(<ul>\s*)?/,''); |
| 38 | + |
| 39 | +apicontent+=data.slice(match.index+match[0].length) |
| 40 | +.replace(/(<\/div>\s*)*\s*<script[\s\S]*/,'') |
| 41 | +.replace(/<ahref="(\w[^#"]*)#/g,(match,href)=>{ |
| 42 | +returnhtmlFiles.includes(href) ? '<a href="#' : match; |
| 43 | +}) |
| 44 | +.trim()+'\n'; |
| 45 | + |
| 46 | +// Mark source as seen. |
| 47 | +seen[href]=true; |
| 48 | +} |
| 49 | + |
| 50 | +// Replace various mentions of _toc with all. |
| 51 | +letall=toc.replace(/_toc\.html/g,'all.html') |
| 52 | +.replace('_toc.json','all.json') |
| 53 | +.replace('api-section-_toc','api-section-all') |
| 54 | +.replace('data-id="_toc"','data-id="all"'); |
| 55 | + |
| 56 | +// Clean up the title. |
| 57 | +all=all.replace(/<title>.*?\|/,'<title>'); |
| 58 | + |
| 59 | +// Insert the combined table of contents. |
| 60 | +consttocStart=/<divid="toc">\s*<h2>.*?<\/h2>\s*/.exec(all); |
| 61 | +all=all.slice(0,tocStart.index+tocStart[0].length)+ |
| 62 | +'<ul>\n'+contents+'</ul>\n'+ |
| 63 | +all.slice(tocStart.index+tocStart[0].length); |
| 64 | + |
| 65 | +// Replace apicontent with the concatenated set of apicontents from each source. |
| 66 | +constapiStart=/<divid="apicontent">\s*/.exec(all); |
| 67 | +constapiEnd=/(\s*<\/div>)*\s*<script/.exec(all); |
| 68 | +all=all.slice(0,apiStart.index+apiStart[0].length)+ |
| 69 | +apicontent+ |
| 70 | +all.slice(apiEnd.index); |
| 71 | + |
| 72 | +// Write results. |
| 73 | +fs.writeFileSync(source+'/all.html',all,'utf8'); |
0 commit comments