publish.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975
  1. const env = require( 'jsdoc/env' );
  2. const fs = require( 'jsdoc/fs' );
  3. const helper = require( 'jsdoc/util/templateHelper' );
  4. const logger = require( 'jsdoc/util/logger' );
  5. const path = require( 'jsdoc/path' );
  6. const { taffy } = require( '@jsdoc/salty' );
  7. const template = require( 'jsdoc/template' );
  8. const util = require( 'util' );
  9. const htmlsafe = helper.htmlsafe;
  10. const linkto = helper.linkto;
  11. const resolveAuthorLinks = helper.resolveAuthorLinks;
  12. const hasOwnProp = Object.prototype.hasOwnProperty;
  13. let data;
  14. let view;
  15. const outdir = path.normalize( env.opts.destination );
  16. const themeOpts = ( env.opts.themeOpts ) || {};
  17. const categoryMap = {}; // Maps class names to their categories (Core, Addons, TSL)
  18. function mkdirSync( filepath ) {
  19. return fs.mkdirSync( filepath, { recursive: true } );
  20. }
  21. function find( spec ) {
  22. return helper.find( data, spec );
  23. }
  24. function getAncestorLinks( doclet ) {
  25. return helper.getAncestorLinks( data, doclet );
  26. }
  27. function hashToLink( doclet, hash ) {
  28. let url;
  29. if ( ! /^(#.+)/.test( hash ) ) {
  30. return hash;
  31. }
  32. url = helper.createLink( doclet );
  33. url = url.replace( /(#.+|$)/, hash );
  34. return `<a href="${url}">${hash}</a>`;
  35. }
  36. function needsSignature( { kind, type, meta } ) {
  37. let needsSig = false;
  38. // function and class definitions always get a signature
  39. if ( kind === 'function' || kind === 'class' ) {
  40. needsSig = true;
  41. } else if ( kind === 'typedef' && type && type.names && type.names.length ) {
  42. // typedefs that contain functions get a signature, too
  43. for ( let i = 0, l = type.names.length; i < l; i ++ ) {
  44. if ( type.names[ i ].toLowerCase() === 'function' ) {
  45. needsSig = true;
  46. break;
  47. }
  48. }
  49. } else if ( kind === 'namespace' && meta && meta.code && meta.code.type && meta.code.type.match( /[Ff]unction/ ) ) {
  50. // and namespaces that are functions get a signature (but finding them is a
  51. // bit messy)
  52. needsSig = true;
  53. }
  54. return needsSig;
  55. }
  56. function updateItemName( item ) {
  57. let itemName = item.name || '';
  58. if ( item.variable ) {
  59. itemName = `&hellip;${itemName}`;
  60. }
  61. return itemName;
  62. }
  63. function addParamAttributes( params ) {
  64. return params.filter( ( { name } ) => name && ! name.includes( '.' ) ).map( param => {
  65. let itemName = updateItemName( param );
  66. if ( param.type && param.type.names && param.type.names.length ) {
  67. const escapedTypes = param.type.names.map( name => htmlsafe( name ) );
  68. itemName += ' : <span class="param-type">' + escapedTypes.join( ' | ' ) + '</span>';
  69. }
  70. return itemName;
  71. } );
  72. }
  73. function buildItemTypeStrings( item ) {
  74. const types = [];
  75. if ( item && item.type && item.type.names ) {
  76. item.type.names.forEach( name => {
  77. types.push( linkto( name, htmlsafe( name ) ) );
  78. } );
  79. }
  80. return types;
  81. }
  82. function buildSearchListForData() {
  83. const categories = {
  84. 'Core': [],
  85. 'Addons': [],
  86. 'Global': [],
  87. 'TSL': []
  88. };
  89. data().each( ( item ) => {
  90. if ( item.kind !== 'package' && item.kind !== 'typedef' && ! item.inherited ) {
  91. // Extract the class name from the longname (e.g., "Animation#getAnimationLoop" -> "Animation")
  92. const parts = item.longname.split( /[#~]/ );
  93. const className = parts[ 0 ];
  94. // If this item is a member/method of a class, check if the parent class exists
  95. if ( parts.length > 1 ) {
  96. // Find the parent class/module
  97. const parentClass = find( { longname: className, kind: [ 'class', 'module' ] } );
  98. // Only include if parent exists and is not private
  99. if ( parentClass && parentClass.length > 0 && parentClass[ 0 ].access !== 'private' ) {
  100. const category = categoryMap[ className ];
  101. const entry = {
  102. title: item.longname,
  103. kind: item.kind
  104. };
  105. if ( category ) {
  106. categories[ category ].push( entry );
  107. }
  108. }
  109. } else {
  110. // This is a top-level class/module/function - include if not private
  111. if ( item.access !== 'private' ) {
  112. let category = categoryMap[ className ];
  113. // If not in categoryMap, determine category from @tsl tag
  114. if ( ! category ) {
  115. const hasTslTag = Array.isArray( item.tags ) && item.tags.some( tag => tag.title === 'tsl' );
  116. if ( hasTslTag ) {
  117. category = 'TSL';
  118. } else {
  119. category = 'Global';
  120. }
  121. }
  122. const entry = {
  123. title: item.longname,
  124. kind: item.kind
  125. };
  126. categories[ category ].push( entry );
  127. }
  128. }
  129. }
  130. } );
  131. return categories;
  132. }
  133. function buildAttribsString( attribs ) {
  134. let attribsString = '';
  135. if ( attribs && attribs.length ) {
  136. attribsString = htmlsafe( util.format( '(%s) ', attribs.join( ', ' ) ) );
  137. }
  138. return attribsString;
  139. }
  140. function addNonParamAttributes( items ) {
  141. let types = [];
  142. items.forEach( item => {
  143. types = types.concat( buildItemTypeStrings( item ) );
  144. } );
  145. return types;
  146. }
  147. function addSignatureParams( f ) {
  148. const params = f.params ? addParamAttributes( f.params ) : [];
  149. const paramsString = params.join( ', ' );
  150. f.signature = util.format( '%s(%s)', ( f.signature || '' ), paramsString ? ' ' + paramsString + ' ' : '' );
  151. }
  152. function addSignatureReturns( f ) {
  153. let returnTypes = [];
  154. let returnTypesString = '';
  155. const source = f.yields || f.returns;
  156. if ( source ) {
  157. returnTypes = addNonParamAttributes( source );
  158. }
  159. if ( returnTypes.length ) {
  160. returnTypesString = util.format( ' : %s', returnTypes.join( ' | ' ) );
  161. }
  162. f.signature = `<span class="signature">${f.signature || ''}</span>${returnTypesString ? `<span class="type-signature">${returnTypesString}</span>` : ''}`;
  163. }
  164. function addSignatureTypes( f ) {
  165. const types = f.type ? buildItemTypeStrings( f ) : [];
  166. f.signature = `${f.signature || ''}${types.length ? `<span class="type-signature"> : ${types.join( ' | ' )}</span>` : ''}`;
  167. }
  168. function addAttribs( f ) {
  169. const attribs = helper.getAttribs( f ).filter( attrib => attrib !== 'static' && attrib !== 'nullable' );
  170. const attribsString = buildAttribsString( attribs );
  171. f.attribs = attribsString ? util.format( '<span class="type-signature">%s</span>', attribsString ) : '';
  172. }
  173. function shortenPaths( files, commonPrefix ) {
  174. Object.keys( files ).forEach( file => {
  175. files[ file ].shortened = files[ file ].resolved.replace( commonPrefix, '' )
  176. // always use forward slashes
  177. .replace( /\\/g, '/' );
  178. } );
  179. return files;
  180. }
  181. function getPathFromDoclet( { meta } ) {
  182. if ( ! meta ) {
  183. return null;
  184. }
  185. return meta.path && meta.path !== 'null' ?
  186. path.join( meta.path, meta.filename ) :
  187. meta.filename;
  188. }
  189. function getFullAugmentsChain( doclet ) {
  190. const chain = [];
  191. if ( ! doclet || ! doclet.augments || ! doclet.augments.length ) {
  192. return chain;
  193. }
  194. // Start with the immediate parent
  195. const parentName = doclet.augments[0];
  196. chain.push( parentName );
  197. // Recursively find the parent's ancestors
  198. const parentDoclet = find( { longname: parentName } );
  199. if ( parentDoclet && parentDoclet.length > 0 ) {
  200. const parentChain = getFullAugmentsChain( parentDoclet[0] );
  201. chain.unshift( ...parentChain );
  202. }
  203. return chain;
  204. }
  205. function generate( title, docs, filename, resolveLinks ) {
  206. let html;
  207. resolveLinks = resolveLinks !== false;
  208. const docData = {
  209. env: env,
  210. title: title,
  211. docs: docs,
  212. augments: docs && docs[0] ? getFullAugmentsChain( docs[0] ) : null
  213. };
  214. // Put HTML files in pages/ subdirectory
  215. const pagesDir = path.join( outdir, 'pages' );
  216. mkdirSync( pagesDir );
  217. const outpath = path.join( pagesDir, filename );
  218. html = view.render( 'container.tmpl', docData );
  219. if ( resolveLinks ) {
  220. html = helper.resolveLinks( html ); // turn {@link foo} into <a href="foodoc.html">foo</a>
  221. }
  222. // Remove lines that only contain whitespace
  223. html = html.replace( /^\s*\n/gm, '' );
  224. fs.writeFileSync( outpath, html, 'utf8' );
  225. }
  226. function generateSourceFiles( sourceFiles, encoding = 'utf8' ) {
  227. Object.keys( sourceFiles ).forEach( file => {
  228. let source;
  229. // links are keyed to the shortened path in each doclet's `meta.shortpath` property
  230. const sourceOutfile = helper.getUniqueFilename( sourceFiles[ file ].shortened );
  231. helper.registerLink( sourceFiles[ file ].shortened, sourceOutfile );
  232. try {
  233. source = {
  234. kind: 'source',
  235. code: helper.htmlsafe( fs.readFileSync( sourceFiles[ file ].resolved, encoding ) )
  236. };
  237. } catch ( e ) {
  238. logger.error( 'Error while generating source file %s: %s', file, e.message );
  239. }
  240. generate( `Source: ${sourceFiles[ file ].shortened}`, [ source ], sourceOutfile,
  241. false );
  242. } );
  243. }
  244. function buildMainNav( items, itemsSeen, linktoFn ) {
  245. const coreDirectory = 'src';
  246. const addonsDirectory = 'examples/jsm';
  247. const hierarchy = new Map();
  248. hierarchy.set( 'Core', new Map() );
  249. hierarchy.set( 'Addons', new Map() );
  250. let nav = '';
  251. if ( items.length ) {
  252. items.forEach( item => {
  253. let displayName;
  254. let itemNav = '';
  255. if ( ! hasOwnProp.call( itemsSeen, item.longname ) ) {
  256. if ( env.conf.templates.default.useLongnameInNav ) {
  257. displayName = item.longname;
  258. } else {
  259. displayName = item.name;
  260. }
  261. itemNav += `<li>${linktoFn( item.longname, displayName.replace( /\b(module|event):/g, '' ) )}</li>`;
  262. itemsSeen[ item.longname ] = true;
  263. const path = item.meta.shortpath;
  264. if ( path.startsWith( coreDirectory ) ) {
  265. const subCategory = path.split( '/' )[ 1 ];
  266. pushNavItem( hierarchy, 'Core', subCategory, itemNav );
  267. categoryMap[ item.longname ] = 'Core';
  268. } else if ( path.startsWith( addonsDirectory ) ) {
  269. const subCategory = path.split( '/' )[ 2 ];
  270. pushNavItem( hierarchy, 'Addons', subCategory, itemNav );
  271. categoryMap[ item.longname ] = 'Addons';
  272. }
  273. }
  274. } );
  275. for ( const [ mainCategory, map ] of hierarchy ) {
  276. nav += `<h2>${mainCategory}</h2>\n`;
  277. const sortedMap = new Map( [ ...map.entries() ].sort() ); // sort sub categories
  278. for ( const [ subCategory, links ] of sortedMap ) {
  279. nav += `<h3>${subCategory}</h3>\n`;
  280. let navItems = '';
  281. links.sort();
  282. for ( const link of links ) {
  283. navItems += link + '\n';
  284. }
  285. nav += `<ul>\n${navItems}</ul>\n`;
  286. }
  287. }
  288. }
  289. return nav;
  290. }
  291. function buildGlobalsNav( globals, seen ) {
  292. let globalNav;
  293. let nav = '';
  294. if ( globals.length ) {
  295. // TSL
  296. let tslNav = '';
  297. globals.forEach( ( { kind, longname, name, tags } ) => {
  298. if ( kind !== 'typedef' && ! hasOwnProp.call( seen, longname ) ) {
  299. const hasTslTag = Array.isArray( tags ) && tags.some( tag => tag.title === 'tsl' );
  300. if ( hasTslTag ) {
  301. tslNav += `<li>${linkto( longname, name )}</li>\n`;
  302. seen[ longname ] = true;
  303. }
  304. }
  305. } );
  306. nav += `<h2>TSL</h2>\n<ul>\n${tslNav}</ul>\n`;
  307. // Globals
  308. globalNav = '';
  309. globals.forEach( ( { kind, longname, name } ) => {
  310. if ( kind !== 'typedef' && ! hasOwnProp.call( seen, longname ) ) {
  311. globalNav += `<li>${linkto( longname, name )}</li>\n`;
  312. }
  313. seen[ longname ] = true;
  314. } );
  315. if ( ! globalNav ) {
  316. // turn the heading into a link so you can actually get to the global page
  317. nav += `<h3>${linkto( 'global', 'Global' )}</h3>\n`;
  318. } else {
  319. nav += `<h2>Global</h2>\n<ul>\n${globalNav}</ul>\n`;
  320. }
  321. }
  322. return nav;
  323. }
  324. function pushNavItem( hierarchy, mainCategory, subCategory, itemNav ) {
  325. // Special case for TSL - keep it all uppercase
  326. if ( subCategory.toLowerCase() === 'tsl' ) {
  327. subCategory = 'TSL';
  328. } else {
  329. subCategory = subCategory[ 0 ].toUpperCase() + subCategory.slice( 1 ); // capitalize
  330. }
  331. if ( hierarchy.get( mainCategory ).get( subCategory ) === undefined ) {
  332. hierarchy.get( mainCategory ).set( subCategory, [] );
  333. }
  334. const categoryList = hierarchy.get( mainCategory ).get( subCategory );
  335. categoryList.push( itemNav );
  336. }
  337. /**
  338. * Create the navigation sidebar.
  339. * @param {Object} members The members that will be used to create the sidebar.
  340. * @return {string} The HTML for the navigation sidebar.
  341. */
  342. function buildNav( members ) {
  343. let nav = '';
  344. const seen = {};
  345. nav += buildMainNav( [ ...members.classes, ...members.modules ], seen, linkto );
  346. nav += buildGlobalsNav( members.globals, seen );
  347. return nav;
  348. }
  349. /**
  350. @param {TAFFY} taffyData See <http://taffydb.com/>.
  351. @param {Object} opts
  352. @param {Tutorial} tutorials
  353. */
  354. exports.publish = ( taffyData, opts, tutorials ) => {
  355. const sourceFilePaths = [];
  356. let sourceFiles = {};
  357. let staticFileFilter;
  358. let staticFilePaths;
  359. let staticFileScanner;
  360. data = taffyData;
  361. const conf = env.conf.templates || {};
  362. conf.default = conf.default || {};
  363. const templatePath = path.normalize( opts.template );
  364. view = new template.Template( path.join( templatePath, 'tmpl' ) );
  365. // claim some special filenames in advance, so the All-Powerful Overseer of Filename Uniqueness
  366. // doesn't try to hand them out later
  367. const indexUrl = helper.getUniqueFilename( 'index' );
  368. // don't call registerLink() on this one! 'index' is also a valid longname
  369. const globalUrl = helper.getUniqueFilename( 'global' );
  370. helper.registerLink( 'global', globalUrl );
  371. // set up templating
  372. view.layout = conf.default.layoutFile ?
  373. path.getResourcePath( path.dirname( conf.default.layoutFile ),
  374. path.basename( conf.default.layoutFile ) ) :
  375. 'layout.tmpl';
  376. // set up tutorials for helper
  377. helper.setTutorials( tutorials );
  378. data = helper.prune( data );
  379. data.sort( 'longname, version, since' );
  380. helper.addEventListeners( data );
  381. data().each( doclet => {
  382. let sourcePath;
  383. doclet.attribs = '';
  384. if ( doclet.see ) {
  385. doclet.see.forEach( ( seeItem, i ) => {
  386. doclet.see[ i ] = hashToLink( doclet, seeItem );
  387. } );
  388. }
  389. // build a list of source files
  390. if ( doclet.meta ) {
  391. sourcePath = getPathFromDoclet( doclet );
  392. sourceFiles[ sourcePath ] = {
  393. resolved: sourcePath,
  394. shortened: null
  395. };
  396. if ( ! sourceFilePaths.includes( sourcePath ) ) {
  397. sourceFilePaths.push( sourcePath );
  398. }
  399. }
  400. } );
  401. fs.mkPath( outdir );
  402. // copy the template's static files to outdir
  403. const fromDir = path.join( templatePath, 'static' );
  404. const staticFiles = fs.ls( fromDir, 3 );
  405. staticFiles.forEach( fileName => {
  406. const toDir = fs.toDir( fileName.replace( fromDir, outdir ) );
  407. fs.mkPath( toDir );
  408. fs.copyFileSync( fileName, toDir );
  409. } );
  410. // copy user-specified static files to outdir
  411. if ( conf.default.staticFiles ) {
  412. // The canonical property name is `include`. We accept `paths` for backwards compatibility
  413. // with a bug in JSDoc 3.2.x.
  414. staticFilePaths = conf.default.staticFiles.include ||
  415. conf.default.staticFiles.paths ||
  416. [];
  417. staticFileFilter = new ( require( 'jsdoc/src/filter' ).Filter )( conf.default.staticFiles );
  418. staticFileScanner = new ( require( 'jsdoc/src/scanner' ).Scanner )();
  419. staticFilePaths.forEach( filePath => {
  420. filePath = path.resolve( env.pwd, filePath );
  421. const extraStaticFiles = staticFileScanner.scan( [ filePath ], 10, staticFileFilter );
  422. extraStaticFiles.forEach( fileName => {
  423. const sourcePath = fs.toDir( filePath );
  424. const toDir = fs.toDir( fileName.replace( sourcePath, outdir ) );
  425. fs.mkPath( toDir );
  426. fs.copyFileSync( fileName, toDir );
  427. } );
  428. } );
  429. }
  430. if ( sourceFilePaths.length ) {
  431. sourceFiles = shortenPaths( sourceFiles, path.commonPrefix( sourceFilePaths ) );
  432. }
  433. data().each( doclet => {
  434. let docletPath;
  435. const url = helper.createLink( doclet );
  436. helper.registerLink( doclet.longname, url );
  437. // add a shortened version of the full path
  438. if ( doclet.meta ) {
  439. docletPath = getPathFromDoclet( doclet );
  440. docletPath = sourceFiles[ docletPath ].shortened;
  441. if ( docletPath ) {
  442. doclet.meta.shortpath = docletPath;
  443. }
  444. }
  445. } );
  446. data().each( doclet => {
  447. const url = helper.longnameToUrl[ doclet.longname ];
  448. if ( url.includes( '#' ) ) {
  449. doclet.id = helper.longnameToUrl[ doclet.longname ].split( /#/ ).pop();
  450. } else {
  451. doclet.id = doclet.name;
  452. }
  453. if ( needsSignature( doclet ) ) {
  454. addSignatureParams( doclet );
  455. addSignatureReturns( doclet );
  456. addAttribs( doclet );
  457. }
  458. } );
  459. // do this after the urls have all been generated
  460. data().each( doclet => {
  461. doclet.ancestors = getAncestorLinks( doclet );
  462. if ( doclet.kind === 'member' ) {
  463. addSignatureTypes( doclet );
  464. addAttribs( doclet );
  465. }
  466. if ( doclet.kind === 'constant' ) {
  467. addSignatureTypes( doclet );
  468. addAttribs( doclet );
  469. doclet.kind = 'member';
  470. }
  471. } );
  472. // prepare import statements, demo tags, and extract code examples
  473. data().each( doclet => {
  474. if ( doclet.kind === 'class' || doclet.kind === 'module' ) {
  475. const tags = doclet.tags;
  476. if ( Array.isArray( tags ) ) {
  477. const importTag = tags.find( tag => tag.title === 'three_import' );
  478. doclet.import = ( importTag !== undefined ) ? importTag.text : null;
  479. const demoTag = tags.find( tag => tag.title === 'demo' );
  480. doclet.demo = ( demoTag !== undefined ) ? demoTag.text : null;
  481. }
  482. // Extract code example from classdesc
  483. if ( doclet.classdesc ) {
  484. const codeBlockRegex = /<pre class="prettyprint source[^"]*"><code>([\s\S]*?)<\/code><\/pre>/;
  485. const match = doclet.classdesc.match( codeBlockRegex );
  486. if ( match ) {
  487. doclet.codeExample = match[ 0 ];
  488. // Remove the code example from classdesc
  489. doclet.classdesc = doclet.classdesc.replace( codeBlockRegex, '' ).trim();
  490. }
  491. }
  492. }
  493. } );
  494. const members = helper.getMembers( data );
  495. members.tutorials = tutorials.children;
  496. // output pretty-printed source files by default
  497. const outputSourceFiles = conf.default && conf.default.outputSourceFiles !== false;
  498. // add template helpers
  499. view.find = find;
  500. view.linkto = linkto;
  501. view.resolveAuthorLinks = resolveAuthorLinks;
  502. view.htmlsafe = htmlsafe;
  503. view.outputSourceFiles = outputSourceFiles;
  504. view.ignoreInheritedSymbols = themeOpts.ignoreInheritedSymbols;
  505. // Empty nav in templates - will be loaded from nav.html client-side
  506. view.nav = '';
  507. // generate the pretty-printed source files first so other pages can link to them
  508. if ( outputSourceFiles ) {
  509. generateSourceFiles( sourceFiles, opts.encoding );
  510. }
  511. if ( members.globals.length ) {
  512. // Split globals into TSL and non-TSL
  513. const tslGlobals = [];
  514. const nonTslGlobals = [];
  515. const originalGlobals = members.globals;
  516. originalGlobals.forEach( item => {
  517. const hasTslTag = Array.isArray( item.tags ) && item.tags.some( tag => tag.title === 'tsl' );
  518. if ( hasTslTag ) {
  519. tslGlobals.push( item );
  520. // Register each TSL item to link to TSL.html
  521. helper.registerLink( item.longname, 'TSL.html#' + item.name );
  522. } else {
  523. nonTslGlobals.push( item );
  524. }
  525. } );
  526. // Generate TSL.html for TSL functions
  527. if ( tslGlobals.length ) {
  528. generate( 'TSL', [ { kind: 'globalobj', isTSL: true } ], 'TSL.html' );
  529. }
  530. // Generate global.html for remaining globals
  531. if ( nonTslGlobals.length ) {
  532. generate( 'Global', [ { kind: 'globalobj' } ], globalUrl );
  533. }
  534. }
  535. // index page displays information from package.json and lists files
  536. const files = find( { kind: 'file' } );
  537. const packages = find( { kind: 'package' } );
  538. generate( '', // MODIFIED (Remove Home title)
  539. packages.concat(
  540. [ {
  541. kind: 'mainpage',
  542. readme: opts.readme,
  543. longname: ( opts.mainpagetitle ) ? opts.mainpagetitle : 'Main Page'
  544. } ]
  545. ).concat( files ), indexUrl );
  546. // set up the lists that we'll use to generate pages
  547. const classes = taffy( members.classes );
  548. const modules = taffy( members.modules );
  549. Object.keys( helper.longnameToUrl ).forEach( longname => {
  550. const myClasses = helper.find( classes, { longname: longname } );
  551. const myModules = helper.find( modules, { longname: longname } );
  552. if ( myClasses.length ) {
  553. generate( `${myClasses[ 0 ].name}`, myClasses, helper.longnameToUrl[ longname ] );
  554. }
  555. if ( myModules.length ) {
  556. generate( `${myModules[ 0 ].name}`, myModules, helper.longnameToUrl[ longname ] );
  557. }
  558. } );
  559. // Build navigation HTML
  560. const navHtml = buildNav( members );
  561. // Generate index.html with embedded navigation
  562. const indexTemplatePath = path.join( templatePath, 'static', 'index.html' );
  563. let indexHtml = fs.readFileSync( indexTemplatePath, 'utf8' );
  564. // Replace placeholder with actual navigation
  565. indexHtml = indexHtml.replace( '<!--NAV_PLACEHOLDER-->', navHtml );
  566. fs.writeFileSync(
  567. path.join( outdir, 'index.html' ),
  568. indexHtml,
  569. 'utf8'
  570. );
  571. // search
  572. const searchList = buildSearchListForData();
  573. fs.writeFileSync(
  574. path.join( outdir, 'search.json' ),
  575. JSON.stringify( searchList, null, '\t' )
  576. );
  577. };
粤ICP备19079148号