Skip to content

Commit 5b45bf0

Browse files
authored
Merge pull request #11703 from github/repo-sync
repo sync
2 parents 59adb99 + 6c51d61 commit 5b45bf0

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Diff for: lib/create-tree.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,22 @@ import fs from 'fs/promises'
44
import Page from './page.js'
55
const __dirname = path.dirname(fileURLToPath(import.meta.url))
66

7+
// Module level cache
8+
const _basePaths = new Map()
9+
// Return a full directory based on __dirname from a specific language directory.
10+
// This function is memoized with a simple global cache object.
11+
function getBasePath(directory) {
12+
if (!_basePaths.has(directory)) {
13+
_basePaths.set(directory, path.posix.join(__dirname, '..', directory, 'content'))
14+
console.log(_basePaths.get(directory))
15+
}
16+
return _basePaths.get(directory)
17+
}
18+
719
export default async function createTree(originalPath, langObj) {
820
// This basePath definition is needed both here and in lib/page-data.js because this
921
// function runs recursively, and the value for originalPath changes on recursive runs.
10-
const basePath = path.posix.join(__dirname, '..', langObj.dir, 'content')
22+
const basePath = getBasePath(langObj.dir)
1123

1224
// On recursive runs, this is processing page.children items in `/<link>` format.
1325
// If the path exists as is, assume this is a directory with a child index.md.

0 commit comments

Comments
 (0)