diff --git a/lib/server/readMetadata.js b/lib/server/readMetadata.js index 61e2582e5672f..f6cd8aad8d81e 100644 --- a/lib/server/readMetadata.js +++ b/lib/server/readMetadata.js @@ -162,13 +162,11 @@ function processMetadata(file) { throw new Error('Document id cannot include "/".'); } - // if file is located in subdirectory, - // it will have the directory name appended to it's id - const relativeFile = path.relative( - path.join(CWD, '../', getDocsPath()), - file + // If a doc file is located in a subdirectory, prepend the subdir to it's ID + // Example: `docs/projectA/test.md` with 'test' ID is changed to `projectA/test` + const curDir = path.dirname( + path.relative(path.join(CWD, '../', getDocsPath()), file) ); - const curDir = path.dirname(relativeFile); if (curDir !== '.') { metadata.id = curDir + '/' + metadata.id; metadata.source = curDir + '/' + metadata.source;