Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor versioning #1235

Merged
merged 6 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion src/components/HomeLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export default function HomeLayout() {
retrieve IOTA messages and data in real time.
</p>
<Link
to='chronicle/getting_started'
to='/chronicle/welcome'
className='nodes__button button button--outline button--primary'
>
Try the permanode framework
Expand Down
1 change: 0 additions & 1 deletion src/components/Switcher/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export type Version = Omit<Item, 'id'> & {
export type Doc = Item & {
subsection: string;
versions: Version[];
defaultVersion?: string;
};

export type Sidebar = {
Expand Down
65 changes: 41 additions & 24 deletions src/utils/pluginConfigGenerators.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
const path = require('path');

const MAIN_BADGE = 'IOTA';

/**
* Find main version of a plugin by resolving it to the default version or the first version configured.
* Find main version of a plugin by resolving it to the first version with the corresponding batch.
* @param {import('../common/components/Switcher').Doc} plugin
*/
function findMainVersion(plugin) {
let mainVersion = plugin.versions[0];
if (plugin.defaultVersion) {
const foundVersion = plugin.versions.find(
(version) => version.label === plugin.defaultVersion,
);
if (!foundVersion)
throw `Default version ${plugin.defaultVersion} of doc ${plugin.label} not found.`;

mainVersion = foundVersion;
}

return mainVersion;
function findMainVersion(plugin, badge = MAIN_BADGE) {
return plugin.versions.find((version) =>
version.badges.some((b) => b.includes(badge)),
);
}

/**
Expand All @@ -26,7 +19,7 @@ function findMainVersion(plugin) {
*/
function generatePluginConfig(pluginConfig, basePath) {
return pluginConfig.flatMap((doc) => {
const mainVersion = findMainVersion(doc);
const mainVersion = findMainVersion(doc) ?? doc.versions[0];

return doc.versions.map((version) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down Expand Up @@ -67,21 +60,44 @@ 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) {
if (doc.versions.length > 1) {
// 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 + '/' + mainVersion.label,
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 All @@ -93,7 +109,7 @@ function createMainVersionRedirects(versionedConfig) {
*/
function generateSwitcherConfig(pluginConfig) {
return pluginConfig.map((plugin) => {
const mainVersion = findMainVersion(plugin);
const mainVersion = findMainVersion(plugin) ?? plugin.versions[0];
return {
...plugin,
id:
Expand All @@ -114,5 +130,6 @@ function generateSwitcherConfig(pluginConfig) {
module.exports = {
generatePluginConfig,
generateSwitcherConfig,
createMainVersionRedirects,
createVersionRedirects,
MAIN_BADGE,
};
16 changes: 6 additions & 10 deletions src/utils/useSwitcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
Sidebar,
Item,
} from '../common/components/Switcher';
import { MAIN_BADGE } from './pluginConfigGenerators';

export type GlobalPluginData = DocsGlobalPluginData & {
globalSidebars?: {
Expand Down Expand Up @@ -133,17 +134,12 @@ export default function useSwitcher(): SwitcherProps {
};
});

// Resolve the doc link to the default version or the first version configured.
// Resolve the doc link to the first MAIN_BADGE version.
let to = versionLinks[0].to;
if (doc.defaultVersion) {
const foundVersion = versionLinks.find(
(version) => version.id === doc.defaultVersion,
);
if (!foundVersion)
throw `Default version ${doc.defaultVersion} of doc ${doc.label} not found.`;

to = foundVersion.to;
}
const foundVersion = versionLinks.find((version) =>
version.badges.some((b) => b.includes(MAIN_BADGE)),
);
if (foundVersion) to = foundVersion.to;

let active = false;
if (current.doc && doc.id === current.doc.id) {
Expand Down
44 changes: 22 additions & 22 deletions versionedConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exports.buildPluginsConfig = [
versions: [
{
label: '1.0',
badges: ['Shimmer'],
badges: ['IOTA', 'Shimmer'],
//overriding default exclude array to include the python api's classes with _ at the beginning
//but still exclude any _admonitions
exclude: [
Expand All @@ -29,7 +29,7 @@ exports.buildPluginsConfig = [
subsection: 'build-layer-2',
versions: [
{
label: '0.7',
label: 'v1.0.0-rc.6',
badges: ['Shimmer'],
},
],
Expand All @@ -42,7 +42,7 @@ exports.buildPluginsConfig = [
subsection: 'build-layer-2',
versions: [
{
label: '0.7',
label: 'v1.0.0-rc.6',
badges: ['Shimmer'],
},
],
Expand All @@ -55,7 +55,7 @@ exports.buildPluginsConfig = [
subsection: 'build-layer-2',
versions: [
{
label: '0.7',
label: 'v1.0.0-rc.6',
badges: ['Shimmer'],
},
],
Expand All @@ -70,7 +70,7 @@ exports.buildPluginsConfig = [
versions: [
{
label: '1.0-rc.1',
badges: ['IOTA/Shimmer'],
badges: ['IOTA', 'Shimmer'],
},
{
label: '0.6',
Expand All @@ -90,10 +90,6 @@ exports.buildPluginsConfig = [
icon: 'IotaCore',
subsection: 'build-layer-1',
versions: [
{
label: '1.4',
badges: ['IOTA'],
},
{
label: '2.0-rc.7',
badges: ['Shimmer'],
Expand All @@ -102,6 +98,10 @@ exports.buildPluginsConfig = [
'banners/pre-sdk-libs-deprecated.mdx',
),
},
{
label: '1.4',
badges: ['IOTA'],
},
],
},
{
Expand Down Expand Up @@ -130,10 +130,6 @@ exports.buildPluginsConfig = [
icon: 'Wallet',
subsection: 'build-layer-1',
versions: [
{
label: '0.1',
badges: ['IOTA'],
},
{
label: '1.0-rc.6',
badges: ['Shimmer'],
Expand All @@ -142,6 +138,10 @@ exports.buildPluginsConfig = [
'banners/pre-sdk-libs-deprecated.mdx',
),
},
{
label: '0.1',
badges: ['IOTA'],
},
],
},
{
Expand All @@ -154,7 +154,7 @@ exports.buildPluginsConfig = [
versions: [
{
label: '1.1',
badges: ['IOTA/Shimmer'],
badges: ['IOTA', 'Shimmer'],
},
],
},
Expand All @@ -167,7 +167,7 @@ exports.buildPluginsConfig = [
versions: [
{
label: '',
badges: ['IOTA/Shimmer'],
badges: ['IOTA', 'Shimmer'],
docItemComponent: '@theme/ApiItem',
},
],
Expand Down Expand Up @@ -199,7 +199,7 @@ exports.buildPluginsConfig = [
versions: [
{
label: '1.0',
badges: ['Shimmer'],
badges: ['IOTA', 'Shimmer'],
},
],
},
Expand All @@ -215,7 +215,7 @@ exports.maintainPluginsConfig = [
versions: [
{
label: '2.0',
badges: ['IOTA/Shimmer'],
badges: ['IOTA', 'Shimmer'],
},
{
label: '1.2',
Expand All @@ -231,7 +231,7 @@ exports.maintainPluginsConfig = [
subsection: 'maintain-layer-2',
versions: [
{
label: '0.7',
label: 'v1.0.0-rc.6',
badges: ['Shimmer'],
},
],
Expand All @@ -244,12 +244,12 @@ exports.maintainPluginsConfig = [
subsection: 'maintain-layer-1',
versions: [
{
label: '0.3',
badges: ['IOTA'],
label: '1.0-rc.2',
badges: ['IOTA', 'Shimmer'],
},
{
label: '1.0-rc.1',
badges: ['Shimmer'],
label: '0.3',
badges: ['Deprecated'],
},
],
},
Expand Down