async function traverseDocsList()

in docs.js [139:203]


async function traverseDocsList(result) {
  let tpl = '';
  const docsInfo = []
  for (const data of result) {
    for (const item of data.list) {
      if (!item.docs) {
        continue;
      }
      for (const doc of item.docs) {
        const {name, repo, repoUrl, docs, description, icon} = item;
        if (!repoUrl) continue;
        let {version, commitId} = doc;
        version = version.toLowerCase();
        commitId = commitId || version;
        const docName = repo === 'skywalking' ? 'main' : repo;
        const localPath = `/content/docs/${docName}/${version}`;
        const menuFileName = `${docName.replace(/\-|\./g, '_')}${version.replace(/\-|v|\./g, '_')}`;

        tpl += `{{ if in .File.Path "${localPath.split('/content/')[1]}" }}
                  <div class="description-wrapper">
                    <h5>
                    <img width="26" height="26" src="/images/project/${icon}.svg">
                    ${name}
                    </h5>
                    <p>${description}</p>
                  </div>
                  {{ $currentVersion := lower .Site.Data.docSidebar.${menuFileName}.version }}
                  <div class="version-wrapper">Version: 
                  <select class="version-select">
                  {{range .Site.Data.docSidebar.${menuFileName}.repoDocs}}
                    {{$version := lower .version}}
                    {{$versionName := .versionName}}
                    <option {{ cond (eq $currentVersion $version) "selected" "" }} value="{{$version}}">
                    {{if $versionName}}
                      {{$versionName}}
                    {{else}}
                      {{$version}}
                    {{end}}
                    </option>
                  {{end}}
                  </select>
                  </div>
                  
                  {{ partial "sidebar-menu.html" .Site.Data.docSidebar.${menuFileName} }}
                  <div class="commit-id">Commit Id: {{.Site.Data.docSidebar.${menuFileName}.commitId}}</div>
                {{ end }}\n`;

        execSync(`"./doc.sh" ${repo} ${repoUrl} ${commitId} ${localPath} ${menuFileName}`);
        const sha = execSync(`git -C ./tmp/${repo} rev-parse HEAD`);
        if(version === NEXT && sha){
          commitId = sha.toString().replace('\n', '');
        }
        docsInfo.push({localPath, repoUrl, commitId, docName, version})

        await handleMenuFiles(`./data/docSidebar/${menuFileName}.yml`, {
          version,
          commitId,
          docs,
        }, `/docs/${docName}/${version}`)
      }

    }
  }
  return {tpl, docsInfo}
}