This is an automated email from the ASF dual-hosted git repository.
VGalaxies pushed a commit to branch docusaurus-issue-103-preview
in repository https://gitbox.apache.org/repos/asf/hugegraph-doc.git
The following commit(s) were added to refs/heads/docusaurus-issue-103-preview
by this push:
new bd8f2688 docs: preserve locale in navbar links
bd8f2688 is described below
commit bd8f26882c44bd01e5a01c57be5cd6ce58ca3196
Author: VGalaxies <[email protected]>
AuthorDate: Tue May 5 14:01:42 2026 +0000
docs: preserve locale in navbar links
---
docusaurus.config.js | 44 ++++++++++++++++++++++++---
src/components/LocaleAwareNavbarItem/index.js | 29 ++++++++++++++++++
src/theme/NavbarItem/ComponentTypes.js | 2 ++
3 files changed, 71 insertions(+), 4 deletions(-)
diff --git a/docusaurus.config.js b/docusaurus.config.js
index ba1c1c2b..1e9b4a14 100644
--- a/docusaurus.config.js
+++ b/docusaurus.config.js
@@ -172,10 +172,46 @@ const config = {
src: 'img/hugegraph-logo.svg',
},
items: [
- {to: '/docs/', label: 'Docs', position: 'left'},
- {to: '/blog/', label: 'Blog', position: 'left'},
- {to: '/community/', label: 'Community', position: 'left'},
- {to: '/download/', label: 'Download', position: 'left'},
+ {
+ type: 'custom-localeAwareLink',
+ enTo: '/docs/',
+ cnTo: '/cn/docs/',
+ label: 'Docs',
+ cnLabel: '文档',
+ activeBasePath: '/docs/',
+ cnActiveBasePath: '/cn/docs/',
+ position: 'left',
+ },
+ {
+ type: 'custom-localeAwareLink',
+ enTo: '/blog/',
+ cnTo: '/cn/blog/',
+ label: 'Blog',
+ cnLabel: '博客',
+ activeBasePath: '/blog/',
+ cnActiveBasePath: '/cn/blog/',
+ position: 'left',
+ },
+ {
+ type: 'custom-localeAwareLink',
+ enTo: '/community/',
+ cnTo: '/cn/community/',
+ label: 'Community',
+ cnLabel: '社区',
+ activeBasePath: '/community/',
+ cnActiveBasePath: '/cn/community/',
+ position: 'left',
+ },
+ {
+ type: 'custom-localeAwareLink',
+ enTo: '/download/',
+ cnTo: '/cn/download/',
+ label: 'Download',
+ cnLabel: '下载',
+ activeBasePath: '/download/',
+ cnActiveBasePath: '/cn/download/',
+ position: 'left',
+ },
{
label: 'ASF',
position: 'right',
diff --git a/src/components/LocaleAwareNavbarItem/index.js
b/src/components/LocaleAwareNavbarItem/index.js
new file mode 100644
index 00000000..67b1b04d
--- /dev/null
+++ b/src/components/LocaleAwareNavbarItem/index.js
@@ -0,0 +1,29 @@
+import React from 'react';
+import {useLocation} from '@docusaurus/router';
+import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
+
+function isChinesePath(pathname) {
+ return pathname === '/cn' || pathname.startsWith('/cn/');
+}
+
+export default function LocaleAwareNavbarItem({
+ enTo,
+ cnTo,
+ cnLabel,
+ cnActiveBasePath,
+ label,
+ activeBasePath,
+ ...props
+}) {
+ const {pathname} = useLocation();
+ const isChinese = isChinesePath(pathname);
+
+ return (
+ <DefaultNavbarItem
+ {...props}
+ label={isChinese ? cnLabel || label : label}
+ to={isChinese ? cnTo : enTo}
+ activeBasePath={isChinese ? cnActiveBasePath || cnTo : activeBasePath ||
enTo}
+ />
+ );
+}
diff --git a/src/theme/NavbarItem/ComponentTypes.js
b/src/theme/NavbarItem/ComponentTypes.js
index 576aa5c5..4f869e86 100644
--- a/src/theme/NavbarItem/ComponentTypes.js
+++ b/src/theme/NavbarItem/ComponentTypes.js
@@ -1,7 +1,9 @@
import ComponentTypes from '@theme-original/NavbarItem/ComponentTypes';
import LanguageSwitcherNavbarItem from
'@site/src/components/LanguageSwitcherNavbarItem';
+import LocaleAwareNavbarItem from '@site/src/components/LocaleAwareNavbarItem';
export default {
...ComponentTypes,
'custom-languageSwitcher': LanguageSwitcherNavbarItem,
+ 'custom-localeAwareLink': LocaleAwareNavbarItem,
};