Skip to content

Commit

Permalink
refactor: add github and openKG link in Nav (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aarebecca authored Oct 27, 2023
1 parent 0bb13ae commit c7ba8e4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .dumi/theme/layouts/GlobalLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ node_modules
.DS_Store
/.idea/
/package-lock.json
/pnpm-lock.yaml

0 comments on commit c7ba8e4

Please sign in to comment.