Skip to content

Commit

Permalink
fix: docusaurus-version should allow duplicate id in different subfol…
Browse files Browse the repository at this point in the history
…der (#1125)

* fix: docusaurus-version should not be confused for duplicate ids in different subfolder

* nits

* nits

* remove log
  • Loading branch information
endiliey authored and yangshun committed Nov 23, 2018
1 parent 579cc61 commit 1e83613
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
16 changes: 13 additions & 3 deletions v1/lib/server/versionFallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ files.forEach(file => {
);
}

if (!(metadata.original_id in available)) {
available[metadata.original_id] = new Set();
}
// The version will be between "version-" and "-<metadata.original_id>"
// e.g. version-1.0.0-beta.2-doc1 => 1.0.0-beta.2
// e.g. version-1.0.0-doc2 => 1.0.0
Expand All @@ -87,6 +84,19 @@ files.forEach(file => {
metadata.id.indexOf('version-') + 8, // version- is 8 characters
metadata.id.lastIndexOf(`-${metadata.original_id}`),
);

// the original_id should be namespaced according to subdir to allow duplicate id in different subfolder
const subDir = utils.getSubDir(
file,
path.join(versionFolder, `version-${version}`),
);
if (subDir) {
metadata.original_id = `${subDir}/${metadata.original_id}`;
}

if (!(metadata.original_id in available)) {
available[metadata.original_id] = new Set();
}
available[metadata.original_id].add(version);

if (!(version in versionFiles)) {
Expand Down
12 changes: 6 additions & 6 deletions v1/lib/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ files.forEach(file => {
metadata.title = metadata.id;
}

if (!versionFallback.diffLatestDoc(file, metadata.id)) {
const docsDir = path.join(CWD, '../', readMetadata.getDocsPath());
const subDir = utils.getSubDir(file, docsDir);
const originalId = subDir ? `${subDir}/${metadata.id}` : metadata.id;
if (!versionFallback.diffLatestDoc(file, originalId)) {
return;
}

metadata.original_id = metadata.id;
metadata.id = `version-${version}-${metadata.id}`;

const docsDir = path.join(CWD, '../', readMetadata.getDocsPath());
const subDir = utils.getSubDir(file, docsDir);
metadata.original_id = originalId;
metadata.id = `version-${version}-${originalId}`;
const targetFile = subDir
? `${versionFolder}/${subDir}/${path.basename(file)}`
: `${versionFolder}/${path.basename(file)}`;
Expand Down

0 comments on commit 1e83613

Please sign in to comment.