Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
samricotta committed May 10, 2023
1 parent 06cd27c commit b888dbf
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 17 deletions.
59 changes: 59 additions & 0 deletions custom-version-plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const fs = require('fs');
const path = require('path');

// Helper function to get all files recursively from a directory
function getAllFiles(dirPath, arrayOfFiles) {
const files = fs.readdirSync(dirPath);

arrayOfFiles = arrayOfFiles || [];

files.forEach(function (file) {
if (fs.statSync(path.join(dirPath, file)).isDirectory()) {
arrayOfFiles = getAllFiles(path.join(dirPath, file), arrayOfFiles);
} else {
arrayOfFiles.push(path.join(dirPath, file));
}
});

return arrayOfFiles;
}

module.exports = function (_context, _options) {
return {
name: 'custom-version-plugin',

async loadContent() {
// Read the versions.json file to get the list of versions
const versionsJsonPath = path.join(_context.siteDir, 'versions.json');
const versions = JSON.parse(fs.readFileSync(versionsJsonPath, 'utf8'));

// Read all the files in the /docs folder
const docsPath = path.join(_context.siteDir, 'docs');
const files = getAllFiles(docsPath);

// Iterate through the list of versions
for (const version of versions) {
const versionedDocsPath = path.join(_context.siteDir, 'versioned_docs', `version-${version}`);

// Check if the version directory exists
if (fs.existsSync(versionedDocsPath)) {
// Iterate through the list of files in the /docs folder
for (const file of files) {
const relativePath = path.relative(docsPath, file);
const customFilePath = path.join(versionedDocsPath, relativePath);

// Check if the file exists in the version directory
if (!fs.existsSync(customFilePath)) {
// Create the directory if it doesn't exist
fs.mkdirSync(path.dirname(customFilePath), { recursive: true });

// If the file doesn't exist, copy it from the /docs folder
fs.copyFileSync(file, customFilePath);
console.log(`Copied file from /docs to version-${version}:`, relativePath);
}
}
}
}
},
};
};
5 changes: 0 additions & 5 deletions docs/develop/_category_.json
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
{
"label": "Develop",
"position": 0,
"link": null
}
15 changes: 3 additions & 12 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

const lightCodeTheme = require("prism-react-renderer/themes/github");
const darkCodeTheme = require("prism-react-renderer/themes/dracula");
const customVersionPlugin = require('./custom-version-plugin');


// const lastVersion = "v0.47";
const lastVersion = "current";
Expand Down Expand Up @@ -106,18 +108,6 @@ const config = {
position: "right",
dropdownActiveClassDisabled: true,
// versions not yet migrated to docusaurus
dropdownItemsAfter: [
{
href: "https://docs.cosmos.network/v0.46/",
label: "v0.46",
target: "_self",
},
{
href: "https://docs.cosmos.network/v0.45/",
label: "v0.45",
target: "_self",
},
],
},
],
},
Expand Down Expand Up @@ -218,6 +208,7 @@ const config = {
},
};
},
customVersionPlugin,
[
"@docusaurus/plugin-google-analytics",
{
Expand Down
Empty file.
Empty file.
Empty file.
26 changes: 26 additions & 0 deletions versioned_sidebars/version-0.45-sidebars.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"developSidebar": [
{
"type": "autogenerated",
"dirName": "develop"
}
],
"integrateSidebar": [
{
"type": "autogenerated",
"dirName": "integrate"
}
],
"userSidebar": [
{
"type": "autogenerated",
"dirName": "user"
}
],
"validateSidebar": [
{
"type": "autogenerated",
"dirName": "validate"
}
]
}
26 changes: 26 additions & 0 deletions versioned_sidebars/version-0.46-sidebars.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"developSidebar": [
{
"type": "autogenerated",
"dirName": "develop"
}
],
"integrateSidebar": [
{
"type": "autogenerated",
"dirName": "integrate"
}
],
"userSidebar": [
{
"type": "autogenerated",
"dirName": "user"
}
],
"validateSidebar": [
{
"type": "autogenerated",
"dirName": "validate"
}
]
}
26 changes: 26 additions & 0 deletions versioned_sidebars/version-0.47-sidebars.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"developSidebar": [
{
"type": "autogenerated",
"dirName": "develop"
}
],
"integrateSidebar": [
{
"type": "autogenerated",
"dirName": "integrate"
}
],
"userSidebar": [
{
"type": "autogenerated",
"dirName": "user"
}
],
"validateSidebar": [
{
"type": "autogenerated",
"dirName": "validate"
}
]
}
5 changes: 5 additions & 0 deletions versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
"0.47",
"0.46",
"0.45"
]

0 comments on commit b888dbf

Please sign in to comment.