From c7ba8e4d120498b58f38338d28dc751bd32d866f Mon Sep 17 00:00:00 2001 From: Aaron Date: Fri, 27 Oct 2023 11:04:31 +0800 Subject: [PATCH] refactor: add github and openKG link in Nav (#11) --- .dumi/theme/layouts/GlobalLayout.tsx | 31 ++++++++++++++++++++++++++++ .gitignore | 1 + 2 files changed, 32 insertions(+) diff --git a/.dumi/theme/layouts/GlobalLayout.tsx b/.dumi/theme/layouts/GlobalLayout.tsx index 4f7d587..391551a 100644 --- a/.dumi/theme/layouts/GlobalLayout.tsx +++ b/.dumi/theme/layouts/GlobalLayout.tsx @@ -15,6 +15,37 @@ const GlobalLayout: React.FC = () => { const isMobileScreen = screenWidth < 900; const isMobile = isMobileDevice && isMobileScreen; + useEffect(() => { + const nav = document.getElementsByClassName('dumi-default-navbar')?.[0]; + if (!nav) return; + + // insert github and openKG in navbar + + const createLink = (name: string, link: string, index: number) => { + const xpath = `//*[text()='${name}']`; + const element = document.evaluate( + xpath, + nav, + null, + XPathResult.FIRST_ORDERED_NODE_TYPE, + null, + ).singleNodeValue; + if (element) return; + + const li = document.createElement('li'); + const a = document.createElement('a'); + a.innerText = name; + a.href = link; + a.target = '_blank'; + a.rel = 'noopener noreferrer'; + li.appendChild(a); + nav.insertBefore(li, nav.childNodes[index]); + }; + + createLink('Github', 'https://github.com/OpenSPG/openspg', 1); + createLink('OpenKG', 'http://openkg.cn/', 5); + }, []); + useEffect(() => { const observer = new IntersectionObserver( (entries) => { diff --git a/.gitignore b/.gitignore index f4c9613..9581cfc 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ node_modules .DS_Store /.idea/ /package-lock.json +/pnpm-lock.yaml \ No newline at end of file