@@ -4,11 +4,12 @@ import { useLocation } from '@docusaurus/router';
44import useDocusaurusContext from '@docusaurus/useDocusaurusContext' ;
55import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem' ;
66import { getLocalePrefix , isDocsNextPath , isReleasesPath , normalizePathname } from '@site/src/utils/locale' ;
7+ import { STAR_COUNT } from '@site/src/constant/github.data' ;
78import './NavbarNext.scss' ;
89
910const GITHUB_REPO = 'apache/doris' ;
10- const FALLBACK_STARS = '-' ;
1111const HOME_VERSION_KEY = 'doris-home-version' ;
12+ const STAR_DISPLAY = `${ STAR_COUNT } k` ;
1213
1314function safeSetLocalStorage ( key : string , value : string ) : void {
1415 try {
@@ -18,33 +19,6 @@ function safeSetLocalStorage(key: string, value: string): void {
1819 }
1920}
2021
21- function formatStars ( n : number ) : string {
22- if ( n >= 1000 ) return `${ ( n / 1000 ) . toFixed ( 1 ) } k` ;
23- return String ( n ) ;
24- }
25-
26- function useGitHubStars ( repo : string , fallback : string ) : string {
27- const [ stars , setStars ] = useState ( fallback ) ;
28- useEffect ( ( ) => {
29- let cancelled = false ;
30- const timer = window . setTimeout ( ( ) => {
31- fetch ( `https://api.github.com/repos/${ repo } ` )
32- . then ( r => ( r . ok ? r . json ( ) : null ) )
33- . then ( data => {
34- if ( ! cancelled && data && typeof data . stargazers_count === 'number' ) {
35- setStars ( formatStars ( data . stargazers_count ) ) ;
36- }
37- } )
38- . catch ( ( ) => { /* keep fallback on network/CORS/rate-limit errors */ } ) ;
39- } , 1200 ) ;
40- return ( ) => {
41- cancelled = true ;
42- window . clearTimeout ( timer ) ;
43- } ;
44- } , [ repo ] ) ;
45- return stars ;
46- }
47-
4822interface DropdownItem {
4923 label : string ;
5024 href : string ;
@@ -138,7 +112,6 @@ export function NavbarNext(): JSX.Element {
138112 i18n : { currentLocale, defaultLocale, localeConfigs } ,
139113 } = useDocusaurusContext ( ) ;
140114 const { pathname, search, hash } = useLocation ( ) ;
141- const stars = useGitHubStars ( GITHUB_REPO , FALLBACK_STARS ) ;
142115 const [ mobileOpen , setMobileOpen ] = useState ( false ) ;
143116 const localePrefix = getLocalePrefix ( currentLocale , defaultLocale ) ;
144117 const docsHref = `${ localePrefix } /docs-next/dev/getting-started/what-is-apache-doris` ;
@@ -152,7 +125,7 @@ export function NavbarNext(): JSX.Element {
152125 const localeSwitchLabel = currentLocale === 'zh-CN' ? localeConfigs [ defaultLocale ] ?. label ?? 'English' : '中文' ;
153126 const currentLocalizedPath = normalizePathname ( pathname , [ defaultLocale , 'zh-CN' ] ) ;
154127 const buildLocaleHref = ( locale : string ) =>
155- `${ locale === defaultLocale ? '' : `/${ locale } ` } ${ currentLocalizedPath } ${ search } ${ hash } ` ;
128+ `pathname:// ${ locale === defaultLocale ? '' : `/${ locale } ` } ${ currentLocalizedPath } ${ search } ${ hash } ` ;
156129 const localeItems = [ defaultLocale , 'zh-CN' ]
157130 . filter ( ( locale , index , arr ) => arr . indexOf ( locale ) === index )
158131 . map ( locale => ( {
@@ -245,12 +218,12 @@ export function NavbarNext(): JSX.Element {
245218 target = "_blank"
246219 rel = "noopener noreferrer"
247220 className = "navbar-next__star-link"
248- aria-label = { `Star Apache Doris on GitHub (${ stars } stars)` }
221+ aria-label = { `Star Apache Doris on GitHub (${ STAR_DISPLAY } stars)` }
249222 >
250223 < StarIcon />
251224 < span > Star</ span >
252225 < span className = "navbar-next__star-divider" />
253- < span className = "navbar-next__star-count" > { stars } </ span >
226+ < span className = "navbar-next__star-count" > { STAR_DISPLAY } </ span >
254227 < span className = "navbar-next__star-divider" />
255228 < GitHubIcon />
256229 </ a >
@@ -340,12 +313,12 @@ export function NavbarNext(): JSX.Element {
340313 target = "_blank"
341314 rel = "noopener noreferrer"
342315 className = "navbar-next__star-link"
343- aria-label = { `Star Apache Doris on GitHub (${ stars } stars)` }
316+ aria-label = { `Star Apache Doris on GitHub (${ STAR_DISPLAY } stars)` }
344317 >
345318 < StarIcon />
346319 < span > Star</ span >
347320 < span className = "navbar-next__star-divider" />
348- < span className = "navbar-next__star-count" > { stars } </ span >
321+ < span className = "navbar-next__star-count" > { STAR_DISPLAY } </ span >
349322 < span className = "navbar-next__star-divider" />
350323 < GitHubIcon />
351324 </ a >
0 commit comments