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

Docusaurus versioning #2

Merged
merged 27 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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
5 changes: 3 additions & 2 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ jobs:
with:
node-version: "16.x"

shell: bash
- run: yarn build
- name: Build 🔧
run: yarn install --frozen-lockfile
run: yarn build

- name: Deploy 🚀
uses: JamesIves/[email protected]
Expand Down
78 changes: 78 additions & 0 deletions custom-version-plugin.js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not too sure what this does. Where is that plugin added as well?
Could this get a small doc? I am trying to understand how it created those files, as they aren't in /docs folder.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just the action they use in docusaurus, i was having trouble last night getting it to build so trying all options. The custom plugin is specified in docusaurus.config.js. It uses all the files from main and any of those that arent the same, they have their own version. Additionally, there is version_config which removes specific files or paths from versions. This way its very clear as to what is in each version when its built

Copy link
Member

@julienrbrt julienrbrt Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not seeing it in the docusaurus.config.js. Which main are we talking about? This repo?

It uses all the files from main and any of those that arent the same, they have their own version.

Ok, so the process of adding a custom content for a version is manual right? If so, this means the versioning is definitely incomplete, won't it be a hell to maintain?
Again, only if my understanding is correct: If I want to change the content only for main, does not this mean I need to first copy the old content to each of the versioned SDK versions, where I want the content to stay the same and then edit the latest content?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol good catch, I removed this by accident c7d8c0d#diff-a038096cbdea434999e1dce5ab497212f1fe18204dde1a027ce3bdd663261a2aL210

but ill fix this up.

For the second point, the process of adding custom content will be automated. I have been working on a script that for any md file that is updated, removed or added will be copied to the specific version/main within the docs repo.

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
const fs = require('fs');
const path = require('path');

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

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

return arrayOfFiles;
}

function shouldExcludeFile(version, filePath, versionConfig) {
const excludedPaths = versionConfig[version]?.excludedPaths || [];
return excludedPaths.some((excludedPath) => filePath.startsWith(excludedPath));
}

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 the version config file
const versionConfigPath = path.join(_context.siteDir, 'version_config.json');
const versionConfig = JSON.parse(fs.readFileSync(versionConfigPath, '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) && !shouldExcludeFile(version, relativePath, versionConfig)) {
// If the file doesn't exist and it's not excluded, copy it from the /docs folder
const customFileDir = path.dirname(customFilePath);
fs.mkdirSync(customFileDir, { recursive: true });
fs.copyFileSync(file, customFilePath);
console.log(`Copied file from /docs to version-${version}:`, relativePath);
}
}

