* refactor dev-toc middleware to use new site tree

* refactor dev-toc layout to use new site tree (we can move this to React someday if we want)
This commit is contained in:
Sarah Schneider 2021-07-01 11:05:18 -04:00 коммит произвёл GitHub
Родитель dbadd4cc42
Коммит 6fb35aae8d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 28 добавлений и 27 удалений

Просмотреть файл

@ -14,53 +14,45 @@
<h3>Versions</h3>
<ul class="versions-list">
{% for version in allVersions %}
{% if version[0] == "free-pro-team@latest" %}
<li><a href="/dev-toc">{{ version[1].versionTitle }}</a>
{% else %}
<li><a href="/{{ version[0] }}/dev-toc">{{ version[1].versionTitle }}</a>
{% endif %}
{% endfor %}
</ul>
{% if allVersions[currentVersion] %}
<h2 class="mt-3 mb-3"><abbr>TOC</abbr> for {{ allVersions[currentVersion].versionTitle }}</h2>
{% if allVersions[devTocVersion] %}
<h2 class="mt-3 mb-3"><abbr>TOC</abbr> for {{ allVersions[devTocVersion].versionTitle }}</h2>
<button class="btn mb-3 js-expand" type="button">Expand All</button>
<div/>
{% for product in siteTree[currentLanguage][currentVersion].products %}
<details class="mb-1"><summary>{{product[1].title}}</summary>
{% for productPage in devTocTree.childPages %}
<details class="mb-1"><summary>{{productPage.renderedFullTitle}}</summary>
<ul class="products-list">
<li title="{{product[1].title}}">
<a href="{{product[1].href}}">{{ product[1].title }}</a>
{% for category in product[1].categories %}
<li title="{{productPage.renderedFullTitle}}">
<a title="{{ productPage.page.documentType }}" href="{{productPage.href}}">{{ productPage.renderedFullTitle }}</a>
{% for categoryPage in productPage.childPages %}
<ul>
<li>
<a href="{{ category[1].href }}">{{ category[1].title }}</a>
<!-- some categories have maptopics with child articles -->
{% if category[1].maptopics %}
<a title="{{ categoryPage.page.documentType }}" href="{{ categoryPage.href }}">{{ categoryPage.renderedFullTitle }}</a>
<ul>
{% for maptopic in category[1].maptopics %}
{% unless maptopic[1].hidden %}
<!-- The following may actually be child articles of categories in some cases,
e.g., github/site-policy, not map topics -->
{% for maptopicPage in categoryPage.childPages %}
<li>
<a href="{{ maptopic[1].href }}">{{ maptopic[1].title }}</a>
<a title="{{ maptopicPage.page.documentType }}" href="{{ maptopicPage.href }}">{{ maptopicPage.renderedFullTitle }}</a>
<ul>
{% for article in maptopic[1].articles %}
{% for articlePage in maptopicPage.childPages %}
<li>
<a href="{{ article[1].href }}">{{ article[1].title }}</a>
<a title="{{ articlePage.page.documentType }}" href="{{ articlePage.href }}">{{ articlePage.renderedFullTitle }}</a>
</li>
{% endfor %}
</ul>
</li>
{% endunless %}
{% endfor %}
</ul>
<!-- some categories have no maptopics, only articles -->
{% else %}
<ul>
{% for article in category[1].articles %}
<li>
<a href="{{ article[1].href }}">{{ article[1].title }}</a>
</li>
{% endfor %}
</ul>
{% endif %}
</li>
{% endfor %}
</ul>

Просмотреть файл

@ -1,9 +1,18 @@
const { liquid } = require('../lib/render-content')
const layouts = require('../lib/layouts')
const nonEnterpriseDefaultVersion = require('../lib/non-enterprise-default-version')
module.exports = async function devToc (req, res, next) {
if (process.env.NODE_ENV !== 'development') return next()
if (!req.path.endsWith('/dev-toc')) return next()
return res.send(await liquid.parseAndRender(layouts['dev-toc'], req.context))
req.context.devTocVersion = req.path === '/dev-toc'
? nonEnterpriseDefaultVersion
: req.context.currentVersion
req.context.devTocTree = req.context.siteTree.en[req.context.devTocVersion]
const body = await liquid.parseAndRender(layouts['dev-toc'], req.context)
return res.status('200').send(body)
}