Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/create-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,22 @@ import fs from 'fs/promises'
import Page from './page.js'
const __dirname = path.dirname(fileURLToPath(import.meta.url))

// Module level cache
const _basePaths = new Map()
// Return a full directory based on __dirname from a specific language directory.
// This function is memoized with a simple global cache object.
function getBasePath(directory) {
if (!_basePaths.has(directory)) {
_basePaths.set(directory, path.posix.join(__dirname, '..', directory, 'content'))
console.log(_basePaths.get(directory))
}
return _basePaths.get(directory)
}

export default async function createTree(originalPath, langObj) {
// This basePath definition is needed both here and in lib/page-data.js because this
// function runs recursively, and the value for originalPath changes on recursive runs.
const basePath = path.posix.join(__dirname, '..', langObj.dir, 'content')
const basePath = getBasePath(langObj.dir)

// 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.
Expand Down