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 path = require('path')
const Page = require('./page') const Page = require('./page')
const { sortBy } = require('lodash') const { sortBy } = require('lodash')
const basePath = path.posix.join(__dirname, '..', 'content')
let basePath
module.exports = async function createTree (originalPath, langObj) { 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. // 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. // 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. // 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 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. // Initialize the Page! This is where the file reads happen.
const page = await Page.init({ const page = await Page.init({
@@ -48,7 +44,7 @@ module.exports = async function createTree (originalPath, langObj) {
if (item.page.children) { if (item.page.children) {
item.childPages = sortBy( item.childPages = sortBy(
(await Promise.all(item.page.children (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), .filter(Boolean),
// Sort by the ordered array of `children` in the frontmatter. // Sort by the ordered array of `children` in the frontmatter.
item.page.children item.page.children

View File

@@ -3,7 +3,7 @@ const languages = require('./languages')
const versions = Object.keys(require('./all-versions')) const versions = Object.keys(require('./all-versions'))
const createTree = require('./create-tree') const createTree = require('./create-tree')
const nonEnterpriseDefaultVersion = require('./non-enterprise-default-version') const nonEnterpriseDefaultVersion = require('./non-enterprise-default-version')
const englishPath = path.join(__dirname, '..', 'content') const englishPath = path.posix.join(__dirname, '..', 'content')
/** /**
* We only need to initialize pages _once per language_ since pages don't change per version. So we do that * We only need to initialize pages _once per language_ since pages don't change per version. So we do that