Skip to content

Commit

Permalink
[Enhancement]:Optimize navbar (apache#1497)
Browse files Browse the repository at this point in the history
1. Optimize navbar
2. Fixed the issue that the Community Page language switching function
is lost.
3. Remove `技术论坛`
4. Fix the problem of missing url parameters.

---------

Co-authored-by: liyang <liyang@selectdb.com>
  • Loading branch information
2 people authored and echo-hhj committed Jan 6, 2025
1 parent 098cfe6 commit 764447a
Show file tree
Hide file tree
Showing 8 changed files with 282 additions and 255 deletions.
154 changes: 43 additions & 111 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ const config = {
explicitSearchResultPath: true,
searchBarShortcut: true,
searchBarShortcutHint: true,
searchResultLimits: 100
searchResultLimits: 100,
},
],
],
Expand Down Expand Up @@ -293,61 +293,6 @@ const config = {
type: 'docsVersionDropdown',
position: 'right',
},
// {
// label: '快速开始',
// position: 'left',
// // to: '/docs/gettingStarted/what-is-new',
// type: 'doc',
// docId: 'gettingStarted/what-is-new',
// activeBaseRegex: 'what-is-new|what-is-apache-doris|quick-start|tutorials',
// },
// {
// label: '使用指南',
// position: 'left',
// // to: '/docs/install/source-install/compilation-with-docker',
// type: 'doc',
// docId: 'install/source-install/compilation-with-docker',
// activeBaseRegex:
// 'summary|install/cluster-deployment|install/source-install|db-connect|table-design|data-operate|query|lakehouse|compute-storage-decoupled|admin-manual|practical-guide|sql-manual',
// },
// {
// label: '性能测试',
// position: 'left',
// // to: '/docs/benchmark/ssb',
// type: 'doc',
// docId: 'benchmark/ssb',
// activeBaseRegex: 'benchmark',
// },
// {
// label: '生态工具',
// position: 'left',
// // to: '/docs/ecosystem/spark-doris-connector',
// type: 'doc',
// docId: 'ecosystem/spark-doris-connector',
// activeBaseRegex: 'ecosystem',
// },
// {
// label: '常见问题',
// position: 'left',
// // to: '/docs/faq/install-faq',
// type: 'doc',
// docId: 'faq/install-faq',
// activeBaseRegex: 'faq',
// },
// {
// label: '版本发布',
// position: 'left',
// // to: '/docs/releasenotes/all-release',
// type: 'doc',
// docId: 'releasenotes/all-release',
// activeBaseRegex: 'releasenotes',
// },
// {
// type: 'html',
// position: 'left',
// value: `<a href="https://ask.selectdb.com/" target="_blank" style="display: flex; align-items: center; justify-content: center; text-decoration: none">技术论坛<img style="width: 1.2rem; height: 1.2rem; margin-left: 0.2rem;font-family: 'SF Pro Display', 'SF Pro Icons', 'Helvetica Neue', Helvetica, Arial, sans-serif;" src="/images/forum-logo.svg">
// </a>`,
// },
],
},
docNavbarEN: {
Expand All @@ -370,61 +315,48 @@ const config = {
type: 'docsVersionDropdown',
position: 'right',
},
// {
// label: 'Getting Started',
// position: 'left',
// // to: '/docs/gettingStarted/what-is-new',
// type: 'doc',
// docId: 'gettingStarted/what-is-new',
// activeBaseRegex: 'what-is-new|what-is-apache-doris|quick-start|tutorials',
// },
// {
// label: 'Guides',
// position: 'left',
// // to: '/docs/install/source-install/compilation-with-docker',
// type: 'doc',
// docId: 'install/source-install/compilation-with-docker',
// activeBaseRegex:
// 'summary|install/cluster-deployment|install/source-install|db-connect|table-design|data-operate|query|lakehouse|compute-storage-decoupled|admin-manual|practical-guide|sql-manual',
// },
// {
// label: 'Benchmark',
// position: 'left',
// // to: '/docs/benchmark/ssb',
// type: 'doc',
// docId: 'benchmark/ssb',
// activeBaseRegex: 'benchmark',
// },
// {
// label: 'Ecosystem',
// position: 'left',
// // to: '/docs/ecosystem/spark-doris-connector',
// type: 'doc',
// docId: 'ecosystem/spark-doris-connector',
// activeBaseRegex: 'ecosystem',
// },
// {
// label: 'FAQ',
// position: 'left',
// // to: '/docs/faq/install-faq',
// type: 'doc',
// docId: 'faq/install-faq',
// activeBaseRegex: 'faq',
// },
// {
// label: 'Releases',
// position: 'left',
// // to: '/docs/releasenotes/all-release',
// type: 'doc',
// docId: 'releasenotes/all-release',
// activeBaseRegex: 'releasenotes',
// },
// {
// type: 'html',
// position: 'left',
// value: `<a href="https://github.com/apache/doris/discussions" target="_blank" style="display: flex; align-items: center; justify-content: center; text-decoration: none;">Forum<img style="width: 1.2rem; height: 1.2rem; margin-left: 0.2rem;" src="/images/forum-logo.svg">
// </a>`,
// },
],
},
communityNavbar: {
title: '',
logo: {
alt: 'Apache Doris',
src: logoImg,
},
items: [
{
position: 'left',
label: 'Docs',
to: '/docs/gettingStarted/what-is-new',
target: '_blank',
},
{ to: '/blog', label: 'Blog', position: 'left' },
{ to: '/users', label: 'Users', position: 'left' },
{
label: 'Discussions',
to: 'https://github.com/apache/doris/discussions',
position: 'left',
},
{
label: 'Ecosystem',
to: '/ecosystem/cluster-management',
position: 'left',
},
{
label: 'Community',
to: '/community/join-community',
position: 'left',
},
{
href: '/download',
className: 'header-right-button-primary navbar-download-mobile',
label: 'Download',
position: 'right',
},
{
type: 'localeDropdown',
position: 'right',
},
],
},
footer: {
Expand Down
14 changes: 0 additions & 14 deletions src/scss/common.scss
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
.docs-wrapper {
.navbar__inner {
.navbar__items--right {
.header-right-button-github,
.header-right-button-slack {
display: none;
}
}
}
.navbar__bottom {
display: none;
}
}

@media screen and (max-width: 996px) {
.docs-wrapper {
.navbar__inner {
Expand Down
9 changes: 6 additions & 3 deletions src/theme/Layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ export default function Layout(props: Props): JSX.Element {
if (
history.location.pathname?.length > 1 &&
history.location.pathname[history.location.pathname.length - 1] === '/'
)
history.replace(history.location.pathname.slice(0, -1));
}, []);
){
const params = location.href.split(history.location.pathname)[1];
history.replace(history.location.pathname.slice(0, -1) + params);
}

}, [history.location]);

