Skip to content

Commit 5a84395

Browse files
committed
Refactor resolveContentFileFromId in generateSeoFiles.mjs for accurate content path resolution #7761
1 parent 63a8ffe commit 5a84395

1 file changed

Lines changed: 8 additions & 22 deletions

File tree

buildScripts/generateSeoFiles.mjs

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ import {Command} from 'commander/esm.mjs';
44
import {execSync} from 'child_process';
55
import {fileURLToPath} from 'url';
66

7-
const ROOT_DIR = process.cwd();
8-
const LEARN_DIR = path.resolve(ROOT_DIR, 'learn');
9-
const PORTAL_DIR = path.resolve(ROOT_DIR, 'apps/portal');
10-
const TREE_FILE_PATH = path.join(LEARN_DIR, 'tree.json');
11-
const DEFAULT_BASE_PATH = '/learn';
12-
const SUPPORTED_DOC_EXTENSIONS = ['.md', '.mdx', '.json'];
7+
const ROOT_DIR = process.cwd();
8+
const LEARN_DIR = path.resolve(ROOT_DIR, 'learn');
9+
const PORTAL_DIR = path.resolve(ROOT_DIR, 'apps/portal');
10+
const TREE_FILE_PATH = path.join(LEARN_DIR, 'tree.json');
11+
const DEFAULT_BASE_PATH = '/learn';
1312

1413
// Top-level routes that don't map to content files
1514
const TOP_LEVEL_ROUTES = [
@@ -71,23 +70,10 @@ async function loadTreeNodes() {
7170
* @returns {Promise<String|null>} The absolute file path if found, otherwise null.
7271
*/
7372
async function resolveContentFileFromId(id) {
74-
const segments = id.split('/').filter(Boolean);
73+
const filePath = path.join(LEARN_DIR, id + '.md');
7574

76-
const directCandidates = SUPPORTED_DOC_EXTENSIONS.map(extension => (
77-
path.join(LEARN_DIR, ...segments) + extension
78-
));
79-
80-
const nestedCandidates = SUPPORTED_DOC_EXTENSIONS.flatMap(extension => ([
81-
path.join(LEARN_DIR, ...segments, `README${extension}`),
82-
path.join(LEARN_DIR, ...segments, `index${extension}`)
83-
]));
84-
85-
const candidates = [...directCandidates, ...nestedCandidates];
86-
87-
for (const candidate of candidates) {
88-
if (await fs.pathExists(candidate)) {
89-
return candidate;
90-
}
75+
if (await fs.pathExists(filePath)) {
76+
return filePath;
9177
}
9278

9379
return null;

0 commit comments

Comments
 (0)