From 4c1d15351c2982d4cf7f8e0870f850a3d7f11df0 Mon Sep 17 00:00:00 2001 From: Dr-Electron Date: Fri, 15 Sep 2023 12:46:01 +0200 Subject: [PATCH 01/13] Restructure config --- contentPlugins.js | 316 +--------------------------- src/utils/pluginConfigGenerators.js | 55 +++++ versionedConfig.js | 267 +++++++++++++++++++++++ 3 files changed, 329 insertions(+), 309 deletions(-) create mode 100644 src/utils/pluginConfigGenerators.js create mode 100644 versionedConfig.js diff --git a/contentPlugins.js b/contentPlugins.js index acd9f4adcdf..61a156a52b8 100644 --- a/contentPlugins.js +++ b/contentPlugins.js @@ -1,7 +1,11 @@ +const { generatePluginConfig } = require('./src/utils/pluginConfigGenerators'); +const { buildPluginsConfig, maintainPluginsConfig } = require('./versionedConfig'); + const path = require('path'); module.exports = async () => { const buildPlugins = [ + ...generatePluginConfig(buildPluginsConfig, __dirname + '/docs/build/'), { id: 'build', globalSidebars: ['build'], @@ -12,226 +16,6 @@ module.exports = async () => { ), routeBasePath: 'build', }, - { - id: 'iota-sdk-1-0', - path: path.resolve(__dirname, 'docs/build/iota-sdk/1.0/docs'), - routeBasePath: 'iota-sdk', - sidebarPath: require.resolve('./docs/build/iota-sdk/1.0/sidebars.js'), - //overriding default exclude array to include the python api's classes with _ at the beginning - //but still exclude any _admonitions - exclude: [ - '**/*.test.{js,jsx,ts,tsx}', - '**/__tests__/**', - '**/_admonitions/_**', - ], - }, - { - id: 'wasp-cli-0-7', - path: path.resolve(__dirname, 'docs/build/wasp-cli/0.7/docs'), - routeBasePath: 'wasp-cli', - sidebarPath: path.resolve( - __dirname, - 'docs/build/wasp-cli/0.7/sidebars.js', - ), - }, - { - id: 'wasp-evm-0-7', - path: path.resolve(__dirname, 'docs/build/wasp-evm/0.7/docs'), - routeBasePath: 'wasp-evm', - sidebarPath: path.resolve( - __dirname, - 'docs/build/wasp-evm/0.7/sidebars.js', - ), - }, - { - id: 'wasp-wasm-0-7', - path: path.resolve(__dirname, 'docs/build/wasp-wasm/0.7/docs'), - routeBasePath: 'wasp-wasm', - sidebarPath: path.resolve( - __dirname, - 'docs/build/wasp-wasm/0.7/sidebars.js', - ), - }, - { - id: 'identity-rs-0-5', - path: path.resolve(__dirname, 'docs/build/identity.rs/0.5/docs'), - routeBasePath: 'identity.rs', - bannerPath: path.resolve(__dirname, 'banners/identity-deprecated.mdx'), - sidebarPath: path.resolve( - __dirname, - 'docs/build/identity.rs/0.5/sidebars.js', - ), - versions: { - current: { - label: '0.5', - path: '0.5', - badge: true, - }, - }, - }, - { - id: 'identity-rs-0-6', - path: path.resolve(__dirname, 'docs/build/identity.rs/0.6/docs'), - routeBasePath: 'identity.rs', - bannerPath: path.resolve( - __dirname, - 'banners/identity-stronghold-migration.mdx', - ), - sidebarPath: path.resolve( - __dirname, - 'docs/build/identity.rs/0.6/sidebars.js', - ), - versions: { - current: { - label: '0.6', - badge: true, - }, - }, - }, - { - id: 'identity-rs-0-7-alpha', - path: path.resolve(__dirname, 'docs/build/identity.rs/0.7-alpha/docs'), - routeBasePath: 'identity.rs', - sidebarPath: path.resolve( - __dirname, - 'docs/build/identity.rs/0.7-alpha/sidebars.js', - ), - versions: { - current: { - label: '0.7', - path: '0.7', - badge: true, - }, - }, - }, - { - id: 'identity-rs-next', - path: path.resolve(__dirname, 'docs/build/identity.rs/next/docs'), - routeBasePath: 'identity.rs', - sidebarPath: path.resolve( - __dirname, - 'docs/build/identity.rs/next/sidebars.js', - ), - versions: { - current: { - label: 'next', - path: 'next', - badge: true, - }, - }, - }, - { - id: 'iota-rs-1-4', - path: path.resolve(__dirname, 'docs/build/iota.rs/1.4/docs'), - routeBasePath: 'iota.rs', - sidebarPath: path.resolve( - __dirname, - 'docs/build/iota.rs/1.4/sidebars.js', - ), - versions: { - current: { - label: '1.4', - badge: true, - }, - }, - }, - { - id: 'iota-rs-2-0-rc-7', - path: path.resolve(__dirname, 'docs/build/iota.rs/2.0-rc.7/docs'), - routeBasePath: 'iota.rs', - bannerPath: path.resolve( - __dirname, - 'banners/pre-sdk-libs-deprecated.mdx', - ), - sidebarPath: path.resolve( - __dirname, - 'docs/build/iota.rs/2.0-rc.7/sidebars.js', - ), - versions: { - current: { - label: '2.0-rc.7', - path: '2.0-rc.7', - badge: true, - }, - }, - }, - { - id: 'iotajs', - path: path.resolve(__dirname, 'docs/build/iota.js/2.0-rc.1/docs'), - routeBasePath: 'iota.js', - bannerPath: path.resolve( - __dirname, - 'banners/pre-sdk-libs-deprecated.mdx', - ), - sidebarPath: path.resolve( - __dirname, - 'docs/build/iota.js/2.0-rc.1/sidebars.js', - ), - }, - { - id: 'wallet-rs-0-1', - path: path.resolve(__dirname, 'docs/build/wallet.rs/0.1/docs'), - routeBasePath: 'wallet.rs', - sidebarPath: path.resolve( - __dirname, - 'docs/build/wallet.rs/0.1/sidebars.js', - ), - versions: { - current: { - label: '0.1', - badge: true, - }, - }, - }, - { - id: 'wallet-rs-1-0-rc-6', - path: path.resolve(__dirname, 'docs/build/wallet.rs/1.0-rc.6/docs'), - routeBasePath: 'wallet.rs', - bannerPath: path.resolve( - __dirname, - 'banners/pre-sdk-libs-deprecated.mdx', - ), - sidebarPath: path.resolve( - __dirname, - 'docs/build/wallet.rs/1.0-rc.6/sidebars.js', - ), - versions: { - current: { - label: '1.0-rc.6', - path: '1.0-rc.6', - badge: true, - }, - }, - }, - { - id: 'stronghold-rs', - path: path.resolve(__dirname, 'docs/build/stronghold.rs/1.1/docs'), - routeBasePath: 'stronghold.rs', - sidebarPath: path.resolve( - __dirname, - 'docs/build/stronghold.rs/1.1/sidebars.js', - ), - }, - { - id: 'apis', - path: path.resolve(__dirname, 'docs/build/apis/docs'), - routeBasePath: 'apis', - sidebarPath: path.resolve(__dirname, 'docs/build/apis/sidebars.js'), - docItemComponent: '@theme/ApiItem', - }, - { - id: 'iota-streams', - path: path.resolve(__dirname, 'docs/build/streams/0.2/docs'), - routeBasePath: 'streams', - bannerPath: path.resolve( - __dirname, - 'banners/iota-streams-deprecated.mdx', - ), - sidebarPath: path.resolve( - __dirname, - 'docs/build/streams/0.2/sidebars.js', - ), - }, { id: 'introduction-docs-chrysalis', path: path.resolve( @@ -269,15 +53,6 @@ module.exports = async () => { }, }, }, - { - id: 'cli-wallet', - path: path.resolve(__dirname, 'docs/build/cli-wallet/1.0/docs'), - routeBasePath: 'cli-wallet', - sidebarPath: path.resolve( - __dirname, - 'docs/build/cli-wallet/1.0/sidebars.js', - ), - }, { id: 'iota-zebra-tutorials', path: path.resolve(__dirname, 'docs/build/zebra-iota-edge-sdk/tutorials'), @@ -290,6 +65,7 @@ module.exports = async () => { ]; const maintainPlugins = [ + ...generatePluginConfig(maintainPluginsConfig, __dirname + '/docs/maintain/'), { id: 'maintain', globalSidebars: ['maintain'], @@ -300,88 +76,10 @@ module.exports = async () => { ), routeBasePath: 'maintain', }, - { - id: 'hornet-1-2', - path: path.resolve(__dirname, 'docs/maintain/hornet/1.2/docs'), - routeBasePath: 'hornet', - sidebarPath: path.resolve( - __dirname, - 'docs/maintain/hornet/1.2/sidebars.js', - ), - versions: { - current: { - label: '1.2', - badge: true, - }, - }, - }, - { - id: 'hornet-2-0-rc-6', - path: path.resolve(__dirname, 'docs/maintain/hornet/2.0-rc.6/docs'), - routeBasePath: 'hornet', - sidebarPath: path.resolve( - __dirname, - 'docs/maintain/hornet/2.0-rc.6/sidebars.js', - ), - versions: { - current: { - label: '2.0-rc.6', - path: '2.0-rc.6', - badge: true, - }, - }, - }, - { - id: 'wasp-0-7', - path: path.resolve(__dirname, 'docs/maintain/wasp/0.7/docs'), - routeBasePath: 'wasp', - sidebarPath: path.resolve( - __dirname, - 'docs/maintain/wasp/0.7/sidebars.js', - ), - }, - { - id: 'chronicle-rs', - path: path.resolve(__dirname, 'docs/maintain/chronicle/0.3/docs'), - routeBasePath: 'chronicle', - sidebarPath: path.resolve( - __dirname, - 'docs/maintain/chronicle/0.3/sidebars.js', - ), - versions: { - current: { - label: '0.3', - badge: true, - }, - }, - }, - { - id: 'inx-chronicle', - path: path.resolve(__dirname, 'docs/maintain/chronicle/1.0-rc.1/docs'), - routeBasePath: 'chronicle', - sidebarPath: path.resolve( - __dirname, - 'docs/maintain/chronicle/1.0-rc.1/sidebars.js', - ), - versions: { - current: { - label: '1.0-rc.1', - path: '1.0-rc.1', - badge: true, - }, - }, - }, - { - id: 'goshimmer', - path: path.resolve(__dirname, 'docs/maintain/goshimmer/0.9/docs'), - routeBasePath: 'goshimmer', - sidebarPath: path.resolve( - __dirname, - 'docs/maintain/goshimmer/0.9/sidebars.js', - ), - }, ]; + console.log('buildPlugins', buildPlugins); + return [ { id: 'get-started', diff --git a/src/utils/pluginConfigGenerators.js b/src/utils/pluginConfigGenerators.js new file mode 100644 index 00000000000..18bd749b8be --- /dev/null +++ b/src/utils/pluginConfigGenerators.js @@ -0,0 +1,55 @@ +const path = require('path'); + +/** + * Generate the plugin config from the versioned config. + * @param {import('../common/components/Switcher').Doc} pluginConfig + * @param {string} basePath + */ +function generatePluginConfig(pluginConfig, basePath) { + let plugins = []; + for (const plugin of pluginConfig) { + + // Resolve main version to the default version or the first version configured. + 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; + } + + for (const version of plugin.versions) { + plugins.push({ + id: plugin.id + (version.label ? '-' + version.label.replace(/\./g, '-') : ''), + path: path.resolve(basePath + plugin.id + '/' + (version.label ? version.label : '') + '/docs'), + routeBasePath: plugin.routeBasePath ? plugin.routeBasePath : plugin.id, + sidebarPath: path.resolve(basePath + plugin.id + '/' + (version.label ? version.label : '') + '/sidebars.js'), + versions: { + current: { + label: version.label, + path: mainVersion.label === version.label ? undefined : version.label, + badge: true, + }, + }, + }); + } + } + + return plugins; +}; + +/** + * Generate the switcher config from the versioned config. + * @param {import('../common/components/Switcher').Doc[]} pluginConfig + */ +function generateSwitcherConfig(pluginConfig) { + return pluginConfig; +}; + +module.exports = { + generatePluginConfig, + generateSwitcherConfig +}; \ No newline at end of file diff --git a/versionedConfig.js b/versionedConfig.js new file mode 100644 index 00000000000..f5c32b0e766 --- /dev/null +++ b/versionedConfig.js @@ -0,0 +1,267 @@ +exports.buildPluginsConfig = [ + { + id: 'iota-sdk', + label: 'IOTA SDK', + description: 'Seamlessly integrate IOTA into your app.', + icon: 'IotaCore', + subsection: 'build-layer-1', + versions: [ + { + label: '1.0', + badges: ['Shimmer'], + //overriding default exclude array to include the python api's classes with _ at the beginning + //but still exclude any _admonitions + exclude: [ + '**/*.test.{js,jsx,ts,tsx}', + '**/__tests__/**', + '**/_admonitions/_**', + ], + }, + ], + }, + { + id: 'wasp-cli', + label: 'Wasp CLI', + description: 'Create custom smart contract chains.', + icon: 'SmartContracts', + subsection: 'build-layer-2', + versions: [ + { + label: '0.7', + badges: ['Shimmer'], + }, + ], + }, + { + id: 'wasp-evm', + label: 'EVM', + description: 'Create EVM smart contracts.', + icon: 'SmartContracts', + subsection: 'build-layer-2', + versions: [ + { + label: '0.7', + badges: ['Shimmer'], + }, + ], + }, + { + id: 'wasp-wasm', + label: 'WASM (Experimental)', + description: 'Create WASM smart contracts.', + icon: 'SmartContracts', + subsection: 'build-layer-2', + versions: [ + { + label: '0.7', + badges: ['Shimmer'], + }, + ], + }, + { + id: 'identity-rs', + routeBasePath: 'identity.rs', + label: 'Identity', + description: 'Trustless digital identity management.', + icon: 'Identity', + subsection: 'build-layer-1', + versions: [ + { + label: 'next', + badges: ['Shimmer'], + }, + { + label: '0.7-alpha', + badges: ['Shimmer'], + }, + { + label: '0.6', + badges: ['IOTA'], + }, + { + label: '0.5', + badges: ['IOTA'], + }, + ], + }, + { + id: 'stronghold-rs', + routeBasePath: 'stronghold.rs', + label: 'Stronghold', + description: 'Securely store secrets.', + icon: 'Stronghold', + subsection: 'build-layer-1', + versions: [ + { + label: '1.1', + badges: ['IOTA/Shimmer'], + }, + ], + }, + { + id: 'cli-wallet', + label: 'CLI Wallet', + description: 'Command line wallet.', + icon: 'Wallet', + subsection: 'build-layer-1', + versions: [ + { + label: '1.0', + badges: ['Shimmer'], + }, + ], + }, + { + id: 'apis', + label: 'APIs', + description: 'All available APIs.', + icon: 'Tools', + subsection: 'build-layer-1', + versions: [ + { + badges: ['IOTA/Shimmer'], + }, + ], + }, + { + id: 'iota-rs', + routeBasePath: 'iota.rs', + label: 'iota.rs (deprecated)', + description: 'Legacy client SDK.', + icon: 'IotaCore', + subsection: 'build-layer-1', + versions: [ + { + label: '2.0-rc.7', + badges: ['Shimmer'], + }, + { + label: '1.4', + badges: ['IOTA'], + }, + ], + }, + { + id: 'iota-js', + routeBasePath: 'iota.js', + label: 'iota.js (deprecated)', + description: 'Legacy JavaScript SDK.', + icon: 'IotaCore', + subsection: 'build-layer-1', + versions: [ + { + label: '2.0-rc.1', + badges: ['Shimmer'], + }, + ], + }, + { + id: 'wallet-rs', + routeBasePath: 'wallet.rs', + label: 'wallet.rs (deprecated)', + description: 'Legacy wallet SDK.', + icon: 'Wallet', + subsection: 'build-layer-1', + versions: [ + { + label: '1.0-rc.6', + badges: ['Shimmer'], + }, + { + label: '0.1', + badges: ['IOTA'], + }, + ], + }, + { + id: 'iota-streams', + routeBasePath: 'streams', + label: 'Streams (deprecated)', + description: 'Secure data channels over the Tangle.', + icon: 'Streams', + subsection: 'build-layer-1', + versions: [ + { + label: '0.2', + badges: ['IOTA'], + }, + ], + }, + { + id: 'smart-contract', + label: 'Smart Contracts', + description: 'Create smart contracts.', + icon: 'SmartContracts', + subsection: 'build-layer-2', + versions: [ + { + label: '0.7', + badges: ['Shimmer'], + }, + ], + }, +]; + +exports.maintainPluginsConfig = [ + { + id: 'hornet', + label: 'Hornet', + description: 'The primary node software for IOTA.', + icon: 'Hornet', + subsection: 'maintain-layer-1', + versions: [ + { + label: '2.0-rc.6', + badges: ['Shimmer'], + }, + { + label: '1.2', + badges: ['IOTA'], + }, + ], + }, + { + id: 'wasp', + label: 'Wasp', + description: 'The node software to run an ISC network', + icon: 'SmartContracts', + subsection: 'maintain-layer-2', + versions: [ + { + label: '0.7', + badges: ['Shimmer'], + }, + ], + }, + { + id: 'chronicle', + label: 'Chronicle', + description: 'Indexer, archival node, analytics.', + icon: 'Chronicle', + subsection: 'maintain-layer-1', + versions: [ + { + label: '1.0-rc.1', + badges: ['Shimmer'], + }, + { + label: '0.3', + badges: ['IOTA'], + }, + ], + }, + { + id: 'goshimmer', + label: 'GoShimmer', + description: 'Research node implementation for IOTA 2.0', + icon: 'GoShimmer', + subsection: 'maintain-layer-1', + versions: [ + { + id: 'goshimmer', + label: '0.9', + badges: ['IOTA 2.0'], + }, + ], + }, +]; From dd776205a8cebb0b13eb0ed9f5e5f0a94da7193c Mon Sep 17 00:00:00 2001 From: Dr-Electron Date: Mon, 18 Sep 2023 10:12:27 +0200 Subject: [PATCH 02/13] Add possibility of adding docusaurus parameters to versions --- contentPlugins.js | 2 +- src/utils/pluginConfigGenerators.js | 18 +++-- versionedConfig.js | 100 +++++++++++++++------------- 3 files changed, 67 insertions(+), 53 deletions(-) diff --git a/contentPlugins.js b/contentPlugins.js index 61a156a52b8..e9fed208f1e 100644 --- a/contentPlugins.js +++ b/contentPlugins.js @@ -5,7 +5,6 @@ const path = require('path'); module.exports = async () => { const buildPlugins = [ - ...generatePluginConfig(buildPluginsConfig, __dirname + '/docs/build/'), { id: 'build', globalSidebars: ['build'], @@ -16,6 +15,7 @@ module.exports = async () => { ), routeBasePath: 'build', }, + ...generatePluginConfig(buildPluginsConfig, __dirname + '/docs/build/'), { id: 'introduction-docs-chrysalis', path: path.resolve( diff --git a/src/utils/pluginConfigGenerators.js b/src/utils/pluginConfigGenerators.js index 18bd749b8be..67890a04e30 100644 --- a/src/utils/pluginConfigGenerators.js +++ b/src/utils/pluginConfigGenerators.js @@ -22,18 +22,22 @@ function generatePluginConfig(pluginConfig, basePath) { } for (const version of plugin.versions) { + const {label, badges, ...rest} = version; plugins.push({ - id: plugin.id + (version.label ? '-' + version.label.replace(/\./g, '-') : ''), - path: path.resolve(basePath + plugin.id + '/' + (version.label ? version.label : '') + '/docs'), + id: plugin.id + (label ? '-' + label.replace(/\./g, '-') : ''), + path: path.resolve(basePath + plugin.id + '/' + (label ? label : '') + '/docs'), routeBasePath: plugin.routeBasePath ? plugin.routeBasePath : plugin.id, - sidebarPath: path.resolve(basePath + plugin.id + '/' + (version.label ? version.label : '') + '/sidebars.js'), - versions: { + sidebarPath: path.resolve(basePath + plugin.id + '/' + (label ? label : '') + '/sidebars.js'), + versions: + plugin.versions.length > 1 ? { current: { - label: version.label, - path: mainVersion.label === version.label ? undefined : version.label, + label: label, + path: mainVersion.label === label ? undefined : label, badge: true, }, - }, + } : + undefined, + ...rest, }); } } diff --git a/versionedConfig.js b/versionedConfig.js index f5c32b0e766..94e2bb17948 100644 --- a/versionedConfig.js +++ b/versionedConfig.js @@ -1,3 +1,5 @@ +const path = require('path'); + exports.buildPluginsConfig = [ { id: 'iota-sdk', @@ -77,49 +79,15 @@ exports.buildPluginsConfig = [ { label: '0.6', badges: ['IOTA'], + bannerPath: path.resolve( + __dirname, + 'banners/identity-stronghold-migration.mdx', + ), }, { label: '0.5', badges: ['IOTA'], - }, - ], - }, - { - id: 'stronghold-rs', - routeBasePath: 'stronghold.rs', - label: 'Stronghold', - description: 'Securely store secrets.', - icon: 'Stronghold', - subsection: 'build-layer-1', - versions: [ - { - label: '1.1', - badges: ['IOTA/Shimmer'], - }, - ], - }, - { - id: 'cli-wallet', - label: 'CLI Wallet', - description: 'Command line wallet.', - icon: 'Wallet', - subsection: 'build-layer-1', - versions: [ - { - label: '1.0', - badges: ['Shimmer'], - }, - ], - }, - { - id: 'apis', - label: 'APIs', - description: 'All available APIs.', - icon: 'Tools', - subsection: 'build-layer-1', - versions: [ - { - badges: ['IOTA/Shimmer'], + bannerPath: path.resolve(__dirname, 'banners/identity-deprecated.mdx'), }, ], }, @@ -134,6 +102,10 @@ exports.buildPluginsConfig = [ { label: '2.0-rc.7', badges: ['Shimmer'], + bannerPath: path.resolve( + __dirname, + 'banners/pre-sdk-libs-deprecated.mdx', + ), }, { label: '1.4', @@ -152,6 +124,10 @@ exports.buildPluginsConfig = [ { label: '2.0-rc.1', badges: ['Shimmer'], + bannerPath: path.resolve( + __dirname, + 'banners/pre-sdk-libs-deprecated.mdx', + ), }, ], }, @@ -166,6 +142,10 @@ exports.buildPluginsConfig = [ { label: '1.0-rc.6', badges: ['Shimmer'], + bannerPath: path.resolve( + __dirname, + 'banners/pre-sdk-libs-deprecated.mdx', + ), }, { label: '0.1', @@ -173,6 +153,32 @@ exports.buildPluginsConfig = [ }, ], }, + { + id: 'stronghold-rs', + routeBasePath: 'stronghold.rs', + label: 'Stronghold', + description: 'Securely store secrets.', + icon: 'Stronghold', + subsection: 'build-layer-1', + versions: [ + { + label: '1.1', + badges: ['IOTA/Shimmer'], + }, + ], + }, + { + id: 'apis', + label: 'APIs', + description: 'All available APIs.', + icon: 'Tools', + subsection: 'build-layer-1', + versions: [ + { + badges: ['IOTA/Shimmer'], + }, + ], + }, { id: 'iota-streams', routeBasePath: 'streams', @@ -184,18 +190,22 @@ exports.buildPluginsConfig = [ { label: '0.2', badges: ['IOTA'], + bannerPath: path.resolve( + __dirname, + 'banners/iota-streams-deprecated.mdx', + ), }, ], }, { - id: 'smart-contract', - label: 'Smart Contracts', - description: 'Create smart contracts.', - icon: 'SmartContracts', - subsection: 'build-layer-2', + id: 'cli-wallet', + label: 'CLI Wallet', + description: 'Command line wallet.', + icon: 'Wallet', + subsection: 'build-layer-1', versions: [ { - label: '0.7', + label: '1.0', badges: ['Shimmer'], }, ], From 041048fecf1dca9d7030bd49be51b3bd6160b834 Mon Sep 17 00:00:00 2001 From: Dr-Electron Date: Mon, 18 Sep 2023 12:43:47 +0200 Subject: [PATCH 03/13] Add code to generate switcher config --- src/utils/pluginConfigGenerators.js | 23 ++- switcherConfig.js | 269 +--------------------------- 2 files changed, 27 insertions(+), 265 deletions(-) diff --git a/src/utils/pluginConfigGenerators.js b/src/utils/pluginConfigGenerators.js index 67890a04e30..f2cf453c728 100644 --- a/src/utils/pluginConfigGenerators.js +++ b/src/utils/pluginConfigGenerators.js @@ -50,7 +50,28 @@ function generatePluginConfig(pluginConfig, basePath) { * @param {import('../common/components/Switcher').Doc[]} pluginConfig */ function generateSwitcherConfig(pluginConfig) { - return pluginConfig; + let plugins = []; + for (const plugin of pluginConfig) { + //TODO: Rethink how we use ids in the switcher and/or determine the main plugin id + const firstLabel = plugin.versions[0].label; + plugins.push({ + id: plugin.id + (firstLabel ? '-' + firstLabel.replace(/\./g, '-') : ''), + label: plugin.label, + icon: plugin.icon, + description: plugin.description, + subsection: plugin.subsection, + versions: plugin.versions.map((version) => { + const {label, badges} = version; + return { + id: plugin.id + (label ? '-' + label.replace(/\./g, '-') : ''), + label: label, + badges: badges, + }; + }), + }); + } + + return plugins; }; module.exports = { diff --git a/switcherConfig.js b/switcherConfig.js index 38c66095ef4..f621493ed70 100644 --- a/switcherConfig.js +++ b/switcherConfig.js @@ -1,271 +1,12 @@ // @ts-check - -const buildDocs = [ - { - id: 'iota-sdk-1-0', - label: 'IOTA SDK', - description: 'Seamlessly integrate IOTA into your app.', - icon: 'IotaCore', - subsection: 'build-layer-1', - versions: [ - { - id: 'iota-sdk-1-0', - label: '1.0', - badges: ['Shimmer'], - }, - ], - }, - { - id: 'identity-rs-0-5', - label: 'Identity', - description: 'Trustless digital identity management.', - icon: 'Identity', - subsection: 'build-layer-1', - versions: [ - { - id: 'identity-rs-next', - label: 'next', - badges: ['Shimmer'], - }, - { - id: 'identity-rs-0-7-alpha', - label: '0.7-alpha', - badges: ['Shimmer'], - }, - { - id: 'identity-rs-0-6', - label: '0.6', - badges: ['IOTA'], - }, - { - id: 'identity-rs-0-5', - label: '0.5', - badges: ['IOTA'], - }, - ], - }, - { - id: 'stronghold-rs', - label: 'Stronghold', - description: 'Securely store secrets.', - icon: 'Stronghold', - subsection: 'build-layer-1', - versions: [ - { - id: 'stronghold-rs', - label: '1.1', - badges: ['IOTA/Shimmer'], - }, - ], - }, - { - id: 'cli-wallet', - label: 'CLI Wallet', - description: 'Command line wallet.', - icon: 'Wallet', - subsection: 'build-layer-1', - versions: [ - { - id: 'cli-wallet', - label: '1.0', - badges: ['Shimmer'], - }, - ], - }, - { - id: 'apis', - label: 'APIs', - description: 'All available APIs.', - icon: 'Tools', - subsection: 'build-layer-1', - versions: [ - { - id: 'apis', - }, - ], - }, - { - id: 'iota-rs-1-4', - label: 'iota.rs (deprecated)', - description: 'Legacy client SDK.', - icon: 'IotaCore', - subsection: 'build-layer-1', - versions: [ - { - id: 'iota-rs-2-0-rc-7', - label: '2.0-rc.7', - badges: ['Shimmer'], - }, - { - id: 'iota-rs-1-4', - label: '1.4', - badges: ['IOTA'], - }, - ], - }, - { - id: 'iotajs', - label: 'iota.js (deprecated)', - description: 'Legacy JavaScript SDK.', - icon: 'IotaCore', - subsection: 'build-layer-1', - versions: [ - { - id: 'iotajs', - label: '2.0-rc.1', - badges: ['Shimmer'], - }, - ], - }, - { - id: 'wallet-rs-0-1', - label: 'wallet.rs (deprecated)', - description: 'Legacy wallet SDK.', - icon: 'Wallet', - subsection: 'build-layer-1', - versions: [ - { - id: 'wallet-rs-1-0-rc-6', - label: '1.0-rc.6', - badges: ['Shimmer'], - }, - { - id: 'wallet-rs-0-1', - label: '0.1', - badges: ['IOTA'], - }, - ], - }, - { - id: 'iota-streams', - label: 'Streams (deprecated)', - description: 'Secure data channels over the Tangle.', - icon: 'Streams', - subsection: 'build-layer-1', - versions: [ - { - id: 'iota-streams', - label: '0.2', - badges: ['IOTA'], - }, - ], - }, - { - id: 'wasp-evm-0-7', - label: 'EVM', - description: 'Create EVM smart contracts.', - icon: 'SmartContracts', - subsection: 'build-layer-2', - versions: [ - { - id: 'wasp-evm-0-7', - label: '0.7', - badges: ['Shimmer'], - }, - ], - }, - { - id: 'wasp-cli-0-7', - label: 'Wasp CLI', - description: 'Create custom smart contract chains.', - icon: 'SmartContracts', - subsection: 'build-layer-2', - versions: [ - { - id: 'wasp-cli-0-7', - label: '0.7', - badges: ['Shimmer'], - }, - ], - }, - { - id: 'wasp-wasm-0-7', - label: 'WASM (Experimental)', - description: 'Create WASM smart contracts.', - icon: 'SmartContracts', - subsection: 'build-layer-2', - versions: [ - { - id: 'wasp-wasm-0-7', - label: '0.7', - badges: ['Shimmer'], - }, - ], - }, -]; - -const maintainDocs = [ - { - id: 'hornet-1-2', - label: 'Hornet', - description: 'The primary node software for IOTA.', - icon: 'Hornet', - subsection: 'maintain-layer-1', - versions: [ - { - id: 'hornet-2-0-rc-6', - label: '2.0-rc.6', - badges: ['Shimmer'], - }, - { - id: 'hornet-1-2', - label: '1.2', - badges: ['IOTA'], - }, - ], - }, - { - id: 'wasp-0-7', - label: 'Wasp', - description: 'The node software to run an ISC network', - icon: 'SmartContracts', - subsection: 'maintain-layer-2', - versions: [ - { - id: 'wasp-0-7', - label: '0.7', - badges: ['Shimmer'], - }, - ], - }, - { - id: 'chronicle-rs', - label: 'Chronicle', - description: 'Indexer, archival node, analytics.', - icon: 'Chronicle', - subsection: 'maintain-layer-1', - versions: [ - { - id: 'inx-chronicle', - label: '1.0-rc.1', - badges: ['Shimmer'], - }, - { - id: 'chronicle-rs', - label: '0.3', - badges: ['IOTA'], - }, - ], - }, - { - id: 'goshimmer', - label: 'GoShimmer', - description: 'Research node implementation for IOTA 2.0', - icon: 'GoShimmer', - subsection: 'maintain-layer-1', - versions: [ - { - id: 'goshimmer', - label: '0.9', - badges: ['IOTA 2.0'], - }, - ], - }, -]; +const { + generateSwitcherConfig, +} = require('./src/utils/pluginConfigGenerators'); +const { buildPluginsConfig, maintainPluginsConfig } = require('./versionedConfig'); /** @type {import('./src/common/components/Switcher').Config} */ const config = { - docs: [...buildDocs, ...maintainDocs], + docs: [...generateSwitcherConfig(buildPluginsConfig), ...generateSwitcherConfig(maintainPluginsConfig)], sections: [ { before: { From ef2619fb009bc07836e5fee15d764d6630a9fe5c Mon Sep 17 00:00:00 2001 From: Dr-Electron Date: Mon, 18 Sep 2023 14:22:30 +0200 Subject: [PATCH 04/13] Remove defaultDoc --- src/common/components/Switcher/index.tsx | 6 +----- src/utils/pluginConfigGenerators.js | 7 ++++--- src/utils/useSwitcher.ts | 15 +++------------ 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/src/common/components/Switcher/index.tsx b/src/common/components/Switcher/index.tsx index d7a48ee32c1..296bd755c61 100644 --- a/src/common/components/Switcher/index.tsx +++ b/src/common/components/Switcher/index.tsx @@ -21,10 +21,6 @@ export type Doc = Item & { defaultVersion?: string; }; -export type Subsection = Item & { - defaultDoc?: string; -}; - export type Sidebar = { docId: string; sidebarId: string; @@ -32,7 +28,7 @@ export type Sidebar = { export type Section = { before?: Sidebar; - subsections: Subsection[]; + subsections: Item[]; after?: Sidebar; }; diff --git a/src/utils/pluginConfigGenerators.js b/src/utils/pluginConfigGenerators.js index f2cf453c728..b8376c136c4 100644 --- a/src/utils/pluginConfigGenerators.js +++ b/src/utils/pluginConfigGenerators.js @@ -52,10 +52,11 @@ function generatePluginConfig(pluginConfig, basePath) { function generateSwitcherConfig(pluginConfig) { let plugins = []; for (const plugin of pluginConfig) { - //TODO: Rethink how we use ids in the switcher and/or determine the main plugin id - const firstLabel = plugin.versions[0].label; plugins.push({ - id: plugin.id + (firstLabel ? '-' + firstLabel.replace(/\./g, '-') : ''), + // Here any unique id could be uses as this is just used to track the active plugin in the switcher. + // So we use the plugin id without version label. So it actually isn't the actual plugin id of the plugin. + // Confusing, I know ;) + id: plugin.id, label: plugin.label, icon: plugin.icon, description: plugin.description, diff --git a/src/utils/useSwitcher.ts b/src/utils/useSwitcher.ts index ff4a329ce43..409a51c18eb 100644 --- a/src/utils/useSwitcher.ts +++ b/src/utils/useSwitcher.ts @@ -12,7 +12,7 @@ import { MenuItem, Section, Sidebar, - Subsection, + Item, } from '../common/components/Switcher'; export type GlobalPluginData = DocsGlobalPluginData & { @@ -33,7 +33,7 @@ export type SwitcherProps = { }; type ConfigTree = (Omit & { - subsections: (Subsection & { docs: Doc[] })[]; + subsections: (Item & { docs: Doc[] })[]; })[]; function findCurrentSection( @@ -158,17 +158,8 @@ export default function useSwitcher(): SwitcherProps { }; }); - // Resolve the subsection link to the default doc or the first doc configured. + // Resolve the subsection link to the first doc configured. let to = docLinks[0].to; - if (subsection.defaultDoc) { - const foundDoc = docLinks.find( - (doc) => doc.id === subsection.defaultDoc, - ); - if (!foundDoc) - throw `Default doc ${subsection.defaultDoc} of subsection ${subsection.label} not found.`; - - to = foundDoc.to; - } let active = false; if (current.subsection && subsection.id === current.subsection.id) { From 1aea01ed4b2407a152f875f4a1b8f5dfb15c58c1 Mon Sep 17 00:00:00 2001 From: Dr-Electron Date: Mon, 18 Sep 2023 14:26:36 +0200 Subject: [PATCH 05/13] Remove console.log --- contentPlugins.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/contentPlugins.js b/contentPlugins.js index e9fed208f1e..e4d2b642cdd 100644 --- a/contentPlugins.js +++ b/contentPlugins.js @@ -78,8 +78,6 @@ module.exports = async () => { }, ]; - console.log('buildPlugins', buildPlugins); - return [ { id: 'get-started', From 401497cc74d8fd641730a08f356f409aafbb7268 Mon Sep 17 00:00:00 2001 From: Dr-Electron Date: Mon, 18 Sep 2023 14:26:51 +0200 Subject: [PATCH 06/13] Format --- contentPlugins.js | 10 ++- src/utils/pluginConfigGenerators.js | 116 ++++++++++++++-------------- switcherConfig.js | 10 ++- 3 files changed, 76 insertions(+), 60 deletions(-) diff --git a/contentPlugins.js b/contentPlugins.js index e4d2b642cdd..6e59a139e93 100644 --- a/contentPlugins.js +++ b/contentPlugins.js @@ -1,5 +1,8 @@ const { generatePluginConfig } = require('./src/utils/pluginConfigGenerators'); -const { buildPluginsConfig, maintainPluginsConfig } = require('./versionedConfig'); +const { + buildPluginsConfig, + maintainPluginsConfig, +} = require('./versionedConfig'); const path = require('path'); @@ -65,7 +68,10 @@ module.exports = async () => { ]; const maintainPlugins = [ - ...generatePluginConfig(maintainPluginsConfig, __dirname + '/docs/maintain/'), + ...generatePluginConfig( + maintainPluginsConfig, + __dirname + '/docs/maintain/', + ), { id: 'maintain', globalSidebars: ['maintain'], diff --git a/src/utils/pluginConfigGenerators.js b/src/utils/pluginConfigGenerators.js index b8376c136c4..dd3f6559195 100644 --- a/src/utils/pluginConfigGenerators.js +++ b/src/utils/pluginConfigGenerators.js @@ -6,44 +6,48 @@ const path = require('path'); * @param {string} basePath */ function generatePluginConfig(pluginConfig, basePath) { - let plugins = []; - for (const plugin of pluginConfig) { - - // Resolve main version to the default version or the first version configured. - 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.`; + let plugins = []; + for (const plugin of pluginConfig) { + // Resolve main version to the default version or the first version configured. + 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; - } + mainVersion = foundVersion; + } - for (const version of plugin.versions) { - const {label, badges, ...rest} = version; - plugins.push({ - id: plugin.id + (label ? '-' + label.replace(/\./g, '-') : ''), - path: path.resolve(basePath + plugin.id + '/' + (label ? label : '') + '/docs'), - routeBasePath: plugin.routeBasePath ? plugin.routeBasePath : plugin.id, - sidebarPath: path.resolve(basePath + plugin.id + '/' + (label ? label : '') + '/sidebars.js'), - versions: - plugin.versions.length > 1 ? { - current: { - label: label, - path: mainVersion.label === label ? undefined : label, - badge: true, - }, - } : - undefined, - ...rest, - }); - } + for (const version of plugin.versions) { + const { label, badges, ...rest } = version; + plugins.push({ + id: plugin.id + (label ? '-' + label.replace(/\./g, '-') : ''), + path: path.resolve( + basePath + plugin.id + '/' + (label ? label : '') + '/docs', + ), + routeBasePath: plugin.routeBasePath ? plugin.routeBasePath : plugin.id, + sidebarPath: path.resolve( + basePath + plugin.id + '/' + (label ? label : '') + '/sidebars.js', + ), + versions: + plugin.versions.length > 1 + ? { + current: { + label: label, + path: mainVersion.label === label ? undefined : label, + badge: true, + }, + } + : undefined, + ...rest, + }); } + } - return plugins; -}; + return plugins; +} /** * Generate the switcher config from the versioned config. @@ -52,30 +56,30 @@ function generatePluginConfig(pluginConfig, basePath) { function generateSwitcherConfig(pluginConfig) { let plugins = []; for (const plugin of pluginConfig) { - plugins.push({ - // Here any unique id could be uses as this is just used to track the active plugin in the switcher. - // So we use the plugin id without version label. So it actually isn't the actual plugin id of the plugin. - // Confusing, I know ;) - id: plugin.id, - label: plugin.label, - icon: plugin.icon, - description: plugin.description, - subsection: plugin.subsection, - versions: plugin.versions.map((version) => { - const {label, badges} = version; - return { - id: plugin.id + (label ? '-' + label.replace(/\./g, '-') : ''), - label: label, - badges: badges, - }; - }), - }); + plugins.push({ + // Here any unique id could be uses as this is just used to track the active plugin in the switcher. + // So we use the plugin id without version label. So it actually isn't the actual plugin id of the plugin. + // Confusing, I know ;) + id: plugin.id, + label: plugin.label, + icon: plugin.icon, + description: plugin.description, + subsection: plugin.subsection, + versions: plugin.versions.map((version) => { + const { label, badges } = version; + return { + id: plugin.id + (label ? '-' + label.replace(/\./g, '-') : ''), + label: label, + badges: badges, + }; + }), + }); } return plugins; -}; +} module.exports = { - generatePluginConfig, - generateSwitcherConfig -}; \ No newline at end of file + generatePluginConfig, + generateSwitcherConfig, +}; diff --git a/switcherConfig.js b/switcherConfig.js index f621493ed70..d95111f9ae0 100644 --- a/switcherConfig.js +++ b/switcherConfig.js @@ -2,11 +2,17 @@ const { generateSwitcherConfig, } = require('./src/utils/pluginConfigGenerators'); -const { buildPluginsConfig, maintainPluginsConfig } = require('./versionedConfig'); +const { + buildPluginsConfig, + maintainPluginsConfig, +} = require('./versionedConfig'); /** @type {import('./src/common/components/Switcher').Config} */ const config = { - docs: [...generateSwitcherConfig(buildPluginsConfig), ...generateSwitcherConfig(maintainPluginsConfig)], + docs: [ + ...generateSwitcherConfig(buildPluginsConfig), + ...generateSwitcherConfig(maintainPluginsConfig), + ], sections: [ { before: { From ad120f3a7607819e50b84e8443b69268e2caae33 Mon Sep 17 00:00:00 2001 From: Jeroen van den Hout Date: Mon, 18 Sep 2023 13:37:09 +0200 Subject: [PATCH 07/13] Fix TS warnings --- src/common/components/Switcher/index.tsx | 4 +++- versionedConfig.js | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/common/components/Switcher/index.tsx b/src/common/components/Switcher/index.tsx index 296bd755c61..7203fe652d1 100644 --- a/src/common/components/Switcher/index.tsx +++ b/src/common/components/Switcher/index.tsx @@ -14,7 +14,9 @@ export type Item = { icon?: string; }; -export type Version = Item; +export type Version = Omit & { + id?: string; +}; export type Doc = Item & { subsection: string; versions: Version[]; diff --git a/versionedConfig.js b/versionedConfig.js index 94e2bb17948..5bf242a2e2b 100644 --- a/versionedConfig.js +++ b/versionedConfig.js @@ -175,6 +175,7 @@ exports.buildPluginsConfig = [ subsection: 'build-layer-1', versions: [ { + label: '', badges: ['IOTA/Shimmer'], }, ], From 4f6f70d31bbe9b167ec336d0efe7a3e7e460f569 Mon Sep 17 00:00:00 2001 From: Dr-Electron Date: Sat, 23 Sep 2023 22:25:32 +0200 Subject: [PATCH 08/13] Fix config --- src/utils/pluginConfigGenerators.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/utils/pluginConfigGenerators.js b/src/utils/pluginConfigGenerators.js index dd3f6559195..b17123d0345 100644 --- a/src/utils/pluginConfigGenerators.js +++ b/src/utils/pluginConfigGenerators.js @@ -22,15 +22,17 @@ function generatePluginConfig(pluginConfig, basePath) { for (const version of plugin.versions) { const { label, badges, ...rest } = version; + // TODO: This could be removed once we don't use points in paths anymore. + const plugin_name_path = plugin.routeBasePath + ? plugin.routeBasePath + : plugin.id; + const extended_base_path = + basePath + plugin_name_path + '/' + (label ? label : ''); plugins.push({ id: plugin.id + (label ? '-' + label.replace(/\./g, '-') : ''), - path: path.resolve( - basePath + plugin.id + '/' + (label ? label : '') + '/docs', - ), - routeBasePath: plugin.routeBasePath ? plugin.routeBasePath : plugin.id, - sidebarPath: path.resolve( - basePath + plugin.id + '/' + (label ? label : '') + '/sidebars.js', - ), + path: path.resolve(extended_base_path + '/docs'), + routeBasePath: plugin_name_path, + sidebarPath: path.resolve(extended_base_path + '/sidebars.js'), versions: plugin.versions.length > 1 ? { From b089d634bb411140e1bfefe87b3db9bb934b3ec7 Mon Sep 17 00:00:00 2001 From: Dr-Electron Date: Sat, 23 Sep 2023 22:54:11 +0200 Subject: [PATCH 09/13] Update src/utils/pluginConfigGenerators.js Co-authored-by: Jeroen van den Hout --- src/utils/pluginConfigGenerators.js | 34 ++++++++++------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/src/utils/pluginConfigGenerators.js b/src/utils/pluginConfigGenerators.js index b17123d0345..73435794ac4 100644 --- a/src/utils/pluginConfigGenerators.js +++ b/src/utils/pluginConfigGenerators.js @@ -56,29 +56,17 @@ function generatePluginConfig(pluginConfig, basePath) { * @param {import('../common/components/Switcher').Doc[]} pluginConfig */ function generateSwitcherConfig(pluginConfig) { - let plugins = []; - for (const plugin of pluginConfig) { - plugins.push({ - // Here any unique id could be uses as this is just used to track the active plugin in the switcher. - // So we use the plugin id without version label. So it actually isn't the actual plugin id of the plugin. - // Confusing, I know ;) - id: plugin.id, - label: plugin.label, - icon: plugin.icon, - description: plugin.description, - subsection: plugin.subsection, - versions: plugin.versions.map((version) => { - const { label, badges } = version; - return { - id: plugin.id + (label ? '-' + label.replace(/\./g, '-') : ''), - label: label, - badges: badges, - }; - }), - }); - } - - return plugins; + return pluginConfig.map((plugin) => ({ + ...plugin, + versions: plugin.versions.map((version) => { + const { label, badges } = version; + return { + id: plugin.id + (label ? '-' + label.replace(/\./g, '-') : ''), + label, + badges, + }; + }), + })); } module.exports = { From d6557c9e3e870de0c8aeab293b745469d41f463c Mon Sep 17 00:00:00 2001 From: Dr-Electron Date: Sun, 24 Sep 2023 10:51:09 +0200 Subject: [PATCH 10/13] Holy moly. I f*cking did it --- src/utils/pluginConfigGenerators.js | 84 ++++++++++++++++++----------- versionedConfig.js | 34 ++++++------ 2 files changed, 70 insertions(+), 48 deletions(-) diff --git a/src/utils/pluginConfigGenerators.js b/src/utils/pluginConfigGenerators.js index 73435794ac4..549938b217c 100644 --- a/src/utils/pluginConfigGenerators.js +++ b/src/utils/pluginConfigGenerators.js @@ -1,24 +1,35 @@ const path = require('path'); + +/** + * Find main version of a plugin by resolving it to the default version or the first version configured. + * @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; +} + /** * Generate the plugin config from the versioned config. - * @param {import('../common/components/Switcher').Doc} pluginConfig + * @param {import('../common/components/Switcher').Doc[]} pluginConfig * @param {string} basePath */ function generatePluginConfig(pluginConfig, basePath) { let plugins = []; - for (const plugin of pluginConfig) { - // Resolve main version to the default version or the first version configured. - 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; - } + for (const plugin of pluginConfig) { + const mainVersion = findMainVersion(plugin); for (const version of plugin.versions) { const { label, badges, ...rest } = version; @@ -28,23 +39,31 @@ function generatePluginConfig(pluginConfig, basePath) { : plugin.id; const extended_base_path = basePath + plugin_name_path + '/' + (label ? label : ''); - plugins.push({ - id: plugin.id + (label ? '-' + label.replace(/\./g, '-') : ''), - path: path.resolve(extended_base_path + '/docs'), - routeBasePath: plugin_name_path, - sidebarPath: path.resolve(extended_base_path + '/sidebars.js'), - versions: - plugin.versions.length > 1 - ? { - current: { - label: label, - path: mainVersion.label === label ? undefined : label, - badge: true, - }, - } - : undefined, - ...rest, - }); + if (plugin.versions.length > 1) { + plugins.push({ + id: plugin.id + (label ? '-' + label.replace(/\./g, '-') : ''), + path: path.resolve(extended_base_path + '/docs'), + routeBasePath: plugin_name_path, + sidebarPath: path.resolve(extended_base_path + '/sidebars.js'), + versions:{ + current: { + label: label, + path: mainVersion.label === label ? undefined : label, + badge: true, + }, + }, + ...rest, + }); + } + else { + plugins.push({ + id: plugin.id + (label ? '-' + label.replace(/\./g, '-') : ''), + path: path.resolve(extended_base_path + '/docs'), + routeBasePath: plugin_name_path, + sidebarPath: path.resolve(extended_base_path + '/sidebars.js'), + ...rest, + }); + } } } @@ -56,8 +75,11 @@ function generatePluginConfig(pluginConfig, basePath) { * @param {import('../common/components/Switcher').Doc[]} pluginConfig */ function generateSwitcherConfig(pluginConfig) { - return pluginConfig.map((plugin) => ({ + return pluginConfig.map((plugin) => { + const mainVersion = findMainVersion(plugin); + return { ...plugin, + id: plugin.id + (mainVersion.label ? '-' + mainVersion.label.replace(/\./g, '-') : ''), versions: plugin.versions.map((version) => { const { label, badges } = version; return { @@ -66,7 +88,7 @@ function generateSwitcherConfig(pluginConfig) { badges, }; }), - })); + }}); } module.exports = { diff --git a/versionedConfig.js b/versionedConfig.js index 5bf242a2e2b..e587985ae60 100644 --- a/versionedConfig.js +++ b/versionedConfig.js @@ -99,6 +99,10 @@ exports.buildPluginsConfig = [ icon: 'IotaCore', subsection: 'build-layer-1', versions: [ + { + label: '1.4', + badges: ['IOTA'], + }, { label: '2.0-rc.7', badges: ['Shimmer'], @@ -107,10 +111,6 @@ exports.buildPluginsConfig = [ 'banners/pre-sdk-libs-deprecated.mdx', ), }, - { - label: '1.4', - badges: ['IOTA'], - }, ], }, { @@ -139,6 +139,10 @@ exports.buildPluginsConfig = [ icon: 'Wallet', subsection: 'build-layer-1', versions: [ + { + label: '0.1', + badges: ['IOTA'], + }, { label: '1.0-rc.6', badges: ['Shimmer'], @@ -147,10 +151,6 @@ exports.buildPluginsConfig = [ 'banners/pre-sdk-libs-deprecated.mdx', ), }, - { - label: '0.1', - badges: ['IOTA'], - }, ], }, { @@ -177,6 +177,7 @@ exports.buildPluginsConfig = [ { label: '', badges: ['IOTA/Shimmer'], + docItemComponent: '@theme/ApiItem', }, ], }, @@ -221,14 +222,14 @@ exports.maintainPluginsConfig = [ icon: 'Hornet', subsection: 'maintain-layer-1', versions: [ - { - label: '2.0-rc.6', - badges: ['Shimmer'], - }, { label: '1.2', badges: ['IOTA'], }, + { + label: '2.0-rc.6', + badges: ['Shimmer'], + }, ], }, { @@ -251,14 +252,14 @@ exports.maintainPluginsConfig = [ icon: 'Chronicle', subsection: 'maintain-layer-1', versions: [ - { - label: '1.0-rc.1', - badges: ['Shimmer'], - }, { label: '0.3', badges: ['IOTA'], }, + { + label: '1.0-rc.1', + badges: ['Shimmer'], + }, ], }, { @@ -269,7 +270,6 @@ exports.maintainPluginsConfig = [ subsection: 'maintain-layer-1', versions: [ { - id: 'goshimmer', label: '0.9', badges: ['IOTA 2.0'], }, From 55e75b79ee87d7d5d0787d376726e759cee1d3fb Mon Sep 17 00:00:00 2001 From: Dr-Electron Date: Mon, 25 Sep 2023 11:41:36 +0200 Subject: [PATCH 11/13] Update src/utils/pluginConfigGenerators.js Co-authored-by: Jeroen van den Hout --- src/utils/pluginConfigGenerators.js | 59 ++++++++++++----------------- 1 file changed, 25 insertions(+), 34 deletions(-) diff --git a/src/utils/pluginConfigGenerators.js b/src/utils/pluginConfigGenerators.js index 549938b217c..c82511317f7 100644 --- a/src/utils/pluginConfigGenerators.js +++ b/src/utils/pluginConfigGenerators.js @@ -26,48 +26,39 @@ function findMainVersion(plugin) { * @param {string} basePath */ function generatePluginConfig(pluginConfig, basePath) { - let plugins = []; + return pluginConfig.flatMap((doc) => { + const mainVersion = findMainVersion(doc); - for (const plugin of pluginConfig) { - const mainVersion = findMainVersion(plugin); - - for (const version of plugin.versions) { + return doc.versions.map((version) => { const { label, badges, ...rest } = version; + // TODO: This could be removed once we don't use points in paths anymore. - const plugin_name_path = plugin.routeBasePath - ? plugin.routeBasePath - : plugin.id; + const plugin_name_path = doc.routeBasePath ? doc.routeBasePath : doc.id; + const extended_base_path = basePath + plugin_name_path + '/' + (label ? label : ''); - if (plugin.versions.length > 1) { - plugins.push({ - id: plugin.id + (label ? '-' + label.replace(/\./g, '-') : ''), - path: path.resolve(extended_base_path + '/docs'), - routeBasePath: plugin_name_path, - sidebarPath: path.resolve(extended_base_path + '/sidebars.js'), - versions:{ - current: { - label: label, - path: mainVersion.label === label ? undefined : label, - badge: true, - }, + + plugin = { + id: doc.id + (label ? '-' + label.replace(/\./g, '-') : ''), + path: path.resolve(extended_base_path + '/docs'), + routeBasePath: plugin_name_path, + sidebarPath: path.resolve(extended_base_path + '/sidebars.js'), + ...rest, + }; + + if (doc.versions.length > 1) { + plugin.versions = { + current: { + label, + path: mainVersion.label === label ? undefined : label, + badge: true, }, - ...rest, - }); + }; } - else { - plugins.push({ - id: plugin.id + (label ? '-' + label.replace(/\./g, '-') : ''), - path: path.resolve(extended_base_path + '/docs'), - routeBasePath: plugin_name_path, - sidebarPath: path.resolve(extended_base_path + '/sidebars.js'), - ...rest, - }); - } - } - } - return plugins; + return plugin; + }); + }); } /** From 69b884afa178772b5c2298aa829809822b68819a Mon Sep 17 00:00:00 2001 From: Dr-Electron Date: Mon, 25 Sep 2023 11:44:46 +0200 Subject: [PATCH 12/13] Format --- src/utils/pluginConfigGenerators.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/utils/pluginConfigGenerators.js b/src/utils/pluginConfigGenerators.js index c82511317f7..5558c7b30db 100644 --- a/src/utils/pluginConfigGenerators.js +++ b/src/utils/pluginConfigGenerators.js @@ -1,6 +1,5 @@ const path = require('path'); - /** * Find main version of a plugin by resolving it to the default version or the first version configured. * @param {import('../common/components/Switcher').Doc} plugin @@ -69,17 +68,20 @@ function generateSwitcherConfig(pluginConfig) { return pluginConfig.map((plugin) => { const mainVersion = findMainVersion(plugin); return { - ...plugin, - id: plugin.id + (mainVersion.label ? '-' + mainVersion.label.replace(/\./g, '-') : ''), - versions: plugin.versions.map((version) => { - const { label, badges } = version; - return { - id: plugin.id + (label ? '-' + label.replace(/\./g, '-') : ''), - label, - badges, - }; - }), - }}); + ...plugin, + id: + plugin.id + + (mainVersion.label ? '-' + mainVersion.label.replace(/\./g, '-') : ''), + versions: plugin.versions.map((version) => { + const { label, badges } = version; + return { + id: plugin.id + (label ? '-' + label.replace(/\./g, '-') : ''), + label, + badges, + }; + }), + }; + }); } module.exports = { From 4faa008b801ff4396f9373d3625e2a709c40eea9 Mon Sep 17 00:00:00 2001 From: Dr-Electron Date: Mon, 25 Sep 2023 14:03:46 +0200 Subject: [PATCH 13/13] Small update and make linter happy --- src/utils/pluginConfigGenerators.js | 22 ++++++++++++---------- src/utils/useSwitcher.ts | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/utils/pluginConfigGenerators.js b/src/utils/pluginConfigGenerators.js index 5558c7b30db..44b4a6303ad 100644 --- a/src/utils/pluginConfigGenerators.js +++ b/src/utils/pluginConfigGenerators.js @@ -29,6 +29,7 @@ function generatePluginConfig(pluginConfig, basePath) { const mainVersion = findMainVersion(doc); return doc.versions.map((version) => { + // eslint-disable-next-line @typescript-eslint/no-unused-vars const { label, badges, ...rest } = version; // TODO: This could be removed once we don't use points in paths anymore. @@ -42,19 +43,20 @@ function generatePluginConfig(pluginConfig, basePath) { path: path.resolve(extended_base_path + '/docs'), routeBasePath: plugin_name_path, sidebarPath: path.resolve(extended_base_path + '/sidebars.js'), + ...(doc.versions.length > 1 + ? { + versions: { + current: { + label, + path: mainVersion.label === label ? undefined : label, + badge: true, + }, + }, + } + : {}), ...rest, }; - if (doc.versions.length > 1) { - plugin.versions = { - current: { - label, - path: mainVersion.label === label ? undefined : label, - badge: true, - }, - }; - } - return plugin; }); }); diff --git a/src/utils/useSwitcher.ts b/src/utils/useSwitcher.ts index 409a51c18eb..52e3abcfa01 100644 --- a/src/utils/useSwitcher.ts +++ b/src/utils/useSwitcher.ts @@ -159,7 +159,7 @@ export default function useSwitcher(): SwitcherProps { }); // Resolve the subsection link to the first doc configured. - let to = docLinks[0].to; + const to = docLinks[0].to; let active = false; if (current.subsection && subsection.id === current.subsection.id) {