Skip to content
This repository was archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
fix toc bug (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
yunair authored Sep 15, 2020
1 parent 603142b commit 2641a6e
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/tocGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { setOfTopLevelItems } from './common/constants';
import { TocItem } from './interfaces/TocItem';
import { flags } from './common/flags';

export function generateItems(element: YamlModel): TocItem {
function generateItems(element: YamlModel): TocItem {
let result: TocItem;
let itemsDetails: TocItem[] = [];
result = {
Expand Down Expand Up @@ -52,10 +52,7 @@ export function generateTOC(elements: YamlModel[], packageUid: string): TocItem[
if (itemsDetails.length === 0) {
itemsDetails = null;
} else {
itemsDetails.splice(0, 0, {
name: "Overview",
uid: packageUid
});
changeTocToOverview(itemsDetails, packageUid);
}

return [{
Expand All @@ -64,6 +61,20 @@ export function generateTOC(elements: YamlModel[], packageUid: string): TocItem[
}];
}

function changeTocToOverview(items: TocItem[], uid: string) {
items.splice(0, 0, {
name: "Overview",
uid: uid
});
for (let item of items) {
if (item.items && item.items.length > 0) {
const uid = item.uid
delete item.uid
changeTocToOverview(item.items, uid)
}
}
}

function sortTOC(a: YamlModel, b: YamlModel) {
let nameA = a.name.toUpperCase();
let nameB = b.name.toUpperCase();
Expand Down

0 comments on commit 2641a6e

Please sign in to comment.