From 0a16f36b8afc23f335c1146d6ea53329f9e27df7 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Fri, 15 Mar 2024 18:01:48 +0100 Subject: Add landing page sections and update resume --- src/theme/NavbarItem/NavbarNavLink.jsx | 88 ++++++++++++++++++++++++++++++++++ src/theme/Root.tsx | 18 +++++++ 2 files changed, 106 insertions(+) create mode 100644 src/theme/NavbarItem/NavbarNavLink.jsx create mode 100644 src/theme/Root.tsx (limited to 'src/theme') diff --git a/src/theme/NavbarItem/NavbarNavLink.jsx b/src/theme/NavbarItem/NavbarNavLink.jsx new file mode 100644 index 0000000..cb151ea --- /dev/null +++ b/src/theme/NavbarItem/NavbarNavLink.jsx @@ -0,0 +1,88 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * Copyright (c) 2023 Kristóf Marussy + * + * SPDX-License-Identifier: MIT + * + * This file was derived from + * https://github.com/facebook/docusaurus/blob/c745021b01a8b88d34e1d772278d7171ad8acdf5/packages/docusaurus-theme-classic/src/theme/NavbarItem/NavbarNavLink.tsx + * via the `swizzle` mechanism of Docusaurus. + * + * It was modified to correctly track the change of the active anchor + * when `setHash` from `@site/src/components/ActiveSectionProvider` is called. + */ + +import React from 'react'; +import Link from '@docusaurus/Link'; +import useBaseUrl from '@docusaurus/useBaseUrl'; +import isInternalUrl from '@docusaurus/isInternalUrl'; +import { isRegexpStringMatch } from '@docusaurus/theme-common'; +import IconExternalLink from '@theme/Icon/ExternalLink'; +import { useActiveSection } from '@site/src/components/ActiveSectionProvider'; +export default function NavbarNavLink({ + activeBasePath, + activeBaseRegex, + to, + href, + label, + html, + isDropdownLink, + prependBaseUrlToHref, + ...props +}) { + const { hash: activeSectionHash } = useActiveSection(); + // TODO all this seems hacky + // {to: 'version'} should probably be forbidden, in favor of {to: '/version'} + const toUrl = useBaseUrl(to); + // Check whether the target URL has a hash. + const hashMatch = toUrl?.match(/#.+$/); + const activeBaseUrl = useBaseUrl(activeBasePath); + const normalizedHref = useBaseUrl(href, { forcePrependBaseUrl: true }); + const isExternalLink = label && href && !isInternalUrl(href); + // Link content is set through html XOR label + const linkContentProps = html + ? { dangerouslySetInnerHTML: { __html: html } } + : { + children: ( + <> + {label} + {isExternalLink && ( + + )} + + ), + }; + if (href) { + return ( + + ); + } + return ( + { + if (activeBaseRegex) { + return isRegexpStringMatch(activeBaseRegex, location.pathname); + } + if (activeBaseUrl) { + return location.pathname.startsWith(activeBaseUrl); + } + // Make sure to only highlight links with a hash when hash also matches. + return ( + !hashMatch || hashMatch[0] === (activeSectionHash ?? location.hash) + ); + }, + })} + {...props} + {...linkContentProps} + /> + ); +} diff --git a/src/theme/Root.tsx b/src/theme/Root.tsx new file mode 100644 index 0000000..9459e9f --- /dev/null +++ b/src/theme/Root.tsx @@ -0,0 +1,18 @@ +/* + * SPDX-FileCopyrightText: 2023 Kristóf Marussy + * + * SPDX-License-Identifier: MIT + */ + +import type { Props } from '@theme/Root'; +import Root from '@theme-original/Root'; + +import ActiveSectionProvider from '@site/src/components/ActiveSectionProvider'; + +export default function RootWrapper(props: Props) { + return ( + + + + ); +} -- cgit v1.2.3-54-g00ecf