This is an automated email from the ASF dual-hosted git repository.

luzhijing pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris-website.git


The following commit(s) were added to refs/heads/master by this push:
     new 86bd84abbe6 [feat] update star display (#337)
86bd84abbe6 is described below

commit 86bd84abbe678f1d7ce3abfdd68e6a3a3b255697
Author: Jeffrey <[email protected]>
AuthorDate: Fri Nov 10 18:32:47 2023 +0800

    [feat] update star display (#337)
---
 src/theme/Navbar/Content/index.tsx | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/src/theme/Navbar/Content/index.tsx 
b/src/theme/Navbar/Content/index.tsx
index 51a157d01b7..ef112c42c3b 100644
--- a/src/theme/Navbar/Content/index.tsx
+++ b/src/theme/Navbar/Content/index.tsx
@@ -1,4 +1,4 @@
-import React from 'react';
+import React, { useEffect, useState } from 'react';
 import { useThemeConfig } from '@docusaurus/theme-common';
 import { splitNavbarItems, useNavbarMobileSidebar } from 
'@docusaurus/theme-common/internal';
 import NavbarItem from '@theme/NavbarItem';
@@ -37,6 +37,26 @@ export default function NavbarContent({ mobile }) {
     const items = useNavbarItems();
     const [leftItems, rightItems] = splitNavbarItems(items);
     const searchBarItem = items.find(item => item.type === 'search');
+    const [star, setStar] = useState<any>();
+    useEffect(() => {
+        getGithubStar();
+    }, []);
+
+    async function getGithubStar() {
+        const res = await fetch('https://api.github.com/repos/apache/doris');
+        const data = await res.json();
+        const starStr = 
(+parseFloat(formatStar(data.stargazers_count)).toFixed(1)).toString();
+        setStar(starStr);
+    }
+
+    function formatStar(star) {
+        return String(star)
+            .split('')
+            .reverse()
+            .reduce((prev, next, index) => {
+                return (index % 3 ? next : next + '.') + prev;
+            });
+    }
     return (
         <NavbarContentLayout
             left={
@@ -59,7 +79,7 @@ export default function NavbarContent({ mobile }) {
                         </NavbarSearch>
                     )}
                     <span className="github-btn desktop 
header-right-button-github">
-                        <GitHubButton type="stargazers" size="large" 
namespace="apache" repo="doris" />
+                        {star && <div className="gh-count">{star}k</div>}
                     </span>
 
                     <Link className="header-right-button-primary 
navbar-download-desktop" to="/download">


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to