Skip to content

Commit e819ecb

Browse files
authored
Add dynamic linking feature that generates links to versioned Javadocs (#627)
* Create JavadocLink.js * Add `className` to versions for JavadocLink use * Add instruction in comment
1 parent b303943 commit e819ecb

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

docusaurus.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,26 @@ const config = {
6969
label: '<VERSION_NUMBER>',
7070
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.
7171
banner: 'none',
72+
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.
7273
},
7374
*/
7475
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.
7576
label: '3.10',
7677
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.
7778
banner: 'none',
79+
className: '3.10.0',
7880
},
7981
"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.
8082
label: '3.9',
8183
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.
8284
banner: 'none',
85+
className: '3.9.4',
8386
},
8487
"3.8": {
8588
label: '3.8',
8689
path: '3.8',
8790
banner: 'none',
91+
className: '3.8.4',
8892
},
8993
"3.7": {
9094
label: '3.7 (unsupported)',

src/theme/JavadocLink.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from 'react';
2+
import { useActiveVersion } from '@docusaurus/plugin-content-docs/client';
3+
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
4+
5+
export default function JavadocLink({ packageName, path, className }) {
6+
const { siteConfig } = useDocusaurusContext();
7+
const activeVersion = useActiveVersion();
8+
9+
// Retrieve className from siteConfig based on the active version.
10+
const docsClassName =
11+
siteConfig.presets?.[0]?.[1]?.docs?.versions?.[activeVersion.name]?.className;
12+
13+
// Log for debugging
14+
console.log('Active Version:', activeVersion?.name);
15+
console.log('Docs ClassName:', docsClassName);
16+
17+
// 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:
18+
// <JavadocLink packageName="scalardl-common" path="com/scalar/dl/ledger/config" className="LedgerConfig" />
19+
// In addition, be sure to add the following below the title to import the component:
20+
// import JavadocLink from "/src/theme/JavadocLink.js";
21+
return (
22+
<a
23+
href={`https://javadoc.io/static/com.scalar-labs/${packageName}/${docsClassName}/${path}/${className}.html`}
24+
target="_blank"
25+
rel="noopener noreferrer"
26+
>
27+
{className}
28+
</a>
29+
);
30+
}

0 commit comments

Comments
 (0)