Skip to content

Commit af519b5

Browse files
committed
use article layout for TOCs instead of new separate generic-toc layout that has to be maintained
1 parent 7db6018 commit af519b5

4 files changed

Lines changed: 16 additions & 82 deletions

File tree

includes/article.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ <h2 id="in-this-article" class="f5 mb-2"><a class="Link--primary" href="#in-this
6868
{% include featured-links %}
6969
{% endif %}
7070
{{ renderedPage }}
71+
72+
{% if tocItems and tocItems.length %}
73+
{% if page.documentType == "category" or page.relativePath == "github/index.md" %}
74+
{% include generic-toc-list %}
75+
{% else %}
76+
{% include generic-toc-items %}
77+
{% endif %}
78+
{% endif %}
7179
</div>
7280
</div>
7381

layouts/generic-toc.html

Lines changed: 0 additions & 64 deletions
This file was deleted.

middleware/contextualizers/generic-toc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ const { sortBy } = require('lodash')
33
module.exports = async function genericToc (req, res, next) {
44
if (!req.context.page) return next()
55
if (req.context.page.hidden) return next()
6-
if (req.context.currentLayoutName !== 'generic-toc') return next()
6+
if (req.context.currentLayoutName !== 'default') return next()
7+
if (req.context.page.documentType === 'homepage' || req.context.page.documentType === 'article') return next()
78

89
const currentSiteTree = req.context.siteTree[req.context.currentLanguage][req.context.currentVersion]
910

middleware/contextualizers/layout.js

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,18 @@ const layouts = require('../../lib/layouts')
33
module.exports = function layoutContext (req, res, next) {
44
if (!req.context.page) return next()
55

6-
let layoutName
7-
8-
// If this is an index.md that is not the homepage and does not have a defined layout, use `generic-toc`.
9-
const usesGenericToc = req.context.page.relativePath.endsWith('index.md') &&
10-
req.context.page.documentType !== 'homepage' &&
11-
!req.context.page.hidden
12-
13-
if (req.context.page.layout) {
6+
const layoutOptsByType = {
147
// Layouts can be specified with a `layout` frontmatter value.
158
// Any invalid layout values will be caught by frontmatter schema validation.
16-
layoutName = req.context.page.layout
17-
} else if (req.context.page.layout === false) {
9+
string: req.context.page.layout,
1810
// A `layout: false` value means use no layout.
19-
layoutName = ''
20-
} else if (req.context.page.layout === undefined) {
11+
boolean: '',
2112
// For all other files (like articles and the homepage), use the `default` layout.
22-
if (process.env.FEATURE_NEW_SITETREE) {
23-
layoutName = usesGenericToc ? 'generic-toc' : 'default'
24-
} else {
25-
layoutName = 'default'
26-
}
13+
undefined: 'default'
2714
}
2815

16+
const layoutName = layoutOptsByType[typeof (req.context.page.layout)]
17+
2918
// Attach to the context object
3019
req.context.currentLayoutName = layoutName
3120
req.context.currentLayout = layouts[layoutName]

0 commit comments

Comments
 (0)