From 50975a2e4e57d125731fb14ca58783b5ce552b16 Mon Sep 17 00:00:00 2001 From: Dr-Electron Date: Thu, 7 Sep 2023 10:42:54 +0200 Subject: [PATCH 1/3] Add draft for version redirects --- docusaurus.config.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docusaurus.config.js b/docusaurus.config.js index ce8e84d0434..4e73944ad22 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -375,6 +375,16 @@ module.exports = async () => { }, ]; + // Version redirects are only used to asign path with the actual version it to the "current" version + const versionRedirects = [ + { + from: '/identity.rs/0.6', + to: '/identity.rs', + }, + ]; + + redirects.push(...versionRedirects); + for (const redirect of redirects) { if (existingPath.includes(redirect.to)) { return existingPath.replace(redirect.to, redirect.from); From 1d112bbb0dfcb6f15d08bfef136e535dc65292cc Mon Sep 17 00:00:00 2001 From: Dr-Electron Date: Sat, 30 Sep 2023 22:47:27 +0200 Subject: [PATCH 2/3] Implement version redirects --- docusaurus.config.js | 22 ++++++++++++---------- src/utils/pluginConfigGenerators.js | 27 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/docusaurus.config.js b/docusaurus.config.js index 4e73944ad22..e325f58c523 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -5,6 +5,11 @@ const common = require('./common/docusaurus.config'); const contentConfigs = require('./contentPlugins'); const articleRedirectsFile = require('./articleRedirects'); const switcherConfig = require('./switcherConfig'); +const { + buildPluginsConfig, + maintainPluginsConfig, +} = require('./versionedConfig'); +const { createMainVersionRedirects } = require('./src/utils/pluginConfigGenerators'); module.exports = async () => { const contentPlugins = await Promise.all( @@ -13,6 +18,10 @@ module.exports = async () => { ).map(async (contentConfig) => await create_doc_plugin(contentConfig)), ); + + const buildMainVersionRedirects = createMainVersionRedirects(buildPluginsConfig); + const maintainMainVersionRedirects = createMainVersionRedirects(maintainPluginsConfig); + // Get tutorials const additionalPlugins = await glob(['tutorials']); @@ -281,6 +290,9 @@ module.exports = async () => { // directory redirects - only added for directories that didn't have a direct match createRedirects(existingPath) { const redirects = [ + // Version redirects are only used to asign paths with the actual version to the "current" version + ...buildMainVersionRedirects, + ...maintainMainVersionRedirects, { from: '/develop/nodes/rest-api', to: '/apis/core/v1', @@ -375,16 +387,6 @@ module.exports = async () => { }, ]; - // Version redirects are only used to asign path with the actual version it to the "current" version - const versionRedirects = [ - { - from: '/identity.rs/0.6', - to: '/identity.rs', - }, - ]; - - redirects.push(...versionRedirects); - for (const redirect of redirects) { if (existingPath.includes(redirect.to)) { return existingPath.replace(redirect.to, redirect.from); diff --git a/src/utils/pluginConfigGenerators.js b/src/utils/pluginConfigGenerators.js index 44b4a6303ad..7321533ee3b 100644 --- a/src/utils/pluginConfigGenerators.js +++ b/src/utils/pluginConfigGenerators.js @@ -62,6 +62,32 @@ function generatePluginConfig(pluginConfig, basePath) { }); } +/** + * Generate directs versioned links to the main version. + * @param {import('../common/components/Switcher').Doc[]} versionedConfig - An array of versioned plugin configurations. + * @returns {Array} - An array of redirects. + */ +function createMainVersionRedirects(versionedConfig) { + redirects = [] + for (const doc of versionedConfig) { + if (doc.versions.length > 1){ + + // Find main version + const mainVersion = findMainVersion(doc); + + // TODO: This could be removed once we don't use points in paths anymore. + const routeBasePath = doc.routeBasePath ? doc.routeBasePath : doc.id; + + redirects.push({ + from: '/' + routeBasePath + '/' + mainVersion.label, + to: '/' + routeBasePath, + }); + } + } + + return redirects; +} + /** * Generate the switcher config from the versioned config. * @param {import('../common/components/Switcher').Doc[]} pluginConfig @@ -89,4 +115,5 @@ function generateSwitcherConfig(pluginConfig) { module.exports = { generatePluginConfig, generateSwitcherConfig, + createMainVersionRedirects, }; From 3976914162159fe14927e8b607de232a34748d46 Mon Sep 17 00:00:00 2001 From: Dr-Electron Date: Sat, 30 Sep 2023 22:50:59 +0200 Subject: [PATCH 3/3] Format --- docusaurus.config.js | 12 ++++++++---- src/utils/pluginConfigGenerators.js | 5 ++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/docusaurus.config.js b/docusaurus.config.js index e325f58c523..bb3c22ecf7a 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -9,7 +9,9 @@ const { buildPluginsConfig, maintainPluginsConfig, } = require('./versionedConfig'); -const { createMainVersionRedirects } = require('./src/utils/pluginConfigGenerators'); +const { + createMainVersionRedirects, +} = require('./src/utils/pluginConfigGenerators'); module.exports = async () => { const contentPlugins = await Promise.all( @@ -18,9 +20,11 @@ module.exports = async () => { ).map(async (contentConfig) => await create_doc_plugin(contentConfig)), ); - - const buildMainVersionRedirects = createMainVersionRedirects(buildPluginsConfig); - const maintainMainVersionRedirects = createMainVersionRedirects(maintainPluginsConfig); + const buildMainVersionRedirects = + createMainVersionRedirects(buildPluginsConfig); + const maintainMainVersionRedirects = createMainVersionRedirects( + maintainPluginsConfig, + ); // Get tutorials const additionalPlugins = await glob(['tutorials']); diff --git a/src/utils/pluginConfigGenerators.js b/src/utils/pluginConfigGenerators.js index 7321533ee3b..b94aad4fdc8 100644 --- a/src/utils/pluginConfigGenerators.js +++ b/src/utils/pluginConfigGenerators.js @@ -68,10 +68,9 @@ function generatePluginConfig(pluginConfig, basePath) { * @returns {Array} - An array of redirects. */ function createMainVersionRedirects(versionedConfig) { - redirects = [] + redirects = []; for (const doc of versionedConfig) { - if (doc.versions.length > 1){ - + if (doc.versions.length > 1) { // Find main version const mainVersion = findMainVersion(doc);