forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontent.js
More file actions
33 lines (29 loc) · 1.09 KB
/
content.js
File metadata and controls
33 lines (29 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import path from 'path'
import walk from 'walk-sync'
import createTree from '#src/frame/lib/create-tree.js'
describe('content files', () => {
test.each(['content', 'src/fixtures/fixtures/content'])(
'no content files left orphaned without being in the tree in %s',
async (contentDir) => {
const tree = await createTree(contentDir)
const traverse = (node) => {
const relativeFiles = [node.page.relativePath]
for (const child of node.childPages || []) {
relativeFiles.push(...traverse(child))
}
return relativeFiles
}
const relativeFiles = traverse(tree).map((p) => path.join(contentDir, p))
const contentFiles = walk(contentDir, { includeBasePath: true, directories: false }).filter(
(file) => {
return file.endsWith('.md') && !file.includes('README')
},
)
const orphanedFiles = contentFiles.filter((file) => !relativeFiles.includes(file))
expect(
orphanedFiles.length,
`${orphanedFiles} orphaned files found on disk but not in site tree`,
).toBe(0)
},
)
})