Skip to content

Commit

Permalink
Fix versioned_docs and skip-next-release relative path issue by addin…
Browse files Browse the repository at this point in the history
…g versioned_source to metadata
  • Loading branch information
josephMG committed Sep 9, 2020
1 parent 77db144 commit 04041d6
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
id: 'en-doc1',
title: 'Document 1',
source: 'doc1.md',
versioned_source: 'doc1.md',
version: 'next',
permalink: 'docs/en/next/doc1.html',
localized_id: 'doc1',
Expand All @@ -25,6 +26,7 @@ module.exports = {
id: 'en-doc2',
title: 'Document 2',
source: 'doc2.md',
versioned_source: 'doc2.md',
version: 'next',
permalink: 'docs/en/next/doc2.html',
localized_id: 'doc2',
Expand All @@ -40,6 +42,7 @@ module.exports = {
id: 'en-doc3',
title: 'Document 3',
source: 'doc3.md',
versioned_source: 'doc3.md',
version: 'next',
permalink: 'docs/en/next/doc3.html',
localized_id: 'doc3',
Expand All @@ -55,6 +58,7 @@ module.exports = {
id: 'en-reflinks',
title: 'Reference Links',
source: 'reflinks.md',
versioned_source: 'reflinks.md',
version: 'next',
permalink: 'docs/en/next/reflinks.html',
localized_id: 'reflinks',
Expand All @@ -70,6 +74,7 @@ module.exports = {
id: 'ko-doc1',
title: '문서 1',
source: 'doc1.md',
versioned_source: 'doc1.md',
version: 'next',
permalink: 'docs/ko/next/doc1.html',
localized_id: 'doc1',
Expand All @@ -84,6 +89,7 @@ module.exports = {
id: 'ko-doc2',
title: '문서 2',
source: 'doc2.md',
versioned_source: 'doc2.md',
version: 'next',
permalink: 'docs/ko/next/doc2.html',
localized_id: 'doc2',
Expand All @@ -99,6 +105,7 @@ module.exports = {
original_id: 'doc1',
title: 'Document 1',
source: 'version-1.0.0/doc1.md',
versioned_source: 'version-1.0.0/doc1.md',
version: '1.0.0',
permalink: 'docs/en/doc1.html',
localized_id: 'version-1.0.0-doc1',
Expand All @@ -114,6 +121,7 @@ module.exports = {
original_id: 'doc2',
title: 'Document 2',
source: 'version-1.0.0/doc2.md',
versioned_source: 'version-1.0.0/doc2.md',
version: '1.0.0',
permalink: 'docs/en/doc2.html',
localized_id: 'version-1.0.0-doc2',
Expand All @@ -128,6 +136,7 @@ module.exports = {
id: 'ko-version-1.0.0-doc1',
title: '문서 1',
source: 'version-1.0.0/doc1.md',
versioned_source: 'version-1.0.0/doc1.md',
version: '1.0.0',
permalink: 'docs/ko/doc1.html',
localized_id: 'version-1.0.0-doc1',
Expand All @@ -142,6 +151,7 @@ module.exports = {
id: 'ko-version-1.0.0-doc2',
title: '문서 2',
source: 'version-1.0.0/doc2.md',
versioned_source: 'version-1.0.0/doc2.md',
version: '1.0.0',
permalink: 'docs/ko/doc2.html',
localized_id: 'version-1.0.0-doc2',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Array [
"source": "doc1.md",
"title": "Document 1",
"version": "next",
"versioned_source": "doc1.md",
},
"type": "LINK",
},
Expand All @@ -37,6 +38,7 @@ Array [
"source": "doc2.md",
"title": "Document 2",
"version": "next",
"versioned_source": "doc2.md",
},
"type": "LINK",
},
Expand All @@ -61,6 +63,7 @@ Array [
"source": "doc3.md",
"title": "Document 3",
"version": "next",
"versioned_source": "doc3.md",
},
"type": "LINK",
},
Expand All @@ -79,6 +82,7 @@ Array [
"source": "reflinks.md",
"title": "Reference Links",
"version": "next",
"versioned_source": "reflinks.md",
},
"type": "LINK",
},
Expand Down
1 change: 1 addition & 0 deletions packages/docusaurus-1.x/lib/server/__tests__/docs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ describe('mdToHtmlify', () => {
id: 'subdir-doc3',
title: 'Document 3',
source: 'subdir/doc3.md',
versioned_source: 'subdir/doc3.md',
permalink: 'docs/subdir/doc3.html',
language: 'en',
},
Expand Down
15 changes: 9 additions & 6 deletions packages/docusaurus-1.x/lib/server/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,20 @@ function mdToHtmlify(oldContent, mdToHtml, metadata, siteConfig) {
let mdMatch = mdRegex.exec(modifiedLine);
while (mdMatch !== null) {
/* Replace it to correct html link */
const docsSource = metadata.version
? metadata.source.replace(/version-.*?\//, '')
: metadata.source;
const docsSource =
metadata.version && readMetadata.shouldGenerateNextReleaseDocs()
? metadata.versioned_source.replace(/version-.*?\//, '')
: metadata.versioned_source;
let htmlLink =
mdToHtml[resolve(docsSource, mdMatch[1])] || mdToHtml[mdMatch[1]];
if (htmlLink) {
htmlLink = getPath(htmlLink, siteConfig.cleanUrl);
htmlLink = htmlLink.replace('/en/', `/${metadata.language}/`);
htmlLink = htmlLink.replace(
'/VERSION/',
metadata.version && metadata.version !== env.versioning.latestVersion
/\/VERSION\/(next\/)?/,
metadata.version &&
metadata.version !== env.versioning.latestVersion &&
readMetadata.shouldGenerateNextReleaseDocs()
? `/${metadata.version}/`
: '/',
);
Expand All @@ -95,7 +98,7 @@ function mdToHtmlify(oldContent, mdToHtml, metadata, siteConfig) {

if (mdBrokenLinks.length) {
console.log(
`[WARN] unresolved links in file '${metadata.source}' >`,
`[WARN] unresolved links in file '${metadata.versioned_source}' >`,
mdBrokenLinks,
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-1.x/lib/server/metadataUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function mdToHtml(Metadata, siteConfig) {
const result = {};
Object.keys(Metadata).forEach((id) => {
const metadata = Metadata[id];
if (metadata.language !== 'en' || metadata.original_id) {
if (metadata.language !== 'en') {
return;
}
let htmlLink = baseUrl + metadata.permalink.replace('/next/', '/');
Expand All @@ -81,7 +81,7 @@ function mdToHtml(Metadata, siteConfig) {
} else {
htmlLink = htmlLink.replace(docsRegex, `${baseDocsPart}VERSION/`);
}
result[metadata.source] = htmlLink;
result[metadata.versioned_source] = htmlLink;
});
return result;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/docusaurus-1.x/lib/server/readMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ function processMetadata(file, refDir) {
metadata.source = subDir
? `${subDir}/${path.basename(file)}`
: path.basename(file);
metadata.versioned_source = metadata.source;

if (!metadata.title) {
metadata.title = metadata.id;
Expand Down Expand Up @@ -426,6 +427,7 @@ module.exports = {
getDocsPath,
readSidebar,
processMetadata,
shouldGenerateNextReleaseDocs,
generateMetadataDocs,
generateMetadataBlog,
};
4 changes: 4 additions & 0 deletions packages/docusaurus-1.x/lib/server/versionFallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ function processVersionMetadata(file, version, useVersion, language) {
metadata.id = (env.translation.enabled ? `${language}-` : '') + metadata.id;
metadata.language = language;
metadata.version = version;
metadata.versioned_source = metadata.source.replace(
`version-${useVersion}`,
`version-${version}`,
);

return metadata;
}
Expand Down

0 comments on commit 04041d6

Please sign in to comment.