2021-08-12 03:11:35 +03:00
|
|
|
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))
|
2021-03-31 02:53:47 +03:00
|
|
|
|
|
|
|
const docsPath = join(__dirname, '../../docs')
|
|
|
|
|
|
|
|
function collectNavLinks(links) {
|
|
|
|
let foundLinks = []
|
2021-04-01 20:56:12 +03:00
|
|
|
for (const link of links) {
|
2021-03-31 02:53:47 +03:00
|
|
|
foundLinks.push({
|
|
|
|
title: link['title'],
|
|
|
|
url: link['url']
|
|
|
|
})
|
2021-04-01 20:56:12 +03:00
|
|
|
if (link['children']) {
|
2021-03-31 02:53:47 +03:00
|
|
|
foundLinks = foundLinks.concat(collectNavLinks(link['children']))
|
|
|
|
}
|
2021-04-01 20:56:12 +03:00
|
|
|
}
|
2021-03-31 02:53:47 +03:00
|
|
|
return foundLinks
|
|
|
|
}
|
|
|
|
|
2021-08-12 03:11:35 +03:00
|
|
|
export function getNavigationLinks() {
|
2021-03-31 02:53:47 +03:00
|
|
|
const nav = yaml.load(fs.readFileSync(join(docsPath, './src/@primer/gatsby-theme-doctocat/nav.yml'), 'utf8'))
|
|
|
|
return collectNavLinks(nav)
|
|
|
|
}
|
|
|
|
|
2021-08-12 03:11:35 +03:00
|
|
|
export async function getContentFrontmatter() {
|
2021-04-01 20:56:12 +03:00
|
|
|
const fm = {}
|
2021-03-31 02:53:47 +03:00
|
|
|
|
|
|
|
const paths = await globby(join(docsPath, './content/**/*.md*'))
|
2021-04-01 20:56:12 +03:00
|
|
|
for (const path of paths) {
|
2021-03-31 02:53:47 +03:00
|
|
|
const contents = fs.readFileSync(path, 'utf8')
|
|
|
|
const fmContents = frontMatter(contents)
|
2021-04-01 20:56:12 +03:00
|
|
|
fm[path.replace(join(docsPath, './content'), '').replace(/(\/index)?\.mdx?/, '')] = fmContents['attributes']
|
|
|
|
}
|
2021-03-31 02:53:47 +03:00
|
|
|
return fm
|
|
|
|
}
|