1
1
mirror of https://github.com/primer/css.git synced 2024-11-25 18:26:14 +03:00
css/__tests__/utils/docs.js
dependabot[bot] f27faef3eb
Bump globby from 11.0.4 to 12.0.0 (#1515)
* Bump globby from 11.0.4 to 12.0.0

Bumps [globby](https://github.com/sindresorhus/globby) from 11.0.4 to 12.0.0.
- [Release notes](https://github.com/sindresorhus/globby/releases)
- [Commits](https://github.com/sindresorhus/globby/compare/v11.0.4...v12.0.0)

---
updated-dependencies:
- dependency-name: globby
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* Import globby

* Converting tests

* Ignore docs test

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jon Rohan <yes@jonrohan.codes>
2021-08-11 17:11:35 -07:00

42 lines
1.1 KiB
JavaScript

import fs from 'fs'
import frontMatter from 'front-matter'
import yaml from 'js-yaml'
import {globby} from 'globby'
import { fileURLToPath } from 'url'
import {join, dirname} from 'path'
const __dirname = dirname(fileURLToPath(import.meta.url))
const docsPath = join(__dirname, '../../docs')
function collectNavLinks(links) {
let foundLinks = []
for (const link of links) {
foundLinks.push({
title: link['title'],
url: link['url']
})
if (link['children']) {
foundLinks = foundLinks.concat(collectNavLinks(link['children']))
}
}
return foundLinks
}
export function getNavigationLinks() {
const nav = yaml.load(fs.readFileSync(join(docsPath, './src/@primer/gatsby-theme-doctocat/nav.yml'), 'utf8'))
return collectNavLinks(nav)
}
export async function getContentFrontmatter() {
const fm = {}
const paths = await globby(join(docsPath, './content/**/*.md*'))
for (const path of paths) {
const contents = fs.readFileSync(path, 'utf8')
const fmContents = frontMatter(contents)
fm[path.replace(join(docsPath, './content'), '').replace(/(\/index)?\.mdx?/, '')] = fmContents['attributes']
}
return fm
}