From 2dfa21abba7bacefc24639d1f427c7dbc3a18daf Mon Sep 17 00:00:00 2001 From: Haidong Xin Date: Tue, 10 Nov 2026 17:18:06 +0800 Subject: [PATCH 1/5] perf(site): optimize media and responsive navigation --- blog/2026-01-27-ultrarag-3.0-release.md | 20 +-- blog/authors.yml | 2 +- docusaurus.config.js | 11 +- src/components/NavbarItems/GithubStar.js | 50 ++++--- .../NavbarItems/GithubStar.module.css | 2 + .../NavbarItems/LanguageSwitcher.js | 4 + .../NavbarItems/LanguageSwitcher.module.css | 2 + src/components/NavbarItems/MegaMenu.js | 138 ++++++++---------- .../NavbarItems/MegaMenu.module.css | 18 ++- src/context/LanguageContext.js | 4 + src/css/custom.css | 57 +++++++- src/pages/contact.js | 18 ++- src/pages/contact.module.css | 4 +- src/pages/index.js | 134 ++++++++++++----- src/pages/index.module.css | 81 ++++++++-- src/pages/markdown-page.md | 7 - src/pages/research.js | 2 + src/pages/research.module.css | 10 +- src/pages/team.js | 46 +++--- src/pages/team.module.css | 4 +- .../Navbar/MobileSidebar/PrimaryMenu/index.js | 52 ++++++- .../PrimaryMenu/styles.module.css | 10 +- src/theme/TOCItems/index.js | 3 +- static/img/optimized/_UltraRAG_logo-400.webp | Bin 0 -> 8024 bytes .../img/optimized/feature-benchmark-400.webp | Bin 0 -> 17296 bytes .../img/optimized/feature-benchmark-640.webp | Bin 0 -> 34840 bytes .../img/optimized/feature-pipeline-400.webp | Bin 0 -> 25082 bytes .../img/optimized/feature-pipeline-640.webp | Bin 0 -> 50688 bytes static/img/optimized/feature-server-400.webp | Bin 0 -> 21784 bytes static/img/optimized/feature-server-640.webp | Bin 0 -> 43916 bytes static/img/optimized/feature-ui-400.webp | Bin 0 -> 19138 bytes static/img/optimized/feature-ui-640.webp | Bin 0 -> 38188 bytes static/img/optimized/home-320.webp | Bin 0 -> 16980 bytes static/img/optimized/home-560.webp | Bin 0 -> 38834 bytes static/img/optimized/home-800.webp | Bin 0 -> 68894 bytes static/img/optimized/ui-1280.webp | Bin 0 -> 41232 bytes static/img/optimized/ui-640.webp | Bin 0 -> 13078 bytes static/img/optimized/ui-800.webp | Bin 0 -> 17294 bytes 38 files changed, 456 insertions(+), 223 deletions(-) delete mode 100644 src/pages/markdown-page.md create mode 100644 static/img/optimized/_UltraRAG_logo-400.webp create mode 100644 static/img/optimized/feature-benchmark-400.webp create mode 100644 static/img/optimized/feature-benchmark-640.webp create mode 100644 static/img/optimized/feature-pipeline-400.webp create mode 100644 static/img/optimized/feature-pipeline-640.webp create mode 100644 static/img/optimized/feature-server-400.webp create mode 100644 static/img/optimized/feature-server-640.webp create mode 100644 static/img/optimized/feature-ui-400.webp create mode 100644 static/img/optimized/feature-ui-640.webp create mode 100644 static/img/optimized/home-320.webp create mode 100644 static/img/optimized/home-560.webp create mode 100644 static/img/optimized/home-800.webp create mode 100644 static/img/optimized/ui-1280.webp create mode 100644 static/img/optimized/ui-640.webp create mode 100644 static/img/optimized/ui-800.webp diff --git a/blog/2026-01-27-ultrarag-3.0-release.md b/blog/2026-01-27-ultrarag-3.0-release.md index 3997bf1..0b61dea 100644 --- a/blog/2026-01-27-ultrarag-3.0-release.md +++ b/blog/2026-01-27-ultrarag-3.0-release.md @@ -53,12 +53,12 @@ Today, Tsinghua University's THUNLP Lab, Northeastern University's NEUIR Lab, Op - - @@ -92,12 +92,12 @@ Let the endpoint of algorithms no longer be cold console logs. UltraRAG 3.0 auto - - @@ -131,20 +131,20 @@ UltraRAG 3.0 重新定义了 **Chat 界面**——它不仅是用户交互的入 - - @@ -219,12 +219,12 @@ We demonstrate four real interaction scenarios here, showing how it transforms n - - \ No newline at end of file diff --git a/blog/authors.yml b/blog/authors.yml index d8225ac..e3650d0 100644 --- a/blog/authors.yml +++ b/blog/authors.yml @@ -2,7 +2,7 @@ ms: name: Sen Mei title: TsinghuaNLP url: https://mssssss123.github.io/ - image_url: /img/team/ms.png + image_url: /img/team/ms.jpg xhd: name: Haidong Xin diff --git a/docusaurus.config.js b/docusaurus.config.js index c6076c3..b7984e5 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -11,11 +11,12 @@ const config = { url: 'https://ultrarag.github.io', baseUrl: '/', // 如果你是用 GitHub Pages 且不是自定义域名,这里通常填 '/仓库名/' - organizationName: 'xhd0728', // 你的 GitHub 用户名 + organizationName: 'UltraRAG', // 你的 GitHub 用户名 projectName: 'ultrarag.github.io', // 你的仓库名 onBrokenLinks: 'throw', - onBrokenMarkdownLinks: 'warn', + onBrokenAnchors: 'throw', + markdown: { hooks: { onBrokenMarkdownLinks: 'throw' } }, i18n: { defaultLocale: 'en', @@ -50,12 +51,14 @@ const config = { disableSwitch: true, // 关掉切换开关(像vLLM一样保持风格统一) respectPrefersColorScheme: false, }, - image: 'img/docusaurus-social-card.jpg', + image: 'img/home/home.jpg', navbar: { // title: 'UltraRAG', logo: { alt: 'UltraRAG Logo', - src: 'img/_UltraRAG_logo.png', + src: 'img/optimized/_UltraRAG_logo-400.webp', + width: 400, + height: 60, }, items: [ // ========== 中间区域菜单 (position: left,但会通过 CSS 居中) ========== diff --git a/src/components/NavbarItems/GithubStar.js b/src/components/NavbarItems/GithubStar.js index d10ebb4..7292972 100644 --- a/src/components/NavbarItems/GithubStar.js +++ b/src/components/NavbarItems/GithubStar.js @@ -28,29 +28,43 @@ export default function GithubStar({ href, repo }) { const [stars, setStars] = useState(null); useEffect(() => { - // 简单的本地缓存,避免频繁请求 API (GitHub API Rate Limit) - const cachedStars = sessionStorage.getItem(`github-stars-${repo}`); - if (cachedStars) { - setStars(JSON.parse(cachedStars)); - return; + setStars(null); + const cacheKey = `github-stars-${repo}`; + try { + const cached = JSON.parse(sessionStorage.getItem(cacheKey)); + if (Number.isSafeInteger(cached) && cached >= 0) { + setStars(cached); + return; + } + } catch { + // Storage may be blocked or contain an old/corrupt cache entry. } - + if (!repo) return; + const controller = new AbortController(); + const timeout = setTimeout(() => controller.abort(), 5000); async function fetchStars() { try { - const response = await fetch(`https://api.github.com/repos/${repo}`); - if (response.ok) { - const data = await response.json(); - setStars(data.stargazers_count); - sessionStorage.setItem(`github-stars-${repo}`, JSON.stringify(data.stargazers_count)); + const response = await fetch(`https://api.github.com/repos/${repo}`, {signal: controller.signal}); + if (!response.ok) return; + const data = await response.json(); + if (controller.signal.aborted || !Number.isSafeInteger(data.stargazers_count) || data.stargazers_count < 0) return; + setStars(data.stargazers_count); + try { + sessionStorage.setItem(cacheKey, JSON.stringify(data.stargazers_count)); + } catch { + // The link remains usable when caching is unavailable. } - } catch (error) { - console.error('Failed to fetch GitHub stars:', error); + } catch { + // This optional counter must not prevent navigation when offline. + } finally { + clearTimeout(timeout); } } - - if (repo) { - fetchStars(); - } + fetchStars(); + return () => { + clearTimeout(timeout); + controller.abort(); + }; }, [repo]); return ( @@ -60,7 +74,7 @@ export default function GithubStar({ href, repo }) { className={styles.githubButton} target="_blank" rel="noopener noreferrer" - aria-label={`Star ${repo} on GitHub`} + aria-label={`GitHub ${formatStarCount(stars)} stars for ${repo}`} >
diff --git a/src/components/NavbarItems/GithubStar.module.css b/src/components/NavbarItems/GithubStar.module.css index ea04072..4a7dbfb 100644 --- a/src/components/NavbarItems/GithubStar.module.css +++ b/src/components/NavbarItems/GithubStar.module.css @@ -38,3 +38,5 @@ font-size: 13px; line-height: 1; } + +.starText { min-width: 3.5ch; } diff --git a/src/components/NavbarItems/LanguageSwitcher.js b/src/components/NavbarItems/LanguageSwitcher.js index 97fedee..a342cd1 100644 --- a/src/components/NavbarItems/LanguageSwitcher.js +++ b/src/components/NavbarItems/LanguageSwitcher.js @@ -10,6 +10,8 @@ export default function LanguageSwitcher() { @@ -17,6 +19,8 @@ export default function LanguageSwitcher() { diff --git a/src/components/NavbarItems/LanguageSwitcher.module.css b/src/components/NavbarItems/LanguageSwitcher.module.css index 2ec8828..5688de6 100644 --- a/src/components/NavbarItems/LanguageSwitcher.module.css +++ b/src/components/NavbarItems/LanguageSwitcher.module.css @@ -34,3 +34,5 @@ font-size: 13px; user-select: none; } + +.btn { min-height: 44px; min-width: 44px; } diff --git a/src/components/NavbarItems/MegaMenu.js b/src/components/NavbarItems/MegaMenu.js index ba4c0da..5d547fa 100644 --- a/src/components/NavbarItems/MegaMenu.js +++ b/src/components/NavbarItems/MegaMenu.js @@ -1,104 +1,92 @@ -import React, { useState, useEffect, useRef } from 'react'; +import React, {useEffect, useId, useRef, useState} from 'react'; import Link from '@docusaurus/Link'; import clsx from 'clsx'; -import useBaseUrl from '@docusaurus/useBaseUrl'; -import { useLanguage } from '@site/src/context/LanguageContext'; +import {useLanguage} from '@site/src/context/LanguageContext'; import styles from './MegaMenu.module.css'; -// 简单的 SVG 箭头图标 -const ChevronDown = () => ( - - - -); - -export default function MegaMenu({ label, labelZh, items, position, to: triggerTo }) { - const { lang } = useLanguage(); +export default function MegaMenu({label, labelZh, items, to: triggerTo}) { + const {lang} = useLanguage(); const isZh = lang === 'zh'; const displayLabel = isZh ? (labelZh || label) : label; - - const localizedItems = items.map(column => ({ - ...column, - title: isZh ? (column.titleZh || column.title) : column.title, - items: column.items.map(item => ({ - ...item, - label: isZh ? (item.labelZh || item.label) : item.label, - })), - })); - const [isOpen, setIsOpen] = useState(false); - const [isHovered, setIsHovered] = useState(false); const containerRef = useRef(null); + const toggleRef = useRef(null); const timeoutRef = useRef(null); + const menuId = useId(); - // 处理延迟关闭,提供更好的用户体验 - const handleMouseEnter = () => { - if (timeoutRef.current) clearTimeout(timeoutRef.current); - setIsHovered(true); + const open = () => { + clearTimeout(timeoutRef.current); setIsOpen(true); }; - - const handleMouseLeave = () => { - timeoutRef.current = setTimeout(() => { - setIsHovered(false); - setIsOpen(false); - }, 150); // 150ms 延迟 + const close = () => { + clearTimeout(timeoutRef.current); + setIsOpen(false); }; - // 点击外部关闭 useEffect(() => { - const handleClickOutside = (event) => { - if (containerRef.current && !containerRef.current.contains(event.target)) { - setIsOpen(false); - setIsHovered(false); - } + const outside = event => { + if (!containerRef.current?.contains(event.target)) setIsOpen(false); + }; + document.addEventListener('pointerdown', outside); + return () => { + clearTimeout(timeoutRef.current); + document.removeEventListener('pointerdown', outside); }; - document.addEventListener('mousedown', handleClickOutside); - return () => document.removeEventListener('mousedown', handleClickOutside); }, []); return ( -
- {triggerTo ? ( - + onMouseLeave={() => { + if (!containerRef.current?.contains(document.activeElement)) { + timeoutRef.current = setTimeout(close, 150); + } + }} + onBlur={event => { + if (!event.currentTarget.contains(event.relatedTarget)) close(); + }} + onKeyDown={event => { + if (event.key === 'Escape' && isOpen) { + event.preventDefault(); + close(); + toggleRef.current?.focus(); + } + if (event.key === 'ArrowDown' && event.target.closest('a, button')?.parentElement === containerRef.current) { + event.preventDefault(); + open(); + requestAnimationFrame(() => document.getElementById(menuId)?.querySelector('a')?.focus()); + } + }}> + {triggerTo && ( + {displayLabel} - ) : ( -
- {displayLabel} -
)} - -
+ + {open && ( -
+
{item.children.map((section, si) => (
{section.section}
@@ -140,15 +142,49 @@ export default function NavbarMobilePrimaryMenu() { const mobileSidebar = useNavbarMobileSidebar(); const { lang, setLang } = useLanguage(); const items = NAV_ITEMS[lang] || NAV_ITEMS.en; + const menuRef = useRef(null); + + useEffect(() => { + if (!mobileSidebar.shown) return; + const drawer = menuRef.current?.closest('.navbar-sidebar'); + if (!drawer) return; + const frame = requestAnimationFrame(() => drawer.querySelector('.navbar-sidebar__close')?.focus()); + const onKeyDown = event => { + if (event.key === 'Escape') { + event.preventDefault(); + mobileSidebar.toggle(); + } + if (event.key === 'Tab') { + if (!drawer.contains(document.activeElement)) { + event.preventDefault(); + drawer.querySelector('.navbar-sidebar__close')?.focus(); + return; + } + const controls = [...drawer.querySelectorAll('a[href], button, [tabindex="0"]')] + .filter(element => !element.disabled && element.getClientRects().length && !element.closest('[inert]')); + if (event.shiftKey && document.activeElement === controls[0]) { + event.preventDefault(); controls.at(-1)?.focus(); + } else if (!event.shiftKey && document.activeElement === controls.at(-1)) { + event.preventDefault(); controls[0]?.focus(); + } + } + }; + document.addEventListener('keydown', onKeyDown); + return () => { + cancelAnimationFrame(frame); + document.removeEventListener('keydown', onKeyDown); + if (drawer.contains(document.activeElement)) document.querySelector('.navbar__toggle')?.focus(); + }; + }, [mobileSidebar.shown, mobileSidebar.toggle]); const closeSidebar = () => mobileSidebar.toggle(); return ( -
+