function renderNavNodes()

in scripts/docsite.ts [52:127]


function renderNavNodes(nodes: INode[], jsonNodes: IJsonNode[], parentUlElement: HTMLElement,
  parentNode: INode | undefined, currentPageUrl: string): void {

  for (const jsonNode of jsonNodes) {
    const expandable: boolean = jsonNode.subitems && jsonNode.subitems.length > 0;

    const liElement: HTMLElement = document.createElement('li');

    let titleContainerElement: HTMLElement = liElement;
    let currentPage: boolean = false;

    if (expandable) {
      liElement.innerHTML = '<svg class="navtree-expander"><use xlink:href="#icon-expander"></use></svg>';
    } else {
      liElement.innerHTML = '<svg class="navtree-expander"></svg>';

      if (jsonNode.url) {
        const linkElement: HTMLAnchorElement = document.createElement('a');
        linkElement.href = jsonNode.url;
        liElement.appendChild(linkElement);
        titleContainerElement = linkElement;

        const jsonNodeUrl: string = getUrlForComparison(jsonNode.url);
        if (jsonNodeUrl === currentPageUrl) {
          currentPage = true;

          // expand all the parent nodes
          for (let current = parentNode; current !== undefined; current = current.parentNode) {
            current.expanded = true;
          }
        }
      }
    }
    titleContainerElement.append(jsonNode.title);

    parentUlElement.appendChild(liElement);

    const node: INode = {
      parentNode,
      childNodes: [],
      liElement: liElement,
      ulElement: undefined,
      expanded: false,
      currentPage
    };
    nodes.push(node);

    if (expandable) {
      const ulElement: HTMLElement = document.createElement('ul');
      node.ulElement = ulElement;
      parentUlElement.appendChild(ulElement);

      if (jsonNode.url) {
        // Our design doesn't allow a container to have a hyperlink; create a virtual child node
        const virtualNode: IJsonNode = {
          title: '(members)',
          url: jsonNode.url,
          subitems: []
        };
        renderNavNodes(node.childNodes, [virtualNode], ulElement, node, currentPageUrl);
      }

      renderNavNodes(node.childNodes, jsonNode.subitems, ulElement, node, currentPageUrl);
    }

    updateNavNode(node);

    if (expandable) {
      liElement.onclick = () => {
        node.expanded = !node.expanded;
        updateNavNode(node);
      };
    }

  }
}