Skip to content

Commit

Permalink
Add shimmer/iota redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr-Electron committed Oct 9, 2023
1 parent 344fb1b commit 0bdb1bd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
7 changes: 3 additions & 4 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const {
maintainPluginsConfig,
} = require('./versionedConfig');
const {
createMainVersionRedirects,
createVersionRedirects,
} = require('./src/utils/pluginConfigGenerators');

module.exports = async () => {
Expand All @@ -20,9 +20,8 @@ module.exports = async () => {
).map(async (contentConfig) => await create_doc_plugin(contentConfig)),
);

const buildMainVersionRedirects =
createMainVersionRedirects(buildPluginsConfig);
const maintainMainVersionRedirects = createMainVersionRedirects(
const buildMainVersionRedirects = createVersionRedirects(buildPluginsConfig);
const maintainMainVersionRedirects = createVersionRedirects(
maintainPluginsConfig,
);

Expand Down
37 changes: 29 additions & 8 deletions src/utils/pluginConfigGenerators.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('path');

const MAIN_BADGE = 'Shimmer';
const MAIN_BADGE = 'IOTA';

/**
* Find main version of a plugin by resolving it to the first version with the corresponding batch.
Expand Down Expand Up @@ -60,21 +60,42 @@ function generatePluginConfig(pluginConfig, basePath) {
* @param {import('../common/components/Switcher').Doc[]} versionedConfig - An array of versioned plugin configurations.
* @returns {Array} - An array of redirects.
*/
function createMainVersionRedirects(versionedConfig) {
function createVersionRedirects(versionedConfig) {
redirects = [];
for (const doc of versionedConfig) {
if (doc.versions.length > 1) {
// Find main version
const mainVersion = findMainVersion(doc);
// Find main version
const mainVersion = findMainVersion(doc);
const mainShimmerVersion = findMainVersion(doc, 'Shimmer');

// TODO: This could be removed once we don't use points in paths anymore.
const routeBasePath = doc.routeBasePath ? doc.routeBasePath : doc.id;
// TODO: This could be removed once we don't use points in paths anymore.
const routeBasePath = doc.routeBasePath ? doc.routeBasePath : doc.id;

if (mainVersion) {
// Redirect deep version link to route base path
redirects.push({
from: '/' + routeBasePath + '/' + mainVersion.label,
to: '/' + routeBasePath,
});

// Redirect to main IOTA version
redirects.push({
from: '/' + routeBasePath + '/iota',
to: '/' + routeBasePath,
});
}

if (mainShimmerVersion && mainShimmerVersion !== mainVersion)
// Redirect to main Shimmer version
redirects.push({
from: '/' + routeBasePath + '/shimmer/',
to: '/' + routeBasePath + '/' + mainShimmerVersion.label,
});
else if (mainShimmerVersion === mainVersion)
// Redirect to main Shimmer version if it is the main version
redirects.push({
from: '/' + routeBasePath + '/shimmer/',
to: '/' + routeBasePath,
});
}

return redirects;
Expand Down Expand Up @@ -107,6 +128,6 @@ function generateSwitcherConfig(pluginConfig) {
module.exports = {
generatePluginConfig,
generateSwitcherConfig,
createMainVersionRedirects,
createVersionRedirects,
MAIN_BADGE,
};

0 comments on commit 0bdb1bd

Please sign in to comment.