Skip to content

Commit

Permalink
Add dynamic linking feature that generates links to versioned Javadocs (
Browse files Browse the repository at this point in the history
#627)

* Create JavadocLink.js

* Add `className` to versions for JavadocLink use

* Add instruction in comment
  • Loading branch information
josh-wong authored Dec 26, 2024
1 parent b303943 commit e819ecb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,26 @@ const config = {
label: '<VERSION_NUMBER>',
path: 'latest', // When a new version is released and this is no longer the current version, change this to the version number and then delete this comment.
banner: 'none',
className: 'X.X.X', // This should be the most recent version (major.minor.patch) so that the Javadoc links point to the latest version based on the major.minor version that the visitor is viewing on the docs site.
},
*/
current: { // When a new version is released and this is no longer the current version, change this to the version number and then delete this comment.
label: '3.10',
path: 'latest', // When a new version is released and this is no longer the current version, change this to the version number and then delete this comment.
banner: 'none',
className: '3.10.0',
},
"3.9": { // When a new version is released and this is no longer the current version, change this to the version number and then delete this comment.
label: '3.9',
path: '3.9', // When a new version is released and this is no longer the current version, change this to the version number and then delete this comment.
banner: 'none',
className: '3.9.4',
},
"3.8": {
label: '3.8',
path: '3.8',
banner: 'none',
className: '3.8.4',
},
"3.7": {
label: '3.7 (unsupported)',
Expand Down
30 changes: 30 additions & 0 deletions src/theme/JavadocLink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';
import { useActiveVersion } from '@docusaurus/plugin-content-docs/client';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';

export default function JavadocLink({ packageName, path, className }) {
const { siteConfig } = useDocusaurusContext();
const activeVersion = useActiveVersion();

// Retrieve className from siteConfig based on the active version.
const docsClassName =
siteConfig.presets?.[0]?.[1]?.docs?.versions?.[activeVersion.name]?.className;

// Log for debugging
console.log('Active Version:', activeVersion?.name);
console.log('Docs ClassName:', docsClassName);

// The link in the <a> code below is generated based on the following JavadocLink component that must be added in place of a static Javadoc link in the doc:
// <JavadocLink packageName="scalardl-common" path="com/scalar/dl/ledger/config" className="LedgerConfig" />
// In addition, be sure to add the following below the title to import the component:
// import JavadocLink from "/src/theme/JavadocLink.js";
return (
<a
href={`https://javadoc.io/static/com.scalar-labs/${packageName}/${docsClassName}/${path}/${className}.html`}
target="_blank"
rel="noopener noreferrer"
>
{className}
</a>
);
}

0 comments on commit e819ecb

Please sign in to comment.