From 0df213dea61da35b5c5b4b8db3ba3572e57a47e1 Mon Sep 17 00:00:00 2001 From: Sarah Schneider Date: Fri, 13 Nov 2020 14:31:59 -0500 Subject: [PATCH] add the barest minimal dev-toc --- layouts/dev-toc.html | 61 +++++++++++++++++++++++++++++++++++++++++++ middleware/dev-toc.js | 9 +++++++ middleware/index.js | 1 + 3 files changed, 71 insertions(+) create mode 100644 layouts/dev-toc.html create mode 100644 middleware/dev-toc.js diff --git a/layouts/dev-toc.html b/layouts/dev-toc.html new file mode 100644 index 0000000000..c48c401348 --- /dev/null +++ b/layouts/dev-toc.html @@ -0,0 +1,61 @@ +

Versions

+ + +{% if allVersions[currentVersion] %} +

TOC for {{ allVersions[currentVersion].versionTitle }}

+ +{% for product in siteTree[currentLanguage][currentVersion].products %} +
{{product[1].title}} + + + +
+{% endfor %} +{% endif %} diff --git a/middleware/dev-toc.js b/middleware/dev-toc.js new file mode 100644 index 0000000000..5e00093e55 --- /dev/null +++ b/middleware/dev-toc.js @@ -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)) +} diff --git a/middleware/index.js b/middleware/index.js index 19ebf17ba6..9427918fa6 100644 --- a/middleware/index.js +++ b/middleware/index.js @@ -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'))