Skip to content

Commit 89e5b46

Browse files
authored
Ensure index files have children (#59194)
1 parent c728720 commit 89e5b46

File tree

6 files changed

+45
-63
lines changed

6 files changed

+45
-63
lines changed

package-lock.json

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/fixtures/fixtures/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: This is an index page
3+
intro: 'I am missing a children frontmatter property'
4+
versions:
5+
fpt: '*'
6+
---

src/fixtures/fixtures/sample-toc-index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
title: A sample TOC
33
versions:
44
free-pro-team: '*'
5+
children:
6+
- /article-one
57
---
6-
7-
{% link_in_list /sample-article %}

src/frame/lib/get-toc-items.ts

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

src/frame/lib/page.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import getApplicableVersions from '@/versions/lib/get-applicable-versions'
66
import generateRedirectsForPermalinks from '@/redirects/lib/permalinks'
77
import getEnglishHeadings from '@/languages/lib/get-english-headings'
88
import { getAlertTitles } from '@/languages/lib/get-alert-titles'
9-
import getTocItems from './get-toc-items'
109
import Permalink from './permalink'
1110
import { renderContent } from '@/content-render/index'
1211
import processLearningTracks from '@/learning-track/lib/process-learning-tracks'
@@ -100,6 +99,8 @@ class Page {
10099
public rawRecommended?: string[]
101100
public autogenerated?: string
102101
public featuredLinks?: FeaturedLinksExpanded
102+
public children?: string[]
103+
public layout?: string
103104

104105
// Derived properties
105106
public languageCode!: string
@@ -111,7 +112,6 @@ class Page {
111112
public documentType: string
112113
public applicableVersions: string[]
113114
public permalinks: Permalink[]
114-
public tocItems?: any[]
115115
public communityRedirect?: CommunityRedirect
116116
public detectedPlatforms: string[] = []
117117
public includesPlatformSpecificContent: boolean = false
@@ -259,9 +259,13 @@ class Page {
259259
this.applicableVersions,
260260
)
261261

262+
// Ensure 'children' frontmatter exists if this is a standard index page
262263
if (this.relativePath.endsWith('index.md')) {
263-
// get an array of linked items in product and category TOCs
264-
this.tocItems = getTocItems(this)
264+
if (!this.children && !/(search|early-access)\/.*index.md/.test(this.relativePath)) {
265+
if (this.layout !== 'journey-landing') {
266+
throw new Error(`${this.fullPath} must contain 'children' frontmatter.`)
267+
}
268+
}
265269
}
266270

267271
// if this is an article and it doesn't have showMiniToc = false, set mini TOC to true

src/frame/tests/page.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,18 @@ describe('catches errors thrown in Page class', () => {
439439
await expect(getPage).rejects.toThrowError('versions')
440440
})
441441

442+
test('missing children frontmatter in index file', async () => {
443+
async function getPage() {
444+
return await Page.init({
445+
relativePath: 'index.md',
446+
basePath: path.join(__dirname, '../../../src/fixtures/fixtures'),
447+
languageCode: 'en',
448+
})
449+
}
450+
451+
await expect(getPage).rejects.toThrowError(/must contain 'children' frontmatter/)
452+
})
453+
442454
test('English page with a version in frontmatter that its parent product is not available in', async () => {
443455
async function getPage() {
444456
return await Page.init({

0 commit comments

Comments
 (0)