From 11febfbd275462fbf44cd3557162aaeedcc115bf Mon Sep 17 00:00:00 2001 From: anshumancanrock Date: Wed, 5 Aug 2026 10:28:53 +0530 Subject: [PATCH] fix: hoist useBaseUrl calls to follow Rules of Hooks Signed-off-by: anshumancanrock --- src/pages/case-studies.js | 5 ++-- src/pages/index.js | 38 ++++++++++++++------------ src/theme/BlogPostItem/Header/index.js | 7 ++--- src/theme/Footer/index.js | 23 ++++++++-------- 4 files changed, 37 insertions(+), 36 deletions(-) diff --git a/src/pages/case-studies.js b/src/pages/case-studies.js index 2538323a3..2e5465ba0 100644 --- a/src/pages/case-studies.js +++ b/src/pages/case-studies.js @@ -1,6 +1,6 @@ import Layout from "@theme/Layout"; import useDocusaurusContext from "@docusaurus/useDocusaurusContext"; -import useBaseUrl from "@docusaurus/useBaseUrl"; +import { useBaseUrlUtils } from "@docusaurus/useBaseUrl"; import caseStudies from "../data/caseStudies"; import styles from "./case-studies.module.css"; @@ -16,6 +16,7 @@ function formatDate(date, locale) { export default function CaseStudiesPage() { const { i18n } = useDocusaurusContext(); + const { withBaseUrl } = useBaseUrlUtils(); const isZh = i18n.currentLocale === "zh"; const t = (item) => (isZh ? item.zh : item.en); @@ -48,7 +49,7 @@ export default function CaseStudiesPage() {
{displayName} diff --git a/src/pages/index.js b/src/pages/index.js index ce7866f4f..8e17945c2 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -2,7 +2,7 @@ import React, { useEffect, useRef, useCallback, useState } from "react"; import clsx from "clsx"; import Layout from "@theme/Layout"; import Link from "@docusaurus/Link"; -import useBaseUrl from "@docusaurus/useBaseUrl"; +import { useBaseUrlUtils } from "@docusaurus/useBaseUrl"; import useDocusaurusContext from "@docusaurus/useDocusaurusContext"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { @@ -373,14 +373,15 @@ function RuntimeLaneCard({ lane, locale }) { export default function Home() { const { i18n } = useDocusaurusContext(); + const { withBaseUrl } = useBaseUrlUtils(); const isZh = i18n.currentLocale === "zh"; const [starsCount, setStarsCount] = useState(3100); // Static: Docker Hub's API sends no CORS header, so it cannot be read from the browser. const dockerPulls = 325000; - const kubernetesLogo = useBaseUrl("img/kubernetes-logo.svg"); - const hamiLogo = useBaseUrl("img/hami-graph-color.svg"); - const hamiHorizontalLogoLight = useBaseUrl("img/hami-horizontal-color-black.svg"); - const hamiHorizontalLogoDark = useBaseUrl("img/hami-horizontal-color-white.svg"); + const kubernetesLogo = withBaseUrl("img/kubernetes-logo.svg"); + const hamiLogo = withBaseUrl("img/hami-graph-color.svg"); + const hamiHorizontalLogoLight = withBaseUrl("img/hami-horizontal-color-black.svg"); + const hamiHorizontalLogoDark = withBaseUrl("img/hami-horizontal-color-white.svg"); const contributorsCount = useCountUp(500); const contributorCountries = useCountUp(27); const starsCountDisplay = useCountUp(starsCount); @@ -494,11 +495,14 @@ export default function Home() {
{isZh ? "快速开始" : "Quick Start"} - + {isZh ? "加入社区" : "Join Community"}
@@ -521,7 +525,7 @@ export default function Home() {
{item.logo ? ( {pickLocalizedOrRaw(i18n.currentLocale, ) : ( @@ -542,7 +546,7 @@ export default function Home() { {heroSchedulerEcosystem.map((item) => (
{pickLocalizedOrRaw(i18n.currentLocale,
@@ -624,13 +628,13 @@ export default function Home() {
Prometheus
OpenTelemetry
@@ -649,7 +653,7 @@ export default function Home() { {heroDeviceEcosystem.map((item) => (
{pickLocalizedOrRaw(i18n.currentLocale,
@@ -672,14 +676,14 @@ export default function Home() {
CNCF logo
CNAI Landscape logo @@ -860,7 +864,7 @@ export default function Home() { rel="noopener noreferrer" className="adopter-card-link" > - {vendor.logo && {vendor.name}} + {vendor.logo && {vendor.name}} ))} @@ -868,7 +872,7 @@ export default function Home() {
{isZh ? "查看完整设备支持列表 →" : "View full supported devices list →"} @@ -1032,7 +1036,7 @@ export default function Home() { > {isZh ? "给 HAMi 点个 Star" : "Star HAMi on GitHub"} - + {isZh ? "加入社区" : "Join Community"}
diff --git a/src/theme/BlogPostItem/Header/index.js b/src/theme/BlogPostItem/Header/index.js index 1b746fd7b..fa928157b 100644 --- a/src/theme/BlogPostItem/Header/index.js +++ b/src/theme/BlogPostItem/Header/index.js @@ -31,6 +31,7 @@ export default function BlogPostItemHeader() { const { metadata, frontMatter, isBlogPostPage } = useBlogPost(); const { i18n } = useDocusaurusContext(); const cover = frontMatter.cover; + const coverUrl = useBaseUrl(cover || ""); const fallbackLabel = ( {isBlogPostPage && cover && (
- {frontMatter.title + {frontMatter.title
)} diff --git a/src/theme/Footer/index.js b/src/theme/Footer/index.js index c8cbdd474..183e8250d 100644 --- a/src/theme/Footer/index.js +++ b/src/theme/Footer/index.js @@ -84,12 +84,12 @@ function Footer() { const { i18n } = useDocusaurusContext(); const [isWechatModalOpen, setIsWechatModalOpen] = useState(false); const [isWechatOfficialOpen, setIsWechatOfficialOpen] = useState(false); - - if (!footer) { - return null; - } - - const { copyright, links, logo, style } = footer; + const cncfLogoLight = useBaseUrl("img/cncf-color.svg"); + const cncfLogoDark = useBaseUrl("img/cncf-white.svg"); + const wechatGroupQr = useBaseUrl("img/community/wechat-assistant-qr.jpg"); + const wechatOfficialQr = useBaseUrl("img/community/wechat-official-account-qr.jpg"); + const cncfLogo = colorMode === "dark" ? cncfLogoDark : cncfLogoLight; + const isZh = i18n.currentLocale === "zh"; useEffect(() => { if (i18n.currentLocale !== "zh") { @@ -119,6 +119,11 @@ function Footer() { return () => document.removeEventListener("click", onFooterLinkClick, true); }, [i18n.currentLocale]); + if (!footer) { + return null; + } + + const { copyright, links, logo, style } = footer; const zhOnlyLabels = new Set(["WeChat Group", "WeChat Official Account"]); const adjustedLinks = i18n.currentLocale === "zh" @@ -167,12 +172,6 @@ function Footer() { })); const footerLinks = iconizedLinks && iconizedLinks.length > 0 ? : null; - const isZh = i18n.currentLocale === "zh"; - const cncfLogoLight = useBaseUrl("img/cncf-color.svg"); - const cncfLogoDark = useBaseUrl("img/cncf-white.svg"); - const cncfLogo = colorMode === "dark" ? cncfLogoDark : cncfLogoLight; - const wechatGroupQr = useBaseUrl("img/community/wechat-assistant-qr.jpg"); - const wechatOfficialQr = useBaseUrl("img/community/wechat-official-account-qr.jpg"); return ( <>