1
0
mirror of synced 2025-12-21 10:57:10 -05:00

set basePath as constant

This commit is contained in:
Sarah Schneider
2021-04-09 09:15:37 -04:00
parent a2e2017e57
commit a08cd650d4
2 changed files with 4 additions and 8 deletions

View File

@@ -2,13 +2,9 @@ const fs = require('fs').promises
const path = require('path')
const Page = require('./page')
const { sortBy } = require('lodash')
let basePath
const basePath = path.posix.join(__dirname, '..', 'content')
module.exports = async function createTree (originalPath, langObj) {
// Do not reset this value on recursive runs.
if (!basePath) basePath = originalPath
// On recursive runs, this is processing page.children items in `/<link>` format.
// If the path exists as is, assume this is a directory with a child index.md.
// Otherwise, assume it's a child .md file and add `.md` to the path.
@@ -21,7 +17,7 @@ module.exports = async function createTree (originalPath, langObj) {
}
const relativePath = filepath.replace(`${basePath}/`, '')
const localizedBasePath = path.join(__dirname, '..', langObj.dir, 'content')
const localizedBasePath = path.posix.join(__dirname, '..', langObj.dir, 'content')
// Initialize the Page! This is where the file reads happen.
const page = await Page.init({
@@ -48,7 +44,7 @@ module.exports = async function createTree (originalPath, langObj) {
if (item.page.children) {
item.childPages = sortBy(
(await Promise.all(item.page.children
.map(async (child) => await createTree(path.join(originalPath, child), langObj))))
.map(async (child) => await createTree(path.posix.join(originalPath, child), langObj))))
.filter(Boolean),
// Sort by the ordered array of `children` in the frontmatter.
item.page.children