return (
<LayoutProvider>
Expand Down
57 changes: 57 additions & 0 deletions src/theme/Navbar/Content/components/NavbarCommon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React, { useEffect, useState } from 'react';
import { useThemeConfig } from '@docusaurus/theme-common';
import { splitNavbarItems } from '@docusaurus/theme-common/internal';
import NavbarLogo from '@theme/Navbar/Logo';
import Link from '@docusaurus/Link';
import Translate from '@docusaurus/Translate';
import NavbarItem, { type Props as NavbarItemConfig } from '@theme/NavbarItem';

import { NavbarItems } from '..';
import styles from '../styles.module.css';

function useNavbarItems() {
return useThemeConfig().navbar.items as NavbarItemConfig[];
}

export const NavbarCommonLeft = () => {
const items = useNavbarItems();
const [leftItems] = splitNavbarItems(items);

return (
<div className={`navbar-left `}>
<div className="navbar-logo-wrapper flex items-center">
<NavbarLogo />
</div>
<div className={`${styles.navbarLeftToc}`}>
<NavbarItems items={leftItems} />
</div>
</div>
);
};

interface NavbarCommonRightProps {
star: string;
}

export const NavbarCommonRight = ({ star }: NavbarCommonRightProps) => {
const items = useNavbarItems();
const [, rightItems] = splitNavbarItems(items);

return (
<>
<NavbarItems items={rightItems} />
<Link
className="github-btn desktop header-right-button-github"
href="https://github.com/apache/doris"
target="_blank"
>
{star && <div className="gh-count">{star}k</div>}
</Link>
<Link
className="slack-btn desktop header-right-button-slack"
href="https://join.slack.com/t/apachedoriscommunity/shared_invite/zt-2unfw3a3q-MtjGX4pAd8bCGC1UV0sKcw"
target="_blank"
></Link>
</>
);
};
44 changes: 44 additions & 0 deletions src/theme/Navbar/Content/components/NavbarCommunity.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react';
import { useThemeConfig } from '@docusaurus/theme-common';
import { splitNavbarItems } from '@docusaurus/theme-common/internal';
import NavbarLogo from '@theme/Navbar/Logo';
import { type Props as NavbarItemConfig } from '@theme/NavbarItem';

import { getNavItem } from '..';
import { NavbarItems } from '..';
import LocaleDropdownNavbarItem from '../../../NavbarItem/LocaleDropdownNavbarItem';
import styles from '../styles.module.css';

function useNavbarItems() {
return useThemeConfig().communityNavbar.items as NavbarItemConfig[];
}

export const NavbarCommunityLeft = () => {
const items = useNavbarItems();
const [leftItems] = splitNavbarItems(items);
return (
<div className={`navbar-left `}>
<div className="navbar-logo-wrapper flex items-center">
<NavbarLogo />
</div>
<div className={`${styles.navbarLeftToc}`}>
<NavbarItems items={leftItems} />
</div>
</div>
);
};

export const NavbarCommunityRight = () => {
const items = useNavbarItems();
const [, rightItems] = splitNavbarItems(items);
return <NavbarItems items={rightItems} />;
};

export const NavbarCommunityBottom = () => {
const items = useNavbarItems();
return (
<div className="docs-nav-version-locale">
<LocaleDropdownNavbarItem mobile={false} {...getNavItem(items, 'localeDropdown')} />
</div>
);
};
72 changes: 72 additions & 0 deletions src/theme/Navbar/Content/components/NavbarDocs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import styles from '../styles.module.css';
import React, { useState, useEffect } from 'react';
import { useLocation } from '@docusaurus/router';
import { useThemeConfig } from '@docusaurus/theme-common';
import { splitNavbarItems } from '@docusaurus/theme-common/internal';
import DocsLogoNew from '@site/static/images/doc-logo-new.svg';
import DocsLogoZH from '@site/static/images/doc-logo-zh.svg';
import LocaleDropdownNavbarItem from '../../../NavbarItem/LocaleDropdownNavbarItem';
import DocsVersionDropdownNavbarItem from '../../../NavbarItem/DocsVersionDropdownNavbarItem';
import { NavbarItems,getNavItem } from '..';

interface NavbarDocsProps {
isEN: boolean;
}

export const NavbarDocsLeft = ({ isEN }: NavbarDocsProps) => {
const [currentVersion, setCurrentVersion] = useState('');
const location = useLocation();
const docItems = isEN ? useThemeConfig().docNavbarEN.items : useThemeConfig().docNavbarZH.items;
const [leftDocItems] = splitNavbarItems(docItems);
useEffect(() => {
const secPath = location.pathname.includes('zh-CN/docs')
? location.pathname.split('/')[3]
: location.pathname.split('/')[2];
if (location.pathname.includes('docs') && ['dev', '2.1', '2.0', '1.2'].includes(secPath)) {
setCurrentVersion(secPath);
} else {
setCurrentVersion('');
}
}, [typeof window !== 'undefined' && location.pathname]);
return (
<div className={`navbar-left `}>
<div className="navbar-logo-wrapper flex items-center">
<div
className="cursor-pointer docs"
onClick={() => {
window.location.href = `${isEN ? '' : '/zh-CN'}/docs${
currentVersion === '' ? '' : `/${currentVersion}`
}/gettingStarted/what-is-new`;
}}
>
{isEN ? <DocsLogoNew /> : <DocsLogoZH />}
</div>
</div>
<div className={`${styles.navbarLeftToc}`}>
<NavbarItems items={leftDocItems} isDocsPage={true} />
</div>
</div>
);
};

export const NavbarDocsRight = ({ isEN }: NavbarDocsProps) => {
const docItems = isEN ? useThemeConfig().docNavbarEN.items : useThemeConfig().docNavbarZH.items;
const [, rightDocItems] = splitNavbarItems(docItems);
return <NavbarItems items={rightDocItems} />;
};

export const NavbarDocsBottom = ({ isEN }: NavbarDocsProps) => {
const docItems = isEN ? useThemeConfig().docNavbarEN.items : useThemeConfig().docNavbarZH.items;
const [, rightDocItems] = splitNavbarItems(docItems);
return (
<div className="docs-nav-version-locale">
{/* getNavItem? */}
<LocaleDropdownNavbarItem mobile={false} {...(getNavItem(rightDocItems,'localeDropdown') as any)} />
<DocsVersionDropdownNavbarItem
mobile={false}
docsPluginId="default"
{...(getNavItem(rightDocItems,'docsVersionDropdown') as any)}
/>
</div>
);
};
Loading

0 comments on commit 764447a

Please sign in to comment.