(pkgName: string, summarize: boolean = false)
| 276 | // parses a package's index file to produce a list of help topics |
| 277 | // highlights ths 'home' topic and adds entries for the package index and DESCRIPTION file |
| 278 | public async getTopics(pkgName: string, summarize: boolean = false): Promise<Topic[] | undefined> { |
| 279 | |
| 280 | const indexEntries = await this.getParsedIndexFile(`/library/${pkgName}/html/00Index.html`); |
| 281 | |
| 282 | if(!indexEntries){ |
| 283 | return undefined; |
| 284 | } |
| 285 | |
| 286 | const topics: TopicExtra[] = indexEntries.map(v => { |
| 287 | const topic: TopicExtra = { |
| 288 | name: v.name, |
| 289 | description: v.description, |
| 290 | href: v.href || v.name, |
| 291 | type: TopicType.NORMAL, //replaced below |
| 292 | helpPath: '' // replaced below |
| 293 | }; |
| 294 | |
| 295 | topic.type = (topic.name === `${pkgName}-package` ? TopicType.HOME : TopicType.NORMAL); |
| 296 | |
| 297 | topic.helpPath = ( |
| 298 | pkgName === 'doc' ? |
| 299 | `/doc/html/${topic.href}` : |
| 300 | `/library/${pkgName}/html/${topic.href}` |
| 301 | ); |
| 302 | return topic; |
| 303 | }); |
| 304 | |
| 305 | const ind = topics.findIndex(v => v.type === TopicType.HOME); |
| 306 | let homeTopic: TopicExtra | undefined = undefined; |
| 307 | if(ind >= 0){ |
| 308 | homeTopic = topics.splice(ind, 1)[0]; |
| 309 | } |
| 310 | |
| 311 | const indexTopic: TopicExtra = { |
| 312 | name: 'Index', |
| 313 | description: '', |
| 314 | href: '00Index.html', |
| 315 | helpPath: `/library/${pkgName}/html/00Index.html`, |
| 316 | type: TopicType.INDEX |
| 317 | }; |
| 318 | |
| 319 | const descriptionTopic: TopicExtra = { |
| 320 | name: 'DESCRIPTION', |
| 321 | description: '', |
| 322 | href: '../DESCRIPTION', |
| 323 | helpPath: `/library/${pkgName}/DESCRIPTION`, |
| 324 | type: TopicType.META |
| 325 | }; |
| 326 | |
| 327 | topics.unshift(indexTopic, descriptionTopic); |
| 328 | if(homeTopic){ |
| 329 | topics.unshift(homeTopic); |
| 330 | } |
| 331 | |
| 332 | const ret = (summarize ? summarizeTopics(topics) : topics); |
| 333 | |
| 334 | ret.sort((a, b) => { |
| 335 | if(a.type === b.type){ |
no test coverage detected