aboutsummaryrefslogtreecommitdiffstats
path: root/src/theme
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2024-03-15 18:01:48 +0100
committerLibravatar Kristóf Marussy <kristof@marussy.com>2024-03-15 19:19:33 +0100
commit0a16f36b8afc23f335c1146d6ea53329f9e27df7 (patch)
tree91a204a8f44f605042a8498a96f68dd02a5f1705 /src/theme
parentchore(deps): bump dependencies (diff)
downloadblog-0a16f36b8afc23f335c1146d6ea53329f9e27df7.tar.gz
blog-0a16f36b8afc23f335c1146d6ea53329f9e27df7.tar.zst
blog-0a16f36b8afc23f335c1146d6ea53329f9e27df7.zip
Add landing page sections and update resume
Diffstat (limited to 'src/theme')
-rw-r--r--src/theme/NavbarItem/NavbarNavLink.jsx88
-rw-r--r--src/theme/Root.tsx18
2 files changed, 106 insertions, 0 deletions
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 @@
1/*
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 * Copyright (c) 2023 Kristóf Marussy <kristof@marussy.com>
4 *
5 * SPDX-License-Identifier: MIT
6 *
7 * This file was derived from
8 * https://github.com/facebook/docusaurus/blob/c745021b01a8b88d34e1d772278d7171ad8acdf5/packages/docusaurus-theme-classic/src/theme/NavbarItem/NavbarNavLink.tsx
9 * via the `swizzle` mechanism of Docusaurus.
10 *
11 * It was modified to correctly track the change of the active anchor
12 * when `setHash` from `@site/src/components/ActiveSectionProvider` is called.
13 */
14
15import React from 'react';
16import Link from '@docusaurus/Link';
17import useBaseUrl from '@docusaurus/useBaseUrl';
18import isInternalUrl from '@docusaurus/isInternalUrl';
19import { isRegexpStringMatch } from '@docusaurus/theme-common';
20import IconExternalLink from '@theme/Icon/ExternalLink';
21import { useActiveSection } from '@site/src/components/ActiveSectionProvider';
22export default function NavbarNavLink({
23 activeBasePath,
24 activeBaseRegex,
25 to,
26 href,
27 label,
28 html,
29 isDropdownLink,
30 prependBaseUrlToHref,
31 ...props
32}) {
33 const { hash: activeSectionHash } = useActiveSection();
34 // TODO all this seems hacky
35 // {to: 'version'} should probably be forbidden, in favor of {to: '/version'}
36 const toUrl = useBaseUrl(to);
37 // Check whether the target URL has a hash.
38 const hashMatch = toUrl?.match(/#.+$/);
39 const activeBaseUrl = useBaseUrl(activeBasePath);
40 const normalizedHref = useBaseUrl(href, { forcePrependBaseUrl: true });
41 const isExternalLink = label && href && !isInternalUrl(href);
42 // Link content is set through html XOR label
43 const linkContentProps = html
44 ? { dangerouslySetInnerHTML: { __html: html } }
45 : {
46 children: (
47 <>
48 {label}
49 {isExternalLink && (
50 <IconExternalLink
51 {...(isDropdownLink && { width: 12, height: 12 })}
52 />
53 )}
54 </>
55 ),
56 };
57 if (href) {
58 return (
59 <Link
60 href={prependBaseUrlToHref ? normalizedHref : href}
61 {...props}
62 {...linkContentProps}
63 />
64 );
65 }
66 return (
67 <Link
68 to={toUrl}
69 isNavLink
70 {...((activeBasePath || activeBaseRegex || hashMatch) && {
71 isActive: (_match, location) => {
72 if (activeBaseRegex) {
73 return isRegexpStringMatch(activeBaseRegex, location.pathname);
74 }
75 if (activeBaseUrl) {
76 return location.pathname.startsWith(activeBaseUrl);
77 }
78 // Make sure to only highlight links with a hash when hash also matches.
79 return (
80 !hashMatch || hashMatch[0] === (activeSectionHash ?? location.hash)
81 );
82 },
83 })}
84 {...props}
85 {...linkContentProps}
86 />
87 );
88}
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 @@
1/*
2 * SPDX-FileCopyrightText: 2023 Kristóf Marussy
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7import type { Props } from '@theme/Root';
8import Root from '@theme-original/Root';
9
10import ActiveSectionProvider from '@site/src/components/ActiveSectionProvider';
11
12export default function RootWrapper(props: Props) {
13 return (
14 <ActiveSectionProvider>
15 <Root {...props} />
16 </ActiveSectionProvider>
17 );
18}