// After copying all files, iterate over the versioned directory to remove excluded files
const versionedFiles = getAllFiles(versionedDocsPath);
for (const file of versionedFiles) {
const relativePath = path.relative(versionedDocsPath, file);

if (shouldExcludeFile(version, relativePath, versionConfig)) {
fs.unlinkSync(file);
console.log(`Removed excluded file from version-${version}:`, relativePath);
}
}
}
}
},
};
};
2 changes: 1 addition & 1 deletion docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const config = {
tagline:
"Cosmos SDK is the world's most popular framework for building application-specific blockchains.",
url: "https://docs.cosmos.network",
baseUrl: "/",
baseUrl: "/cosmos-sdk-docs",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! It could be handy to have this tiny thing in a separate PR so that https://cosmos.github.io/cosmos-sdk-docs can work sooner.

onBrokenLinks: "warn",
onBrokenMarkdownLinks: "warn",
favicon: "img/favicon.svg",
Expand Down
31 changes: 31 additions & 0 deletions version_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"0.45": {
"excludedPaths": ["integrate/modules/slashing", "integrate/modules/nft", "integrate/building-modules/15-depinject.md", "integrate/modules/genutil",
"integrate/modules/consensus", "integrate/modules/circuit", "integrate/building-apps","integrate/building-modules/autocli", "integrate/building-modules/depinject",
"integrate/building-modules/testing", "integrate/building-apps", "integrate/architecture/rfc", "integrate/specs", "integrate/architecture/adr-041-in-place-store-migrations", "integrate/architecture/adr-042-group-module",
"integrate/architecture/adr-043-nft-module", "integrate/architecture/adr-044-protobuf-updates-guidelines", "integrate/architecture/adr-045-check-delivertx-middlewares",
"integrate/architecture/adr-046-module-params", "integrate/architecture/adr-046-module-params", "integrate/architecture/adr-047-extend-upgrade-plan",
"integrate/architecture/adr-048-consensus-fees", "integrate/architecture/adr-049-state-sync-hooks", "integrate/architecture/adr-050-sign-mode-textual",
"integrate/architecture/adr-050-sign-mode-textual-annex1", "integrate/architecture/adr-050-sign-mode-textual-annex2", "integrate/architecture/adr-053-go-module-refactoring","integrate/architecture/adr-054-semver-compatible-modules",
"integrate/architecture/adr-055-orm", "integrate/architecture/adr-057-app-wiring", "integrate/architecture/adr-058-auto-generated-cli", "integrate/architecture/adr-059-test-scopes",
"integrate/architecture/adr-060-abci-1.0", "integrate/architecture/adr-061-liquid-staking", "integrate/architecture/adr-062-collections-state-layer",
"integrate/architecture/adr-062-collections-state-layer", "integrate/architecture/adr-063-core-module-api", "integrate/architecture/adr-064-abci-2.0",
"integrate/architecture/adr-065-store-v2", "integrate/architecture/README"]
},
"0.46": {
"excludedPaths": ["integrate/modules/genutil", "integrate/building-modules/15-depinject.md","integrate/modules/consensus", "integrate/modules/circuit", "integrate/architecture/rfc",
"integrate/specs", "integrate/building-apps", "integrate/building-modules/depinject", "integrate/architecture/adr-007-specialization-groups",
"integrate/architecture/adr-008-dCERT-group", "integrate/architecture/adr-014-proportional-slashing",
"integrate/architecture/adr-034-account-keying", "integrate/architecture/adr-041-in-place-store-migrations", "integrate/architecture/adr-042-group-module",
"integrate/architecture/adr-043-nft-module", "integrate/architecture/adr-044-protobuf-updates-guidelines", "integrate/architecture/adr-045-check-delivertx-middlewares",
"integrate/architecture/adr-048-consensus-fees", "integrate/architecture/adr-049-state-sync-hooks", "integrate/architecture/adr-050-sign-mode-textual",
"integrate/architecture/adr-050-sign-mode-textual-annex1", "integrate/architecture/adr-050-sign-mode-textual-annex2", "integrate/architecture/adr-054-semver-compatible-modules",
"integrate/architecture/adr-055-orm", "integrate/architecture/adr-057-app-wiring", "integrate/architecture/adr-058-auto-generated-cli", "integrate/architecture/adr-059-test-scopes",
"integrate/architecture/adr-060-abci-1.0", "integrate/architecture/adr-061-liquid-staking", "integrate/architecture/adr-062-collections-state-layer",
"integrate/architecture/adr-062-collections-state-layer", "integrate/architecture/adr-063-core-module-api", "integrate/architecture/adr-064-abci-2.0",
"integrate/architecture/adr-065-store-v2", "integrate/architecture/README"]
},
"0.47": {
"excludedPaths": []
}
}
20 changes: 20 additions & 0 deletions versioned_docs/version-0.45/integrate/ibc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!--
order: false
parent:
order: 5
-->

# IBC

This repository contains reference documentation for the IBC protocol integration and concepts:

1. [Overview](overview.md)
2. [Integration](integration.md)
3. [Customization](custom.md)
4. [Relayer](relayer.md)
5. [Governance Proposals](proposals.md)

**NOTE**: The IBC module has been moved to its [own repository](https://github.com/cosmos/ibc-go).

After reading about IBC, head on to the [Building Modules
documentation](../building-modules/) to learn more about the process of building modules.
Loading