-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
84 additions
and
21 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,33 @@ | ||
const fs = require('fs') | ||
const yaml = require('js-yaml') | ||
const {getNavigationLinks, getContentFrontmatter} = require('./utils/docs') | ||
|
||
let nav | ||
let navLinks, contentFM | ||
|
||
beforeAll(() => { | ||
nav = yaml.load(fs.readFileSync('./docs/src/@primer/gatsby-theme-doctocat/nav.yml', 'utf8')) | ||
beforeAll(async () => { | ||
contentFM = await getContentFrontmatter() | ||
navLinks = getNavigationLinks() | ||
}) | ||
|
||
describe('frontmatter', () => { | ||
it('page title matches link title', () => { | ||
navLinks.forEach(link => { | ||
const content = contentFM[link['url']] | ||
expect(content).not.toBeNull() | ||
expect(content['title']).toBe(link['title']) | ||
}) | ||
}) | ||
|
||
it('contains path attribute', () => { | ||
Object.values(contentFM).forEach( v => { | ||
expect(v['path']).not.toBeNull() | ||
}) | ||
}) | ||
}) | ||
|
||
describe('navigation', () => { | ||
it('has a file for each nav item', () => { | ||
|
||
navLinks.forEach(link => { | ||
const content = contentFM[link['url']] | ||
expect(content).not.toBeNull() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const fs = require('fs') | ||
const frontMatter = require('front-matter') | ||
const yaml = require('js-yaml') | ||
const globby = require('globby') | ||
const {join} = require('path') | ||
|
||
const docsPath = join(__dirname, '../../docs') | ||
|
||
function collectNavLinks(links) { | ||
let foundLinks = [] | ||
links.forEach(link => { | ||
foundLinks.push({ | ||
title: link['title'], | ||
url: link['url'] | ||
}) | ||
if(link['children']) { | ||
foundLinks = foundLinks.concat(collectNavLinks(link['children'])) | ||
} | ||
}) | ||
return foundLinks | ||
} | ||
|
||
function getNavigationLinks() { | ||
const nav = yaml.load(fs.readFileSync(join(docsPath, './src/@primer/gatsby-theme-doctocat/nav.yml'), 'utf8')) | ||
return collectNavLinks(nav) | ||
} | ||
|
||
async function getContentFrontmatter() { | ||
let fm = {} | ||
|
||
const paths = await globby(join(docsPath, './content/**/*.md*')) | ||
paths.forEach(path => { | ||
const contents = fs.readFileSync(path, 'utf8') | ||
const fmContents = frontMatter(contents) | ||
fm[path.replace(join(docsPath, './content'), '').replace(/(\/index)?\.mdx?/,'')] = fmContents['attributes'] | ||
}) | ||
return fm | ||
} | ||
|
||
module.exports = { | ||
getContentFrontmatter, | ||
getNavigationLinks | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters