feat(site): prefetch all links

This commit is contained in:
Darius Cepulis
2025-10-30 08:34:47 -05:00
parent bd6ef02282
commit bd9fd38aa4
5 changed files with 15 additions and 17 deletions
+3 -1
View File
@@ -28,7 +28,9 @@ export default defineConfig({
}, },
}), }),
], ],
prefetch: true, prefetch: {
prefetchAll: true,
},
markdown: { markdown: {
// a lot of these are defaults but I'm setting them just to be explicit // a lot of these are defaults but I'm setting them just to be explicit
+2 -8
View File
@@ -9,12 +9,10 @@ type NavLink = {
href: string; href: string;
label: string; label: string;
external?: boolean; external?: boolean;
prefetch?: boolean;
}; };
const navLinks: NavLink[] = [ const navLinks: NavLink[] = [
{ href: '/', label: 'Home' }, { href: '/', label: 'Home' },
// docs require a redirect, so, let's prefetch them to hide that latency { href: '/docs', label: 'Docs' },
{ href: '/docs', label: 'Docs', prefetch: true },
// { href: '/blog', label: 'Blog' }, // { href: '/blog', label: 'Blog' },
{ href: '/privacy', label: 'Privacy' }, { href: '/privacy', label: 'Privacy' },
]; ];
@@ -31,11 +29,7 @@ const { class: className } = Astro.props;
<div class="flex justify-center sm:justify-start"> <div class="flex justify-center sm:justify-start">
{ {
navLinks.map((link) => ( navLinks.map((link) => (
<a <a href={link.href} class="intent:underline px-3 py-2 inline-flex gap-1 items-center">
href={link.href}
class="intent:underline px-3 py-2 inline-flex gap-1 items-center"
data-astro-prefetch={link.prefetch ? '' : undefined}
>
{link.label} {link.external ? <ArrowUpRight size="1em" /> : null} {link.label} {link.external ? <ArrowUpRight size="1em" /> : null}
</a> </a>
)) ))
+7 -2
View File
@@ -1,9 +1,15 @@
import type { NavLink } from './NavBar.astro';
import { Dialog } from '@base-ui-components/react/dialog'; import { Dialog } from '@base-ui-components/react/dialog';
import clsx from 'clsx'; import clsx from 'clsx';
import { ArrowUpRight, Menu, X } from 'lucide-react'; import { ArrowUpRight, Menu, X } from 'lucide-react';
import { DISCORD_INVITE_URL, GITHUB_REPO_URL } from '@/consts'; import { DISCORD_INVITE_URL, GITHUB_REPO_URL } from '@/consts';
interface NavLink {
href: string;
label: string;
matchPath: string | null;
external?: boolean;
}
export interface MobileNavProps { export interface MobileNavProps {
navLinks: NavLink[]; navLinks: NavLink[];
currentPath: string; currentPath: string;
@@ -52,7 +58,6 @@ export default function MobileNav({ navLinks, currentPath, dark = false, childre
href={link.href} href={link.href}
className={clsx('text-lg px-6 py-3', link.matchPath && currentPath.startsWith(link.matchPath) ? 'underline' : 'intent:underline')} className={clsx('text-lg px-6 py-3', link.matchPath && currentPath.startsWith(link.matchPath) ? 'underline' : 'intent:underline')}
aria-current={link.matchPath && currentPath.startsWith(link.matchPath) ? 'page' : undefined} aria-current={link.matchPath && currentPath.startsWith(link.matchPath) ? 'page' : undefined}
data-astro-prefetch={link.prefetch ? '' : undefined}
> >
{link.label} {link.label}
{' '} {' '}
+2 -5
View File
@@ -10,16 +10,14 @@ export interface Props {
class?: string; class?: string;
} }
export type NavLink = { type NavLink = {
href: string; href: string;
label: string; label: string;
matchPath: string | null; matchPath: string | null;
external?: boolean; external?: boolean;
prefetch?: boolean;
}; };
const navLinks: NavLink[] = [ const navLinks: NavLink[] = [
// docs require a redirect, so, let's prefetch them to hide that latency { href: '/docs', label: 'Docs', matchPath: '/docs' },
{ href: '/docs', label: 'Docs', matchPath: '/docs', prefetch: true },
// { href: '/blog', label: 'Blog', matchPath: '/blog' }, // { href: '/blog', label: 'Blog', matchPath: '/blog' },
]; ];
@@ -53,7 +51,6 @@ const { class: className, dark = false } = Astro.props;
: 'border-transparent intent:border-current', : 'border-transparent intent:border-current',
]} ]}
aria-current={link.matchPath && currentPath.startsWith(link.matchPath) ? 'page' : undefined} aria-current={link.matchPath && currentPath.startsWith(link.matchPath) ? 'page' : undefined}
data-astro-prefetch={link.prefetch ? '' : undefined}
> >
{link.label} {link.external ? <ArrowUpRight size="1em" /> : null} {link.label} {link.external ? <ArrowUpRight size="1em" /> : null}
</a> </a>
+1 -1
View File
@@ -24,6 +24,6 @@ const { url: href } = resolveDocsLinkUrl({
}); });
--- ---
<A href={href} data-astro-prefetch> <A href={href}>
<slot /> <slot />
</A> </A>