Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 7 additions & 4 deletions docs/docusaurus.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-check
const lightCodeTheme = require('prism-react-renderer').themes.github;
const darkCodeTheme = require('prism-react-renderer').themes.dracula;
const webforjVersion = `${process.env.WEBFORJ_VERSION || 'latest'}`;

/** @type {import('@docusaurus/types').Config} */
const config = {
Expand All @@ -14,6 +15,9 @@ const config = {
organizationName: 'webforj',
projectName: 'webforj-docs',
trailingSlash: false,
customFields: {
webforjVersion: `${webforjVersion}`,
},
i18n: {
defaultLocale: 'en',
locales: ['en', 'es', 'de', 'fr', 'nl', 'fi', 'zh'],
Expand Down Expand Up @@ -58,8 +62,7 @@ const config = {
scripts: [
{ src: '/js/dwc-theme-switcher.js', async: false },
{ src: '/js/link-decorator.js' },
{ src: '/js/style-startforj.js', defer: true},
{ src: '/js/latest-webforj-version.js', defer: true}
{ src: '/js/style-startforj.js', defer: true}
],
headTags: [
{
Expand Down Expand Up @@ -151,7 +154,7 @@ const config = {
announcementBar: {
id: '25.03',
content:
'We are excited to announce webforJ version 25.03 is live! Read more about the changes and features <a href=/blog/whats-new-v25.03>here.</a> ',
`We are excited to announce webforJ version ${webforjVersion} is live! Read more about the changes and features <a href=/blog/whats-new-v${webforjVersion}>here.</a>`,
isCloseable: true,
},
image: 'https://docs.webforj.com/img/social-cover.png',
Expand All @@ -166,7 +169,7 @@ const config = {
items: [
{
position: 'left',
label: ' ',
label: `v${webforjVersion}`,
href: 'https://github.com/webforj/webforj/releases/latest',
target: '_blank',
id: 'webforj-version-badge',
Expand Down
47 changes: 5 additions & 42 deletions docs/src/components/DocsTools/JavadocLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { useState, useEffect } from "react";
import { css } from "@emotion/react";
import { Tooltip, Chip } from "@mui/material";
import AutoStoriesIcon from "@mui/icons-material/AutoStories";
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';

export default function JavadocLink({
type,
Expand All @@ -12,6 +13,7 @@ export default function JavadocLink({
code,
suffix,
}) {
const {siteConfig} = useDocusaurusContext();
const [url, setUrl] = useState("");
const [hasDocChips, setHasDocChips] = useState(false);

Expand All @@ -26,49 +28,10 @@ export default function JavadocLink({
}, []);

useEffect(() => {
async function fetchLatestVersion() {
const resolvedSuffix = suffix || "";
const cacheKey = "webforj_latest_version";
const cacheExpiry = 24 * 60 * 60 * 1000; // 24 hours

const cachedData = localStorage.getItem(cacheKey);
const cachedTimestamp = localStorage.getItem(`${cacheKey}_timestamp`);

if (cachedData && cachedTimestamp && (Date.now() - cachedTimestamp) < cacheExpiry) {
const latestVersion = cachedData;
setUrl(
`https://javadoc.io/doc/com.webforj/webforj-${type}/${latestVersion}/${location}.html${resolvedSuffix}`
);
return;
}

try {
const response = await fetch(
"https://api.github.com/repos/webforj/webforj/releases/latest"
);
if (!response.ok) {
throw new Error(`GitHub API error: ${response.statusText}`);
}

const data = await response.json();
const latestVersion = data.tag_name;
console.log(latestVersion);

localStorage.setItem(cacheKey, latestVersion);
localStorage.setItem(`${cacheKey}_timestamp`, Date.now());

setUrl(
`https://javadoc.io/doc/com.webforj/webforj-${type}/${latestVersion}/${location}.html${resolvedSuffix}`
);
} catch (error) {
console.error("Failed to fetch the latest version:", error);
setUrl(
`https://javadoc.io/doc/com.webforj/webforj-${type}/latest/${location}.html${resolvedSuffix}`
);
}
}
fetchLatestVersion();
}, [type, location, suffix]);
setUrl(`https://javadoc.io/doc/com.webforj/webforj-${type}/${siteConfig.customFields.webforjVersion}/${location}.html${resolvedSuffix}`
);
}, [type, location, suffix]);

const mainStyles = css`
${(top) =>
Expand Down
56 changes: 0 additions & 56 deletions docs/static/js/latest-webforj-version.js

This file was deleted.

3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@
</goals>
<phase>generate-resources</phase>
<configuration>
<environmentVariables>
<WEBFORJ_VERSION>${webforj.version}</WEBFORJ_VERSION>
</environmentVariables>
<arguments>run build</arguments>
</configuration>
</execution>
Expand Down