-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |