set basePath as constant
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -3,7 +3,7 @@ const languages = require('./languages')
|
||||
const versions = Object.keys(require('./all-versions'))
|
||||
const createTree = require('./create-tree')
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user