add the barest minimal dev-toc

This commit is contained in:
Sarah Schneider 2020-11-13 14:31:59 -05:00
Родитель 23e8317af4
Коммит 0df213dea6
3 изменённых файлов: 71 добавлений и 0 удалений

61
layouts/dev-toc.html Normal file
Просмотреть файл

@ -0,0 +1,61 @@
<h3>Versions</h3>
<ul>
{% for version in allVersions %}
<li><a href="/{{ version[0] }}/dev-toc">{{ version[1].versionTitle }}</a>
{% endfor %}
</ul>
{% if allVersions[currentVersion] %}
<h2>TOC for {{ allVersions[currentVersion].versionTitle }}</h2>
{% for product in siteTree[currentLanguage][currentVersion].products %}
<details><summary>{{product[1].title}}</summary>
<ul>
<li title="{{product[1].title}}">
<a href="/{{currentLanguage}}{{product[1].href}}">{{ product[1].title }}</a>
{% for category in product[1].categories %}
{% capture fullPathToCategory %}/{{currentLanguage}}{{category[1].href}}{% endcapture %}
<ul>
<li>
<a href="{{fullPathToCategory}}">{{ category[1].title }}</a>
<!-- some categories have maptopics with child articles -->
{% if category[1].maptopics %}
<ul">
{% for maptopic in category[1].maptopics %}
{% unless maptopic[1].hidden %}
{% capture fullPathToMaptopic %}/{{currentLanguage}}{{maptopic[1].href}}{% endcapture %}
<li>
<a href="{{fullPathToMaptopic}}">{{ maptopic[1].title }}</a>
<ul>
{% for article in maptopic[1].articles %}
{% capture fullPathToArticle %}/{{currentLanguage}}{{article[1].href}}{% endcapture %}
<li>
<a href="{{fullPathToArticle}}">{{ article[1].title }}</a>
</li>
{% endfor %}
</ul>
</li>
{% endunless %}
{% endfor %}
</ul>
<!-- some categories have no maptopics, only articles -->
{% else %}
<ul>
{% for article in category[1].articles %}
{% capture fullPathToArticle %}/{{currentLanguage}}{{article[1].href}}{% endcapture %}
<li>
<a href="{{fullPathToArticle}}">{{ article[1].title }}</a>
</li>
{% endfor %}
</ul>
{% endif %}
</li>
{% endfor %}
</ul>
</li>
</ul>
</details>
{% endfor %}
{% endif %}

9
middleware/dev-toc.js Normal file
Просмотреть файл

@ -0,0 +1,9 @@
const { liquid } = require('../lib/render-content')
const layouts = require('../lib/layouts')
module.exports = async (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))
}

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

@ -55,6 +55,7 @@ module.exports = function (app) {
app.use(require('./disable-caching-on-safari'))
app.get('/_500', asyncMiddleware(require('./trigger-error')))
app.use(require('./breadcrumbs'))
app.use(require('./dev-toc'))
app.use(require('./featured-links'))
app.get('/*', asyncMiddleware(require('./render-page')))
app.use(require('./handle-errors'))