Initial commit
62
src/components/AuthorCard.astro
Normal file
@@ -0,0 +1,62 @@
|
||||
---
|
||||
import Link from '@/components/Link.astro'
|
||||
import AvatarComponent from '@/components/ui/avatar'
|
||||
import { cn } from '@/lib/utils'
|
||||
import type { SocialLink } from '@/types'
|
||||
import type { CollectionEntry } from 'astro:content'
|
||||
import SocialIcons from './SocialIcons.astro'
|
||||
|
||||
interface Props {
|
||||
author: CollectionEntry<'authors'>
|
||||
}
|
||||
|
||||
const { author } = Astro.props
|
||||
const { name, avatar, bio, pronouns } = author.data
|
||||
const currentPath = Astro.url.pathname
|
||||
const isAuthorPage = currentPath === `/authors/${author.id}`
|
||||
|
||||
const socialLinks: SocialLink[] = [
|
||||
author.data.website && { href: author.data.website, label: 'Website' },
|
||||
author.data.github && { href: author.data.github, label: 'GitHub' },
|
||||
author.data.twitter && { href: author.data.twitter, label: 'Twitter' },
|
||||
author.data.linkedin && { href: author.data.linkedin, label: 'LinkedIn' },
|
||||
author.data.mail && { href: `mailto:${author.data.mail}`, label: 'Email' },
|
||||
].filter(Boolean) as SocialLink[]
|
||||
---
|
||||
|
||||
<div
|
||||
class="has-[a:hover]:bg-muted/50 overflow-hidden rounded-xl border p-4 transition-colors duration-300 ease-in-out"
|
||||
>
|
||||
<div class="flex flex-wrap gap-4">
|
||||
<Link
|
||||
href={`/authors/${author.id}`}
|
||||
class={cn('block', isAuthorPage && 'pointer-events-none')}
|
||||
>
|
||||
<AvatarComponent
|
||||
client:load
|
||||
src={avatar}
|
||||
alt={`Avatar of ${name}`}
|
||||
fallback={name[0]}
|
||||
className={cn(
|
||||
'size-32 rounded-md [&>[data-slot="avatar-fallback"]]:rounded-md',
|
||||
!isAuthorPage &&
|
||||
'hover:ring-primary transition-shadow duration-300 hover:cursor-pointer hover:ring-2',
|
||||
)}
|
||||
/>
|
||||
</Link>
|
||||
<div class="flex grow flex-col justify-between gap-y-4">
|
||||
<div>
|
||||
<div class="flex flex-wrap items-center gap-x-2">
|
||||
<h3 class="text-lg font-medium">{name}</h3>
|
||||
{
|
||||
pronouns && (
|
||||
<span class="text-muted-foreground text-sm">({pronouns})</span>
|
||||
)
|
||||
}
|
||||
</div>
|
||||
<p class="text-muted-foreground text-sm">{bio}</p>
|
||||
</div>
|
||||
<SocialIcons links={socialLinks} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
105
src/components/BlogCard.astro
Normal file
@@ -0,0 +1,105 @@
|
||||
---
|
||||
import AvatarComponent from '@/components/ui/avatar'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Separator } from '@/components/ui/separator'
|
||||
import {
|
||||
getCombinedReadingTime,
|
||||
getSubpostCount,
|
||||
isSubpost,
|
||||
parseAuthors,
|
||||
} from '@/lib/data-utils'
|
||||
import { formatDate } from '@/lib/utils'
|
||||
import { Icon } from 'astro-icon/components'
|
||||
import { Image } from 'astro:assets'
|
||||
import type { CollectionEntry } from 'astro:content'
|
||||
import Link from './Link.astro'
|
||||
|
||||
interface Props {
|
||||
entry: CollectionEntry<'blog'>
|
||||
}
|
||||
|
||||
const { entry } = Astro.props
|
||||
const formattedDate = formatDate(entry.data.date)
|
||||
const readTime = await getCombinedReadingTime(entry.id)
|
||||
const authors = await parseAuthors(entry.data.authors ?? [])
|
||||
const subpostCount = !isSubpost(entry.id) ? await getSubpostCount(entry.id) : 0
|
||||
---
|
||||
|
||||
<div
|
||||
class="hover:bg-muted/50 rounded-xl border p-4 transition-colors duration-300 ease-in-out"
|
||||
>
|
||||
<Link
|
||||
href={`/${entry.collection}/${entry.id}`}
|
||||
class="flex flex-col gap-4 sm:flex-row"
|
||||
>
|
||||
{
|
||||
entry.data.image && (
|
||||
<div class="w-full sm:max-w-3xs sm:shrink-0">
|
||||
<Image
|
||||
src={entry.data.image}
|
||||
alt={entry.data.title}
|
||||
width={1200}
|
||||
height={630}
|
||||
class="object-cover"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
<div class="grow">
|
||||
<h3 class="mb-1 text-lg font-medium">{entry.data.title}</h3>
|
||||
<p class="text-muted-foreground mb-2 text-sm">{entry.data.description}</p>
|
||||
|
||||
<div
|
||||
class="text-muted-foreground mb-2 flex flex-wrap items-center gap-x-2 text-xs"
|
||||
>
|
||||
{
|
||||
authors.length > 0 && (
|
||||
<>
|
||||
{authors.map((author) => (
|
||||
<div class="flex items-center gap-x-1.5">
|
||||
<AvatarComponent
|
||||
client:load
|
||||
src={author.avatar}
|
||||
alt={author.name}
|
||||
fallback={author.name[0]}
|
||||
className="size-5 rounded-full"
|
||||
/>
|
||||
<span>{author.name}</span>
|
||||
</div>
|
||||
))}
|
||||
<Separator orientation="vertical" className="h-4!" />
|
||||
</>
|
||||
)
|
||||
}
|
||||
<span>{formattedDate}</span>
|
||||
<Separator orientation="vertical" className="h-4!" />
|
||||
<span>{readTime}</span>
|
||||
{
|
||||
subpostCount > 0 && (
|
||||
<>
|
||||
<Separator orientation="vertical" className="h-4!" />
|
||||
<span class="flex items-center gap-1">
|
||||
<Icon name="lucide:file-text" class="size-3" />
|
||||
{subpostCount} subpost{subpostCount === 1 ? '' : 's'}
|
||||
</span>
|
||||
</>
|
||||
)
|
||||
}
|
||||
</div>
|
||||
|
||||
{
|
||||
entry.data.tags && (
|
||||
<div class="flex flex-wrap gap-2">
|
||||
{entry.data.tags.map((tag) => (
|
||||
<Badge variant="muted" className="flex items-center gap-x-1">
|
||||
<Icon name="lucide:hash" class="size-3" />
|
||||
{tag}
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</div>
|
||||
</Link>
|
||||
</div>
|
||||
61
src/components/Breadcrumbs.astro
Normal file
@@ -0,0 +1,61 @@
|
||||
---
|
||||
import {
|
||||
Breadcrumb,
|
||||
BreadcrumbItem,
|
||||
BreadcrumbLink,
|
||||
BreadcrumbList,
|
||||
BreadcrumbPage,
|
||||
BreadcrumbSeparator,
|
||||
} from '@/components/ui/breadcrumb'
|
||||
import { Icon } from 'astro-icon/components'
|
||||
|
||||
export interface BreadcrumbItem {
|
||||
href?: string
|
||||
label: string
|
||||
icon?: string
|
||||
}
|
||||
|
||||
interface Props {
|
||||
items: BreadcrumbItem[]
|
||||
}
|
||||
|
||||
const { items } = Astro.props
|
||||
---
|
||||
|
||||
<Breadcrumb>
|
||||
<BreadcrumbList>
|
||||
<BreadcrumbItem>
|
||||
<BreadcrumbLink href="/">
|
||||
<Icon name="lucide:home" class="size-4 shrink-0" />
|
||||
</BreadcrumbLink>
|
||||
</BreadcrumbItem>
|
||||
{
|
||||
items.map((item, index) => (
|
||||
<>
|
||||
<BreadcrumbSeparator />
|
||||
<BreadcrumbItem>
|
||||
{index === items.length - 1 ? (
|
||||
<BreadcrumbPage>
|
||||
<span class="flex items-center gap-x-2">
|
||||
{item.icon && (
|
||||
<Icon name={item.icon} class="size-4 shrink-0" />
|
||||
)}
|
||||
<span>{item.label}</span>
|
||||
</span>
|
||||
</BreadcrumbPage>
|
||||
) : (
|
||||
<BreadcrumbLink href={item.href}>
|
||||
<span class="flex items-center gap-x-2">
|
||||
{item.icon && (
|
||||
<Icon name={item.icon} class="size-4 shrink-0" />
|
||||
)}
|
||||
<span>{item.label}</span>
|
||||
</span>
|
||||
</BreadcrumbLink>
|
||||
)}
|
||||
</BreadcrumbItem>
|
||||
</>
|
||||
))
|
||||
}
|
||||
</BreadcrumbList>
|
||||
</Breadcrumb>
|
||||
183
src/components/Callout.astro
Normal file
@@ -0,0 +1,183 @@
|
||||
---
|
||||
import { cn } from '@/lib/utils'
|
||||
import { Icon } from 'astro-icon/components'
|
||||
import { cva, type VariantProps } from 'class-variance-authority'
|
||||
|
||||
const calloutConfig = {
|
||||
note: {
|
||||
style: 'border-blue-500 dark:bg-blue-950/5',
|
||||
textColor: 'text-blue-700 dark:text-blue-300',
|
||||
icon: 'lucide:info',
|
||||
},
|
||||
tip: {
|
||||
style: 'border-green-500 dark:bg-green-950/5',
|
||||
textColor: 'text-green-700 dark:text-green-300',
|
||||
icon: 'lucide:lightbulb',
|
||||
},
|
||||
warning: {
|
||||
style: 'border-amber-500 dark:bg-amber-950/5',
|
||||
textColor: 'text-amber-700 dark:text-amber-300',
|
||||
icon: 'lucide:alert-triangle',
|
||||
},
|
||||
danger: {
|
||||
style: 'border-red-500 dark:bg-red-950/5',
|
||||
textColor: 'text-red-700 dark:text-red-300',
|
||||
icon: 'lucide:shield-alert',
|
||||
},
|
||||
important: {
|
||||
style: 'border-purple-500 dark:bg-purple-950/5',
|
||||
textColor: 'text-purple-700 dark:text-purple-300',
|
||||
icon: 'lucide:message-square-warning',
|
||||
},
|
||||
definition: {
|
||||
style: 'border-purple-500 dark:bg-purple-950/5',
|
||||
textColor: 'text-purple-700 dark:text-purple-300',
|
||||
icon: 'lucide:book-open',
|
||||
},
|
||||
theorem: {
|
||||
style: 'border-teal-500 dark:bg-teal-950/5',
|
||||
textColor: 'text-teal-700 dark:text-teal-300',
|
||||
icon: 'lucide:check-circle',
|
||||
},
|
||||
lemma: {
|
||||
style: 'border-sky-400 dark:bg-sky-950/5',
|
||||
textColor: 'text-sky-700 dark:text-sky-300',
|
||||
icon: 'lucide:puzzle',
|
||||
},
|
||||
proof: {
|
||||
style: 'border-gray-500 dark:bg-gray-950/5',
|
||||
textColor: 'text-gray-700 dark:text-gray-300',
|
||||
icon: 'lucide:check-square',
|
||||
},
|
||||
corollary: {
|
||||
style: 'border-cyan-500 dark:bg-cyan-950/5',
|
||||
textColor: 'text-cyan-700 dark:text-cyan-300',
|
||||
icon: 'lucide:git-branch',
|
||||
},
|
||||
proposition: {
|
||||
style: 'border-slate-500 dark:bg-slate-950/5',
|
||||
textColor: 'text-slate-700 dark:text-slate-300',
|
||||
icon: 'lucide:file-text',
|
||||
},
|
||||
axiom: {
|
||||
style: 'border-violet-600 dark:bg-violet-950/5',
|
||||
textColor: 'text-violet-700 dark:text-violet-300',
|
||||
icon: 'lucide:anchor',
|
||||
},
|
||||
conjecture: {
|
||||
style: 'border-pink-500 dark:bg-pink-950/5',
|
||||
textColor: 'text-pink-700 dark:text-pink-300',
|
||||
icon: 'lucide:help-circle',
|
||||
},
|
||||
notation: {
|
||||
style: 'border-slate-400 dark:bg-slate-950/5',
|
||||
textColor: 'text-slate-700 dark:text-slate-300',
|
||||
icon: 'lucide:pen-tool',
|
||||
},
|
||||
remark: {
|
||||
style: 'border-gray-400 dark:bg-gray-950/5',
|
||||
textColor: 'text-gray-700 dark:text-gray-300',
|
||||
icon: 'lucide:message-circle',
|
||||
},
|
||||
intuition: {
|
||||
style: 'border-yellow-500 dark:bg-yellow-950/5',
|
||||
textColor: 'text-yellow-700 dark:text-yellow-300',
|
||||
icon: 'lucide:lightbulb',
|
||||
},
|
||||
recall: {
|
||||
style: 'border-blue-300 dark:bg-blue-950/5',
|
||||
textColor: 'text-blue-600 dark:text-blue-300',
|
||||
icon: 'lucide:rotate-ccw',
|
||||
},
|
||||
explanation: {
|
||||
style: 'border-lime-500 dark:bg-lime-950/5',
|
||||
textColor: 'text-lime-700 dark:text-lime-300',
|
||||
icon: 'lucide:help-circle',
|
||||
},
|
||||
example: {
|
||||
style: 'border-emerald-500 dark:bg-emerald-950/5',
|
||||
textColor: 'text-emerald-700 dark:text-emerald-300',
|
||||
icon: 'lucide:code',
|
||||
},
|
||||
exercise: {
|
||||
style: 'border-indigo-500 dark:bg-indigo-950/5',
|
||||
textColor: 'text-indigo-700 dark:text-indigo-300',
|
||||
icon: 'lucide:dumbbell',
|
||||
},
|
||||
problem: {
|
||||
style: 'border-orange-600 dark:bg-orange-950/5',
|
||||
textColor: 'text-orange-700 dark:text-orange-300',
|
||||
icon: 'lucide:alert-circle',
|
||||
},
|
||||
answer: {
|
||||
style: 'border-teal-500 dark:bg-teal-950/5',
|
||||
textColor: 'text-teal-700 dark:text-teal-300',
|
||||
icon: 'lucide:check',
|
||||
},
|
||||
solution: {
|
||||
style: 'border-emerald-600 dark:bg-emerald-950/5',
|
||||
textColor: 'text-emerald-700 dark:text-emerald-300',
|
||||
icon: 'lucide:check-circle-2',
|
||||
},
|
||||
summary: {
|
||||
style: 'border-sky-500 dark:bg-sky-950/5',
|
||||
textColor: 'text-sky-700 dark:text-sky-300',
|
||||
icon: 'lucide:list',
|
||||
},
|
||||
} as const
|
||||
|
||||
const capitalize = (str: string) => str.charAt(0).toUpperCase() + str.slice(1)
|
||||
|
||||
const calloutVariants = cva('relative px-4 py-3 my-6 border-l-4 text-sm', {
|
||||
variants: {
|
||||
variant: Object.fromEntries(
|
||||
Object.entries(calloutConfig).map(([key, config]) => [key, config.style]),
|
||||
),
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: 'note',
|
||||
},
|
||||
})
|
||||
|
||||
interface Props extends VariantProps<typeof calloutVariants> {
|
||||
title?: string
|
||||
class?: string
|
||||
variant?: keyof typeof calloutConfig
|
||||
defaultOpen?: boolean
|
||||
}
|
||||
|
||||
const { title, variant = 'note', defaultOpen = true, ...rest } = Astro.props
|
||||
---
|
||||
|
||||
<details
|
||||
class={cn(
|
||||
calloutVariants({ variant }),
|
||||
rest.class,
|
||||
'[&[open]>summary_svg:last-child]:rotate-180 [&[open]>summary]:mb-3',
|
||||
)}
|
||||
{...rest}
|
||||
open={defaultOpen}
|
||||
>
|
||||
<summary
|
||||
class="flex cursor-pointer items-center font-medium [&::-webkit-details-marker]:hidden"
|
||||
>
|
||||
<Icon
|
||||
name={calloutConfig[variant].icon}
|
||||
class={cn('mr-2 size-4 shrink-0', calloutConfig[variant].textColor)}
|
||||
/>
|
||||
<span class={cn('font-medium mr-2', calloutConfig[variant].textColor)}>
|
||||
{capitalize(variant)}
|
||||
{title && <span class="font-normal opacity-70"> ({title})</span>}
|
||||
</span>
|
||||
<Icon
|
||||
name="lucide:chevron-down"
|
||||
class={cn(
|
||||
'ml-auto h-4 w-4 shrink-0 transition-transform duration-200',
|
||||
calloutConfig[variant].textColor,
|
||||
)}
|
||||
/>
|
||||
</summary>
|
||||
<div>
|
||||
<slot />
|
||||
</div>
|
||||
</details>
|
||||
6
src/components/Favicons.astro
Normal file
@@ -0,0 +1,6 @@
|
||||
<link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<link rel="shortcut icon" href="/favicon.ico" />
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
|
||||
<meta name="apple-mobile-web-app-title" content="astro-erudite" />
|
||||
<link rel="manifest" href="/site.webmanifest" />
|
||||
26
src/components/Footer.astro
Normal file
@@ -0,0 +1,26 @@
|
||||
---
|
||||
import { Separator } from '@/components/ui/separator'
|
||||
import { SOCIAL_LINKS } from '@/consts'
|
||||
import Link from './Link.astro'
|
||||
import SocialIcons from './SocialIcons.astro'
|
||||
---
|
||||
|
||||
<footer
|
||||
class="mx-auto mb-8 flex w-full max-w-3xl flex-col items-center justify-center gap-y-2 px-4 sm:mb-4 sm:flex-row sm:justify-between"
|
||||
>
|
||||
<div class="flex flex-wrap items-center justify-center gap-x-2 text-center">
|
||||
<span class="text-muted-foreground text-sm">
|
||||
© {new Date().getFullYear()} All rights reserved.
|
||||
</span>
|
||||
<Separator orientation="vertical" className="hidden h-4! sm:block" />
|
||||
<p class="text-muted-foreground text-sm">
|
||||
Made with 🤍 by <Link
|
||||
href="https://github.com/jktrn"
|
||||
class="text-foreground"
|
||||
external
|
||||
underline>enscribe</Link
|
||||
>!
|
||||
</p>
|
||||
</div>
|
||||
<SocialIcons links={SOCIAL_LINKS} />
|
||||
</footer>
|
||||
49
src/components/Head.astro
Normal file
@@ -0,0 +1,49 @@
|
||||
---
|
||||
import { SITE } from '@/consts'
|
||||
import { ClientRouter } from 'astro:transitions'
|
||||
import Favicons from './Favicons.astro'
|
||||
---
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta
|
||||
name="viewport"
|
||||
content="width=device-width, initial-scale=1.0, user-scalable=yes"
|
||||
/>
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
|
||||
<meta name="HandheldFriendly" content="True" />
|
||||
<meta name="mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
|
||||
<meta
|
||||
name="format-detection"
|
||||
content="telephone=no,date=no,address=no,email=no,url=no"
|
||||
/>
|
||||
|
||||
<meta
|
||||
name="theme-color"
|
||||
content="#121212"
|
||||
media="(prefers-color-scheme: dark)"
|
||||
/>
|
||||
<meta
|
||||
name="theme-color"
|
||||
content="#121212"
|
||||
media="(prefers-color-scheme: light)"
|
||||
/>
|
||||
|
||||
<link rel="sitemap" href="/sitemap-index.xml" />
|
||||
<link rel="manifest" href="/site.webmanifest" />
|
||||
<link
|
||||
rel="alternate"
|
||||
type="application/rss+xml"
|
||||
title={SITE.title}
|
||||
href={new URL('rss.xml', Astro.site)}
|
||||
/>
|
||||
|
||||
<Favicons />
|
||||
<ClientRouter />
|
||||
|
||||
<slot />
|
||||
</head>
|
||||
36
src/components/Header.astro
Normal file
@@ -0,0 +1,36 @@
|
||||
---
|
||||
import Link from '@/components/Link.astro'
|
||||
import ThemeToggle from '@/components/ThemeToggle.astro'
|
||||
import { NAV_LINKS, SITE } from '@/consts'
|
||||
import { Image } from 'astro:assets'
|
||||
import logo from '../../public/static/logo.svg'
|
||||
---
|
||||
|
||||
<div>
|
||||
<div
|
||||
class="mx-auto flex max-w-3xl items-center justify-between gap-4 px-4 py-3"
|
||||
>
|
||||
<Link href="/" class="flex shrink-0 items-center justify-center gap-3">
|
||||
<Image src={logo} alt="Logo" class="size-5 sm:size-6" />
|
||||
<span
|
||||
class="hidden h-full text-lg leading-none font-medium min-[400px]:block"
|
||||
>{SITE.title}</span
|
||||
>
|
||||
</Link>
|
||||
<div class="flex items-center gap-4">
|
||||
<nav class="flex items-center gap-4 text-sm sm:gap-6">
|
||||
{
|
||||
NAV_LINKS.map((item) => (
|
||||
<Link
|
||||
href={item.href}
|
||||
class="text-foreground/60 hover:text-foreground capitalize transition-colors"
|
||||
>
|
||||
{item.label}
|
||||
</Link>
|
||||
))
|
||||
}
|
||||
</nav>
|
||||
<ThemeToggle transition:persist />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
27
src/components/Link.astro
Normal file
@@ -0,0 +1,27 @@
|
||||
---
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
interface Props {
|
||||
href: string
|
||||
external?: boolean
|
||||
class?: string
|
||||
underline?: boolean
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
const { href, external, class: className, underline, ...rest } = Astro.props
|
||||
---
|
||||
|
||||
<a
|
||||
href={href}
|
||||
target={external ? '_blank' : '_self'}
|
||||
class={cn(
|
||||
'inline-block transition-colors duration-300 ease-in-out',
|
||||
underline &&
|
||||
'underline decoration-muted-foreground underline-offset-[3px] hover:decoration-foreground',
|
||||
className,
|
||||
)}
|
||||
{...rest}
|
||||
>
|
||||
<slot />
|
||||
</a>
|
||||
36
src/components/PageHead.astro
Normal file
@@ -0,0 +1,36 @@
|
||||
---
|
||||
import { SITE } from '@/consts'
|
||||
|
||||
interface Props {
|
||||
title?: string
|
||||
description?: string
|
||||
noindex?: boolean
|
||||
}
|
||||
|
||||
const {
|
||||
title = SITE.title,
|
||||
description = SITE.description,
|
||||
noindex = false,
|
||||
} = Astro.props
|
||||
const image = new URL('/static/1200x630.png', Astro.site)
|
||||
---
|
||||
|
||||
<title>{`${title} | ${SITE.title}`}</title>
|
||||
<meta name="description" content={description} />
|
||||
<link rel="canonical" href={SITE.href} />
|
||||
{noindex && <meta name="robots" content="noindex, nofollow" />}
|
||||
|
||||
<meta property="og:title" content={title} />
|
||||
<meta property="og:description" content={description} />
|
||||
<meta property="og:image" content={image} />
|
||||
<meta property="og:image:alt" content={title} />
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="og:locale" content={SITE.locale} />
|
||||
<meta property="og:site_name" content={SITE.title} />
|
||||
<meta property="og:url" content={Astro.url} />
|
||||
|
||||
<meta name="twitter:title" content={title} />
|
||||
<meta name="twitter:description" content={description} />
|
||||
<meta name="twitter:image" content={image} />
|
||||
<meta name="twitter:image:alt" content={title} />
|
||||
<meta name="twitter:card" content="summary_large_image" />
|
||||
60
src/components/PostHead.astro
Normal file
@@ -0,0 +1,60 @@
|
||||
---
|
||||
import { SITE } from '@/consts'
|
||||
import { isSubpost } from '@/lib/data-utils'
|
||||
import type { CollectionEntry } from 'astro:content'
|
||||
|
||||
interface Props {
|
||||
post: CollectionEntry<'blog'>
|
||||
}
|
||||
|
||||
const { post } = Astro.props
|
||||
|
||||
const title = post.data.title || SITE.title
|
||||
const description = post.data.description || SITE.description
|
||||
const image = new URL('/static/1200x630.png', Astro.site)
|
||||
const author =
|
||||
post.data.authors && post.data.authors.length > 0
|
||||
? post.data.authors.join(', ')
|
||||
: SITE.author
|
||||
---
|
||||
|
||||
<title>{`${title} | ${SITE.title}`}</title>
|
||||
<meta name="title" content={`${title} | ${SITE.title}`} />
|
||||
<meta name="description" content={description} />
|
||||
<link rel="canonical" href={SITE.href} />
|
||||
|
||||
{isSubpost(post.id) && <meta name="robots" content="noindex" />}
|
||||
|
||||
<meta property="og:title" content={title} />
|
||||
<meta property="og:description" content={description} />
|
||||
<meta
|
||||
property="og:image"
|
||||
content={post?.data?.image?.src
|
||||
? `${SITE.href}${post.data.image.src}`
|
||||
: image}
|
||||
/>
|
||||
<meta property="og:image:alt" content={title} />
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="og:locale" content={SITE.locale} />
|
||||
<meta property="og:site_name" content={SITE.title} />
|
||||
<meta property="og:url" content={Astro.url} />
|
||||
<meta property="og:author" content={author} />
|
||||
|
||||
<meta name="twitter:title" content={title} />
|
||||
<meta name="twitter:description" content={description} />
|
||||
<meta
|
||||
property="twitter:image"
|
||||
content={post?.data?.image?.src
|
||||
? `${SITE.href}${post.data.image.src}`
|
||||
: image}
|
||||
/>
|
||||
<meta name="twitter:image:alt" content={title} />
|
||||
<meta name="twitter:card" content="summary_large_image" />
|
||||
<meta name="twitter:creator" content={author} />
|
||||
|
||||
{
|
||||
post?.data.tags &&
|
||||
post.data.tags.map((tag: string) => {
|
||||
return <meta property="article:tag" content={tag} />
|
||||
})
|
||||
}
|
||||
94
src/components/PostNavigation.astro
Normal file
@@ -0,0 +1,94 @@
|
||||
---
|
||||
import Link from '@/components/Link.astro'
|
||||
import { buttonVariants } from '@/components/ui/button'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { Icon } from 'astro-icon/components'
|
||||
|
||||
const { newerPost, olderPost, parentPost } = Astro.props
|
||||
const isSubpost = !!parentPost
|
||||
---
|
||||
|
||||
<nav
|
||||
class={cn(
|
||||
'col-start-2 grid grid-cols-1 gap-4',
|
||||
isSubpost ? 'sm:grid-cols-3' : 'sm:grid-cols-2',
|
||||
)}
|
||||
>
|
||||
<Link
|
||||
href={olderPost ? `/blog/${olderPost.id}#post-title` : '#'}
|
||||
class={cn(
|
||||
buttonVariants({ variant: 'outline' }),
|
||||
'rounded-lg group flex items-center justify-start size-full',
|
||||
!olderPost && 'pointer-events-none opacity-50 cursor-not-allowed',
|
||||
)}
|
||||
aria-disabled={!olderPost}
|
||||
>
|
||||
<Icon
|
||||
name="lucide:arrow-left"
|
||||
class="mr-2 size-4 transition-transform group-hover:-translate-x-1"
|
||||
/>
|
||||
<div class="flex flex-col items-start overflow-hidden text-wrap">
|
||||
<span class="text-muted-foreground text-left text-xs">
|
||||
{isSubpost ? 'Previous Subpost' : 'Previous Post'}
|
||||
</span>
|
||||
<span class="w-full text-left text-sm text-balance text-ellipsis">
|
||||
{
|
||||
olderPost?.data.title ||
|
||||
(isSubpost ? 'No older subpost' : "You're at the oldest post!")
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
</Link>
|
||||
|
||||
{
|
||||
isSubpost && (
|
||||
<Link
|
||||
href={parentPost ? `/blog/${parentPost.id}#post-title` : '#'}
|
||||
class={cn(
|
||||
buttonVariants({ variant: 'outline' }),
|
||||
'group flex size-full items-center justify-center rounded-lg',
|
||||
!parentPost && 'pointer-events-none cursor-not-allowed opacity-50',
|
||||
)}
|
||||
>
|
||||
<Icon
|
||||
name="lucide:corner-left-up"
|
||||
class="mr-2 size-4 transition-transform group-hover:-translate-y-1"
|
||||
/>
|
||||
<div class="flex flex-col items-center overflow-hidden text-wrap">
|
||||
<span class="text-muted-foreground text-center text-xs">
|
||||
Parent Post
|
||||
</span>
|
||||
<span class="w-full text-center text-sm text-balance text-ellipsis">
|
||||
{parentPost?.data.title || 'No parent post'}
|
||||
</span>
|
||||
</div>
|
||||
</Link>
|
||||
)
|
||||
}
|
||||
|
||||
<Link
|
||||
href={newerPost ? `/blog/${newerPost.id}#post-title` : '#'}
|
||||
class={cn(
|
||||
buttonVariants({ variant: 'outline' }),
|
||||
'rounded-lg group flex items-center justify-end size-full',
|
||||
!newerPost && 'pointer-events-none opacity-50 cursor-not-allowed',
|
||||
)}
|
||||
aria-disabled={!newerPost}
|
||||
>
|
||||
<div class="flex flex-col items-end overflow-hidden text-wrap">
|
||||
<span class="text-muted-foreground text-right text-xs">
|
||||
{isSubpost ? 'Next Subpost' : 'Next Post'}
|
||||
</span>
|
||||
<span class="w-full text-right text-sm text-balance text-ellipsis">
|
||||
{
|
||||
newerPost?.data.title ||
|
||||
(isSubpost ? 'No newer subpost' : "You're at the newest post!")
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
<Icon
|
||||
name="lucide:arrow-right"
|
||||
class="ml-2 size-4 transition-transform group-hover:translate-x-1"
|
||||
/>
|
||||
</Link>
|
||||
</nav>
|
||||
70
src/components/ProjectCard.astro
Normal file
@@ -0,0 +1,70 @@
|
||||
---
|
||||
import Link from '@/components/Link.astro'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { formatDate } from '@/lib/utils'
|
||||
import { Icon } from 'astro-icon/components'
|
||||
import { Image } from 'astro:assets'
|
||||
import type { CollectionEntry } from 'astro:content'
|
||||
|
||||
interface Props {
|
||||
project: CollectionEntry<'projects'>
|
||||
}
|
||||
|
||||
const { project } = Astro.props
|
||||
---
|
||||
|
||||
<div
|
||||
class="hover:bg-muted/50 rounded-xl border p-4 transition-colors duration-300 ease-in-out"
|
||||
>
|
||||
<Link
|
||||
href={project.data.link}
|
||||
class="flex flex-col gap-4 sm:flex-row"
|
||||
external
|
||||
>
|
||||
{
|
||||
project.data.image && (
|
||||
<div class="w-full sm:max-w-3xs sm:shrink-0">
|
||||
<Image
|
||||
src={project.data.image}
|
||||
alt={project.data.name}
|
||||
width={1200}
|
||||
height={630}
|
||||
class="object-cover"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
<div class="grow">
|
||||
<h3 class="mb-1 text-lg font-medium">
|
||||
{project.data.name}
|
||||
</h3>
|
||||
<p class="text-muted-foreground mb-2 text-sm">
|
||||
{project.data.description}
|
||||
</p>
|
||||
{
|
||||
project.data.startDate && (
|
||||
<p class="text-muted-foreground/70 mb-2 flex items-center gap-x-1.5 text-xs">
|
||||
<span class="flex items-center gap-x-1.5">
|
||||
<Icon name="lucide:calendar" class="size-3" />
|
||||
<span>
|
||||
{formatDate(project.data.startDate)}
|
||||
{project.data.endDate
|
||||
? ` → ${formatDate(project.data.endDate)}`
|
||||
: ' → Present'}
|
||||
</span>
|
||||
</span>
|
||||
</p>
|
||||
)
|
||||
}
|
||||
{
|
||||
project.data.tags && (
|
||||
<div class="flex flex-wrap gap-2">
|
||||
{project.data.tags.map((tag: string) => (
|
||||
<Badge variant="muted">{tag}</Badge>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</div>
|
||||
</Link>
|
||||
</div>
|
||||
37
src/components/SocialIcons.astro
Normal file
@@ -0,0 +1,37 @@
|
||||
---
|
||||
import Link from '@/components/Link.astro'
|
||||
import { buttonVariants } from '@/components/ui/button'
|
||||
import { ICON_MAP } from '@/consts'
|
||||
import type { SocialLink } from '@/types'
|
||||
import { Icon } from 'astro-icon/components'
|
||||
|
||||
interface Props {
|
||||
links: SocialLink[]
|
||||
}
|
||||
|
||||
const { links } = Astro.props
|
||||
---
|
||||
|
||||
<ul class="flex flex-wrap gap-2" role="list">
|
||||
{
|
||||
links.map(({ href, label }) => (
|
||||
<li>
|
||||
<Link
|
||||
href={href}
|
||||
aria-label={label}
|
||||
title={label}
|
||||
class={buttonVariants({ variant: 'outline', size: 'icon' })}
|
||||
external
|
||||
>
|
||||
<Icon
|
||||
name={
|
||||
ICON_MAP[label as keyof typeof ICON_MAP] ||
|
||||
'lucide:message-circle-question'
|
||||
}
|
||||
class="size-4"
|
||||
/>
|
||||
</Link>
|
||||
</li>
|
||||
))
|
||||
}
|
||||
</ul>
|
||||
314
src/components/SubpostsHeader.astro
Normal file
@@ -0,0 +1,314 @@
|
||||
---
|
||||
import { ScrollArea } from '@/components/ui/scroll-area'
|
||||
import {
|
||||
getCombinedReadingTime,
|
||||
getParentId,
|
||||
getParentPost,
|
||||
getPostById,
|
||||
getPostReadingTime,
|
||||
getSubpostsForParent,
|
||||
isSubpost,
|
||||
} from '@/lib/data-utils'
|
||||
import { Icon } from 'astro-icon/components'
|
||||
|
||||
const { parentId } = Astro.props
|
||||
const currentPostId = Astro.params.id as string
|
||||
const isCurrentSubpost = isSubpost(currentPostId)
|
||||
const rootParentId = isCurrentSubpost ? getParentId(currentPostId) : parentId
|
||||
|
||||
const currentPost = !isCurrentSubpost ? await getPostById(currentPostId) : null
|
||||
const subposts = await getSubpostsForParent(rootParentId)
|
||||
const parentPost = isCurrentSubpost ? await getParentPost(currentPostId) : null
|
||||
|
||||
const activePost = parentPost || currentPost
|
||||
const isActivePost = activePost?.id === currentPostId
|
||||
|
||||
const activePostReadingTime = activePost
|
||||
? await getPostReadingTime(activePost.id)
|
||||
: null
|
||||
const activePostCombinedReadingTime =
|
||||
activePost && subposts.length > 0
|
||||
? await getCombinedReadingTime(activePost.id)
|
||||
: null
|
||||
const subpostsWithReadingTime = await Promise.all(
|
||||
subposts.map(async (subpost) => ({
|
||||
...subpost,
|
||||
readingTime: await getPostReadingTime(subpost.id),
|
||||
})),
|
||||
)
|
||||
|
||||
const currentSubpostDetails = isCurrentSubpost
|
||||
? subpostsWithReadingTime.find((subpost) => subpost.id === currentPostId)
|
||||
: null
|
||||
---
|
||||
|
||||
{
|
||||
activePost && subposts.length > 0 && (
|
||||
<div id="mobile-subposts-container" class="w-full xl:hidden">
|
||||
<details class="group">
|
||||
<summary class="flex w-full cursor-pointer items-center justify-between">
|
||||
<div class="mx-auto flex w-full max-w-3xl items-center px-4 py-3">
|
||||
<div class="relative mr-2 size-4">
|
||||
<Icon
|
||||
name={
|
||||
currentSubpostDetails
|
||||
? 'lucide:file-text'
|
||||
: isActivePost
|
||||
? 'lucide:book-open-text'
|
||||
: 'lucide:book-open'
|
||||
}
|
||||
class="size-4 flex-shrink-0"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</div>
|
||||
<div class="flex flex-grow flex-col truncate text-sm">
|
||||
<span class="text-muted-foreground truncate">
|
||||
{currentSubpostDetails
|
||||
? currentSubpostDetails.data.title
|
||||
: activePost?.data.title}
|
||||
</span>
|
||||
</div>
|
||||
<span class="text-muted-foreground ml-2">
|
||||
<Icon
|
||||
name="lucide:chevron-down"
|
||||
class="h-4 w-4 transition-transform duration-200 group-open:rotate-180"
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
</summary>
|
||||
|
||||
<ScrollArea
|
||||
client:load
|
||||
className="mx-auto max-w-3xl"
|
||||
data-subposts-header-scroll
|
||||
>
|
||||
<div class="max-h-[30vh]">
|
||||
<ul class="flex list-none flex-col gap-y-1 px-4 pb-4">
|
||||
{activePost && (
|
||||
<li>
|
||||
{isActivePost ? (
|
||||
<div class="text-foreground bg-muted mobile-subposts-active-item flex items-center gap-2 rounded-md px-2 py-1.5 text-sm font-medium">
|
||||
<Icon
|
||||
name="lucide:book-open-text"
|
||||
class="size-4 flex-shrink-0"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<div class="flex flex-col">
|
||||
<span class="line-clamp-2">
|
||||
{activePost.data.title}
|
||||
</span>
|
||||
{activePostReadingTime && (
|
||||
<span class="text-muted-foreground/80 text-xs">
|
||||
{activePostReadingTime}
|
||||
{activePostCombinedReadingTime &&
|
||||
activePostCombinedReadingTime !==
|
||||
activePostReadingTime && (
|
||||
<span>
|
||||
{' '}
|
||||
({activePostCombinedReadingTime} total)
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<a
|
||||
href={`/blog/${activePost.id}`}
|
||||
class="mobile-subposts-link hover:text-foreground text-muted-foreground hover:bg-muted/50 flex items-center gap-2 rounded-md px-2 py-1.5 text-sm transition-colors"
|
||||
>
|
||||
<Icon
|
||||
name="lucide:book-open"
|
||||
class="size-4 flex-shrink-0"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<div class="flex flex-col">
|
||||
<span class="line-clamp-2">
|
||||
{activePost.data.title}
|
||||
</span>
|
||||
{activePostReadingTime && (
|
||||
<span class="text-muted-foreground/80 hover:text-foreground/80 text-xs">
|
||||
{activePostReadingTime}
|
||||
{activePostCombinedReadingTime &&
|
||||
activePostCombinedReadingTime !==
|
||||
activePostReadingTime && (
|
||||
<span>
|
||||
{' '}
|
||||
({activePostCombinedReadingTime} total)
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</a>
|
||||
)}
|
||||
</li>
|
||||
)}
|
||||
|
||||
{subpostsWithReadingTime.length > 0 && (
|
||||
<div class="ml-4 space-y-1">
|
||||
{subpostsWithReadingTime.map((subpost) =>
|
||||
currentPostId === subpost.id ? (
|
||||
<div class="text-foreground bg-muted mobile-subposts-active-item flex items-center gap-2 rounded-md px-2 py-1.5 text-sm font-medium">
|
||||
<Icon
|
||||
name="lucide:file-text"
|
||||
class="size-4 flex-shrink-0"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<div class="flex flex-col">
|
||||
<span class="line-clamp-2">{subpost.data.title}</span>
|
||||
<span class="text-muted-foreground/80 text-xs">
|
||||
{subpost.readingTime}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<a
|
||||
href={`/blog/${subpost.id}`}
|
||||
class="mobile-subposts-link hover:text-foreground text-muted-foreground hover:bg-muted/50 flex items-center gap-2 rounded-md px-2 py-1.5 text-sm transition-colors"
|
||||
>
|
||||
<Icon
|
||||
name="lucide:file"
|
||||
class="size-4 flex-shrink-0"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<div class="flex flex-col">
|
||||
<span class="line-clamp-2">{subpost.data.title}</span>
|
||||
<span class="text-muted-foreground/80 hover:text-foreground/80 text-xs">
|
||||
{subpost.readingTime}
|
||||
</span>
|
||||
</div>
|
||||
</a>
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</ul>
|
||||
</div>
|
||||
</ScrollArea>
|
||||
</details>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
<script>
|
||||
class SubpostsState {
|
||||
scrollArea: HTMLElement | null = null
|
||||
detailsElement: HTMLDetailsElement | null = null
|
||||
headerScrollArea: HTMLElement | null = null
|
||||
|
||||
reset() {
|
||||
this.scrollArea = null
|
||||
this.detailsElement = null
|
||||
this.headerScrollArea = null
|
||||
}
|
||||
}
|
||||
|
||||
const state = new SubpostsState()
|
||||
|
||||
class SubpostsHeaderScrollMask {
|
||||
static update() {
|
||||
if (!state.scrollArea || !state.headerScrollArea) return
|
||||
|
||||
const { scrollTop, scrollHeight, clientHeight } = state.scrollArea
|
||||
const threshold = 5
|
||||
const isAtTop = scrollTop <= threshold
|
||||
const isAtBottom = scrollTop >= scrollHeight - clientHeight - threshold
|
||||
|
||||
state.headerScrollArea.classList.toggle('mask-t-from-80%', !isAtTop)
|
||||
state.headerScrollArea.classList.toggle('mask-b-from-80%', !isAtBottom)
|
||||
}
|
||||
}
|
||||
|
||||
class SubpostsScroll {
|
||||
static toActive() {
|
||||
if (!state.scrollArea) return
|
||||
|
||||
const activeItem = state.scrollArea.querySelector(
|
||||
'.mobile-subposts-active-item',
|
||||
)
|
||||
if (!activeItem) return
|
||||
|
||||
const { top: areaTop, height: areaHeight } =
|
||||
state.scrollArea.getBoundingClientRect()
|
||||
const { top: itemTop, height: itemHeight } =
|
||||
activeItem.getBoundingClientRect()
|
||||
|
||||
const currentItemTop = itemTop - areaTop + state.scrollArea.scrollTop
|
||||
const targetScroll = Math.max(
|
||||
0,
|
||||
Math.min(
|
||||
currentItemTop - (areaHeight - itemHeight) / 2,
|
||||
state.scrollArea.scrollHeight - state.scrollArea.clientHeight,
|
||||
),
|
||||
)
|
||||
|
||||
state.scrollArea.scrollTop = targetScroll
|
||||
}
|
||||
|
||||
static setupInteraction() {
|
||||
const container = document.getElementById('mobile-subposts-container')
|
||||
if (!container) return
|
||||
|
||||
state.scrollArea = container.querySelector(
|
||||
'[data-radix-scroll-area-viewport]',
|
||||
)
|
||||
state.detailsElement = container.querySelector('details')
|
||||
state.headerScrollArea = container.querySelector(
|
||||
'[data-subposts-header-scroll]',
|
||||
)
|
||||
const links = container.querySelectorAll('.mobile-subposts-link')
|
||||
|
||||
if (state.scrollArea) {
|
||||
state.scrollArea.addEventListener(
|
||||
'scroll',
|
||||
SubpostsHeaderScrollMask.update,
|
||||
{ passive: true },
|
||||
)
|
||||
}
|
||||
|
||||
if (state.detailsElement) {
|
||||
state.detailsElement.addEventListener('toggle', () => {
|
||||
if (state.detailsElement?.open) {
|
||||
requestAnimationFrame(() => {
|
||||
SubpostsScroll.toActive()
|
||||
setTimeout(SubpostsHeaderScrollMask.update, 100)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
links.forEach((link) => {
|
||||
link.addEventListener('click', () => {
|
||||
if (state.detailsElement) state.detailsElement.open = false
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
class SubpostsController {
|
||||
static init() {
|
||||
state.reset()
|
||||
SubpostsScroll.setupInteraction()
|
||||
}
|
||||
|
||||
static cleanup() {
|
||||
if (state.scrollArea) {
|
||||
state.scrollArea.removeEventListener(
|
||||
'scroll',
|
||||
SubpostsHeaderScrollMask.update,
|
||||
)
|
||||
}
|
||||
state.reset()
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('astro:page-load', () => SubpostsController.init())
|
||||
document.addEventListener('astro:after-swap', () => {
|
||||
SubpostsController.cleanup()
|
||||
SubpostsController.init()
|
||||
})
|
||||
document.addEventListener('astro:before-swap', () =>
|
||||
SubpostsController.cleanup(),
|
||||
)
|
||||
</script>
|
||||
267
src/components/SubpostsSidebar.astro
Normal file
@@ -0,0 +1,267 @@
|
||||
---
|
||||
import Link from '@/components/Link.astro'
|
||||
import { ScrollArea } from '@/components/ui/scroll-area'
|
||||
import {
|
||||
getCombinedReadingTime,
|
||||
getParentId,
|
||||
getParentPost,
|
||||
getPostById,
|
||||
getPostReadingTime,
|
||||
getSubpostsForParent,
|
||||
isSubpost,
|
||||
} from '@/lib/data-utils'
|
||||
import { Icon } from 'astro-icon/components'
|
||||
|
||||
const { parentId } = Astro.props
|
||||
const currentPostId = Astro.params.id as string
|
||||
const isCurrentSubpost = isSubpost(currentPostId)
|
||||
const rootParentId = isCurrentSubpost ? getParentId(currentPostId) : parentId
|
||||
|
||||
const currentPost = !isCurrentSubpost ? await getPostById(currentPostId) : null
|
||||
const subposts = await getSubpostsForParent(rootParentId)
|
||||
const parentPost = isCurrentSubpost ? await getParentPost(currentPostId) : null
|
||||
|
||||
const activePost = parentPost || currentPost
|
||||
const isActivePost = activePost?.id === currentPostId
|
||||
|
||||
const activePostReadingTime = activePost
|
||||
? await getPostReadingTime(activePost.id)
|
||||
: null
|
||||
const activePostCombinedReadingTime =
|
||||
activePost && subposts.length > 0
|
||||
? await getCombinedReadingTime(activePost.id)
|
||||
: null
|
||||
const subpostsWithReadingTime = await Promise.all(
|
||||
subposts.map(async (subpost) => ({
|
||||
...subpost,
|
||||
readingTime: await getPostReadingTime(subpost.id),
|
||||
})),
|
||||
)
|
||||
---
|
||||
|
||||
<div
|
||||
id="subposts-sidebar-container"
|
||||
class="sticky top-20 col-start-3 row-span-1 mr-auto ml-8 hidden h-[calc(100vh-5rem)] max-w-md xl:block"
|
||||
>
|
||||
<ScrollArea
|
||||
client:load
|
||||
className="flex max-h-[calc(100vh-8rem)] flex-col overflow-y-auto"
|
||||
data-subposts-sidebar-scroll
|
||||
>
|
||||
<div class="px-4">
|
||||
<ul class="space-y-1">
|
||||
{
|
||||
activePost && (
|
||||
<li>
|
||||
{isActivePost ? (
|
||||
<div class="text-foreground bg-muted subposts-sidebar-active-item flex items-center gap-2 rounded-md py-1.5 pr-3 pl-2 text-sm font-medium text-pretty">
|
||||
<Icon
|
||||
name="lucide:book-open-text"
|
||||
class="size-4 flex-shrink-0"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<div class="flex flex-col">
|
||||
<span class="line-clamp-2 text-pretty">
|
||||
{activePost.data.title}
|
||||
</span>
|
||||
{activePostReadingTime && (
|
||||
<span class="text-muted-foreground/80 text-xs">
|
||||
{activePostReadingTime}
|
||||
{activePostCombinedReadingTime &&
|
||||
activePostCombinedReadingTime !==
|
||||
activePostReadingTime && (
|
||||
<span>
|
||||
{' '}
|
||||
({activePostCombinedReadingTime} total)
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<Link
|
||||
href={`/blog/${activePost.id}#post-title`}
|
||||
class="hover:text-foreground text-muted-foreground hover:bg-muted/50 subposts-sidebar-link flex items-center gap-2 rounded-md px-2 py-1.5 text-sm text-pretty transition-colors"
|
||||
>
|
||||
<Icon
|
||||
name="lucide:book-open"
|
||||
class="size-4 flex-shrink-0"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<div class="flex flex-col">
|
||||
<span class="line-clamp-2 text-pretty">
|
||||
{activePost.data.title}
|
||||
</span>
|
||||
{activePostReadingTime && (
|
||||
<span class="text-muted-foreground/80 text-xs">
|
||||
{activePostReadingTime}
|
||||
{activePostCombinedReadingTime &&
|
||||
activePostCombinedReadingTime !==
|
||||
activePostReadingTime && (
|
||||
<span>
|
||||
{' '}
|
||||
({activePostCombinedReadingTime} total)
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</Link>
|
||||
)}
|
||||
</li>
|
||||
)
|
||||
}
|
||||
|
||||
{
|
||||
subpostsWithReadingTime.length > 0 && (
|
||||
<li class="ml-4 space-y-1">
|
||||
{subpostsWithReadingTime.map((subpost) =>
|
||||
currentPostId === subpost.id ? (
|
||||
<div class="text-foreground bg-muted subposts-sidebar-active-item flex items-center gap-2 rounded-md px-2 py-1.5 text-sm font-medium text-pretty">
|
||||
<Icon
|
||||
name="lucide:file-text"
|
||||
class="size-4 flex-shrink-0"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<div class="flex flex-col">
|
||||
<span class="line-clamp-2 text-pretty">
|
||||
{subpost.data.title}
|
||||
</span>
|
||||
<span class="text-muted-foreground/80 text-xs">
|
||||
{subpost.readingTime}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<Link
|
||||
href={`/blog/${subpost.id}`}
|
||||
class="hover:text-foreground text-muted-foreground hover:bg-muted/50 subposts-sidebar-link flex items-center gap-2 rounded-md px-2 py-1.5 text-sm text-pretty transition-colors"
|
||||
>
|
||||
<Icon
|
||||
name="lucide:file"
|
||||
class="size-4 flex-shrink-0"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<div class="flex flex-col">
|
||||
<span class="line-clamp-2 text-pretty">
|
||||
{subpost.data.title}
|
||||
</span>
|
||||
<span class="text-muted-foreground/80 text-xs">
|
||||
{subpost.readingTime}
|
||||
</span>
|
||||
</div>
|
||||
</Link>
|
||||
),
|
||||
)}
|
||||
</li>
|
||||
)
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
</ScrollArea>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
class SidebarState {
|
||||
scrollArea: HTMLElement | null = null
|
||||
sidebarScrollArea: HTMLElement | null = null
|
||||
|
||||
reset() {
|
||||
this.scrollArea = null
|
||||
this.sidebarScrollArea = null
|
||||
}
|
||||
}
|
||||
|
||||
const state = new SidebarState()
|
||||
|
||||
class SidebarScrollMask {
|
||||
static update() {
|
||||
if (!state.scrollArea || !state.sidebarScrollArea) return
|
||||
|
||||
const { scrollTop, scrollHeight, clientHeight } = state.scrollArea
|
||||
const threshold = 5
|
||||
const isAtTop = scrollTop <= threshold
|
||||
const isAtBottom = scrollTop >= scrollHeight - clientHeight - threshold
|
||||
|
||||
state.sidebarScrollArea.classList.toggle('mask-t-from-90%', !isAtTop)
|
||||
state.sidebarScrollArea.classList.toggle('mask-b-from-90%', !isAtBottom)
|
||||
}
|
||||
}
|
||||
|
||||
class SidebarScroll {
|
||||
static toActive() {
|
||||
if (!state.scrollArea) return
|
||||
|
||||
const activeItem = state.scrollArea.querySelector(
|
||||
'.subposts-sidebar-active-item',
|
||||
)
|
||||
if (!activeItem) {
|
||||
return
|
||||
}
|
||||
|
||||
const { top: areaTop, height: areaHeight } =
|
||||
state.scrollArea.getBoundingClientRect()
|
||||
const { top: itemTop, height: itemHeight } =
|
||||
activeItem.getBoundingClientRect()
|
||||
|
||||
const currentItemTop = itemTop - areaTop + state.scrollArea.scrollTop
|
||||
const targetScroll = Math.max(
|
||||
0,
|
||||
Math.min(
|
||||
currentItemTop - (areaHeight - itemHeight) / 2,
|
||||
state.scrollArea.scrollHeight - state.scrollArea.clientHeight,
|
||||
),
|
||||
)
|
||||
|
||||
state.scrollArea.scrollTop = targetScroll
|
||||
}
|
||||
}
|
||||
|
||||
class SidebarController {
|
||||
static init() {
|
||||
state.reset()
|
||||
|
||||
const sidebarContainer = document.getElementById(
|
||||
'subposts-sidebar-container',
|
||||
)
|
||||
if (sidebarContainer) {
|
||||
state.scrollArea = sidebarContainer.querySelector(
|
||||
'[data-radix-scroll-area-viewport]',
|
||||
)
|
||||
state.sidebarScrollArea = sidebarContainer.querySelector(
|
||||
'[data-subposts-sidebar-scroll]',
|
||||
)
|
||||
|
||||
if (state.scrollArea) {
|
||||
state.scrollArea.addEventListener(
|
||||
'scroll',
|
||||
SidebarScrollMask.update,
|
||||
{ passive: true },
|
||||
)
|
||||
}
|
||||
|
||||
requestAnimationFrame(() => {
|
||||
SidebarScroll.toActive()
|
||||
setTimeout(SidebarScrollMask.update, 100)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
static cleanup() {
|
||||
if (state.scrollArea) {
|
||||
state.scrollArea.removeEventListener('scroll', SidebarScrollMask.update)
|
||||
}
|
||||
state.reset()
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('astro:page-load', () => SidebarController.init())
|
||||
document.addEventListener('astro:after-swap', () => {
|
||||
SidebarController.cleanup()
|
||||
SidebarController.init()
|
||||
})
|
||||
document.addEventListener('astro:before-swap', () =>
|
||||
SidebarController.cleanup(),
|
||||
)
|
||||
</script>
|
||||
398
src/components/TOCHeader.astro
Normal file
@@ -0,0 +1,398 @@
|
||||
---
|
||||
import { ScrollArea } from '@/components/ui/scroll-area'
|
||||
import { cn, getHeadingMargin } from '@/lib/utils'
|
||||
import type { MarkdownHeading } from 'astro'
|
||||
import { Icon } from 'astro-icon/components'
|
||||
|
||||
type Props = {
|
||||
headings: MarkdownHeading[]
|
||||
}
|
||||
|
||||
const { headings } = Astro.props
|
||||
---
|
||||
|
||||
{
|
||||
headings && headings.length > 0 && (
|
||||
<div id="mobile-toc-container" class="w-full xl:hidden">
|
||||
<details class="group">
|
||||
<summary class="flex w-full cursor-pointer items-center justify-between">
|
||||
<div class="mx-auto flex w-full max-w-3xl items-center px-4 py-3">
|
||||
<div class="relative mr-2 size-4">
|
||||
<svg class="h-4 w-4" viewBox="0 0 24 24">
|
||||
<circle
|
||||
class="text-primary/20"
|
||||
cx="12"
|
||||
cy="12"
|
||||
r="10"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
/>
|
||||
<circle
|
||||
id="mobile-toc-progress-circle"
|
||||
class="text-primary"
|
||||
cx="12"
|
||||
cy="12"
|
||||
r="10"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-dasharray="62.83"
|
||||
stroke-dashoffset="62.83"
|
||||
transform="rotate(-90 12 12)"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
<span
|
||||
id="mobile-toc-current-section"
|
||||
class="text-muted-foreground flex-grow truncate text-sm"
|
||||
>
|
||||
Overview
|
||||
</span>
|
||||
<span class="text-muted-foreground ml-2">
|
||||
<Icon
|
||||
name="lucide:chevron-down"
|
||||
class="h-4 w-4 transition-transform duration-200 group-open:rotate-180"
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
</summary>
|
||||
|
||||
<ScrollArea
|
||||
client:load
|
||||
className="mx-auto max-w-3xl"
|
||||
data-toc-header-scroll
|
||||
>
|
||||
<div class="max-h-[30vh]">
|
||||
<ul
|
||||
class="flex list-none flex-col gap-y-2 px-4 pb-4"
|
||||
id="mobile-table-of-contents"
|
||||
>
|
||||
{headings.map((heading) => (
|
||||
<li
|
||||
class={cn(
|
||||
'px-4 text-sm',
|
||||
getHeadingMargin(heading.depth),
|
||||
'text-foreground/60',
|
||||
)}
|
||||
>
|
||||
<a
|
||||
href={`#${heading.slug}`}
|
||||
class="mobile-toc-item underline decoration-transparent underline-offset-[3px] transition-colors duration-200 hover:decoration-inherit"
|
||||
data-heading-id={heading.slug}
|
||||
>
|
||||
{heading.text}
|
||||
</a>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</ScrollArea>
|
||||
</details>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
<script>
|
||||
const INITIAL_OVERVIEW_TEXT = 'Overview'
|
||||
const HEADER_OFFSET = 102 + 36
|
||||
const PROGRESS_CIRCLE_RADIUS = 10
|
||||
const PROGRESS_CIRCLE_CIRCUMFERENCE = 2 * Math.PI * PROGRESS_CIRCLE_RADIUS
|
||||
|
||||
class MobileTOCState {
|
||||
progressCircle: HTMLElement | null = null
|
||||
currentSectionText: HTMLElement | null = null
|
||||
detailsElement: HTMLDetailsElement | null = null
|
||||
listElement: HTMLElement | null = null
|
||||
scrollArea: HTMLElement | null = null
|
||||
headings: HTMLElement[] = []
|
||||
regions: { id: string; start: number; end: number }[] = []
|
||||
activeIds: string[] = []
|
||||
|
||||
reset() {
|
||||
this.progressCircle = document.getElementById(
|
||||
'mobile-toc-progress-circle',
|
||||
)
|
||||
this.currentSectionText = document.getElementById(
|
||||
'mobile-toc-current-section',
|
||||
)
|
||||
this.detailsElement = document.querySelector(
|
||||
'#mobile-toc-container details',
|
||||
)
|
||||
this.listElement = document.getElementById('mobile-table-of-contents')
|
||||
const tocContainer = document.getElementById('mobile-toc-container')
|
||||
this.scrollArea =
|
||||
tocContainer?.querySelector('[data-radix-scroll-area-viewport]') || null
|
||||
this.headings = []
|
||||
this.regions = []
|
||||
this.activeIds = []
|
||||
|
||||
if (this.progressCircle) {
|
||||
this.progressCircle.style.strokeDasharray =
|
||||
PROGRESS_CIRCLE_CIRCUMFERENCE.toString()
|
||||
this.progressCircle.style.strokeDashoffset =
|
||||
PROGRESS_CIRCLE_CIRCUMFERENCE.toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const state = new MobileTOCState()
|
||||
|
||||
class HeadingRegions {
|
||||
static build() {
|
||||
state.headings = Array.from(
|
||||
document.querySelectorAll<HTMLElement>(
|
||||
'.prose h2, .prose h3, .prose h4, .prose h5, .prose h6',
|
||||
),
|
||||
)
|
||||
|
||||
if (state.headings.length === 0) {
|
||||
state.regions = []
|
||||
return
|
||||
}
|
||||
|
||||
state.regions = state.headings.map((heading, index) => {
|
||||
const nextHeading = state.headings[index + 1]
|
||||
return {
|
||||
id: heading.id,
|
||||
start: heading.offsetTop,
|
||||
end: nextHeading ? nextHeading.offsetTop : document.body.scrollHeight,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
static getVisibleIds(): string[] {
|
||||
if (state.headings.length === 0) return []
|
||||
|
||||
const viewportTop = window.scrollY + HEADER_OFFSET
|
||||
const viewportBottom = window.scrollY + window.innerHeight
|
||||
const visibleIds = new Set<string>()
|
||||
|
||||
const isInViewport = (top: number, bottom: number) =>
|
||||
(top >= viewportTop && top <= viewportBottom) ||
|
||||
(bottom >= viewportTop && bottom <= viewportBottom) ||
|
||||
(top <= viewportTop && bottom >= viewportBottom)
|
||||
|
||||
state.headings.forEach((heading) => {
|
||||
const headingBottom = heading.offsetTop + heading.offsetHeight
|
||||
if (isInViewport(heading.offsetTop, headingBottom)) {
|
||||
visibleIds.add(heading.id)
|
||||
}
|
||||
})
|
||||
|
||||
state.regions.forEach((region) => {
|
||||
if (region.start <= viewportBottom && region.end >= viewportTop) {
|
||||
const heading = document.getElementById(region.id)
|
||||
if (heading) {
|
||||
const headingBottom = heading.offsetTop + heading.offsetHeight
|
||||
if (
|
||||
region.end > headingBottom &&
|
||||
(headingBottom < viewportBottom || viewportTop < region.end)
|
||||
) {
|
||||
visibleIds.add(region.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return Array.from(visibleIds)
|
||||
}
|
||||
}
|
||||
|
||||
class TOCHeaderScrollMask {
|
||||
static update() {
|
||||
if (!state.scrollArea) return
|
||||
|
||||
const { scrollTop, scrollHeight, clientHeight } = state.scrollArea
|
||||
const threshold = 5
|
||||
const isAtTop = scrollTop <= threshold
|
||||
const isAtBottom = scrollTop >= scrollHeight - clientHeight - threshold
|
||||
|
||||
state.scrollArea.classList.toggle('mask-t-from-80%', !isAtTop)
|
||||
state.scrollArea.classList.toggle('mask-b-from-80%', !isAtBottom)
|
||||
}
|
||||
}
|
||||
|
||||
class MobileTOCLinks {
|
||||
static update(headingIds: string[]) {
|
||||
if (!state.listElement || !state.currentSectionText) return
|
||||
|
||||
state.listElement.querySelectorAll('.mobile-toc-item').forEach((item) => {
|
||||
const tocItem = item as HTMLElement
|
||||
const headingId = tocItem.dataset.headingId
|
||||
if (headingId && headingIds.includes(headingId)) {
|
||||
tocItem.classList.add('text-foreground')
|
||||
} else {
|
||||
tocItem.classList.remove('text-foreground')
|
||||
}
|
||||
})
|
||||
|
||||
if (headingIds.length > 0) {
|
||||
this.scrollToActive(headingIds[0])
|
||||
}
|
||||
|
||||
this.updateCurrentSectionText(headingIds)
|
||||
}
|
||||
|
||||
static updateCurrentSectionText(headingIds: string[]) {
|
||||
if (!state.currentSectionText) return
|
||||
|
||||
let textToShow = INITIAL_OVERVIEW_TEXT
|
||||
|
||||
if (headingIds.length > 0) {
|
||||
const activeTexts = state.headings
|
||||
.filter(
|
||||
(heading) => headingIds.includes(heading.id) && heading.textContent,
|
||||
)
|
||||
.map((heading) => heading.textContent!.trim())
|
||||
|
||||
if (activeTexts.length > 0) {
|
||||
textToShow = activeTexts.join(', ')
|
||||
}
|
||||
}
|
||||
|
||||
state.currentSectionText.textContent = textToShow
|
||||
}
|
||||
|
||||
static scrollToActive(activeHeadingId: string) {
|
||||
if (!state.listElement) return
|
||||
|
||||
const activeItem = state.listElement.querySelector(
|
||||
`[data-heading-id="${activeHeadingId}"]`,
|
||||
)
|
||||
if (!activeItem) return
|
||||
|
||||
const scrollContainer = state.scrollArea
|
||||
if (!scrollContainer) return
|
||||
|
||||
const { top: containerTop, height: containerHeight } =
|
||||
scrollContainer.getBoundingClientRect()
|
||||
const { top: itemTop, height: itemHeight } =
|
||||
activeItem.getBoundingClientRect()
|
||||
|
||||
const currentItemTop = itemTop - containerTop + scrollContainer.scrollTop
|
||||
const targetScroll = Math.max(
|
||||
0,
|
||||
Math.min(
|
||||
currentItemTop - (containerHeight - itemHeight) / 2,
|
||||
scrollContainer.scrollHeight - scrollContainer.clientHeight,
|
||||
),
|
||||
)
|
||||
|
||||
if (Math.abs(targetScroll - scrollContainer.scrollTop) > 5) {
|
||||
scrollContainer.scrollTop = targetScroll
|
||||
}
|
||||
}
|
||||
|
||||
static setupInteraction() {
|
||||
if (!state.listElement) return
|
||||
|
||||
state.listElement.querySelectorAll('.mobile-toc-item').forEach((item) => {
|
||||
item.addEventListener('click', () => {
|
||||
if (state.detailsElement) state.detailsElement.open = false
|
||||
})
|
||||
})
|
||||
|
||||
if (state.scrollArea) {
|
||||
state.scrollArea.addEventListener(
|
||||
'scroll',
|
||||
() => TOCHeaderScrollMask.update(),
|
||||
{ passive: true },
|
||||
)
|
||||
}
|
||||
|
||||
if (state.detailsElement) {
|
||||
state.detailsElement.addEventListener('toggle', () => {
|
||||
if (state.detailsElement?.open) {
|
||||
setTimeout(TOCHeaderScrollMask.update, 100)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ProgressCircle {
|
||||
static update() {
|
||||
if (!state.progressCircle) return
|
||||
|
||||
const scrollableDistance =
|
||||
document.documentElement.scrollHeight - window.innerHeight
|
||||
const scrollProgress =
|
||||
scrollableDistance > 0
|
||||
? Math.min(Math.max(window.scrollY / scrollableDistance, 0), 1)
|
||||
: 0
|
||||
|
||||
state.progressCircle.style.strokeDashoffset = (
|
||||
PROGRESS_CIRCLE_CIRCUMFERENCE *
|
||||
(1 - scrollProgress)
|
||||
).toString()
|
||||
}
|
||||
}
|
||||
|
||||
class MobileTOCController {
|
||||
static handleScroll() {
|
||||
const newActiveIds = HeadingRegions.getVisibleIds()
|
||||
|
||||
if (JSON.stringify(newActiveIds) !== JSON.stringify(state.activeIds)) {
|
||||
state.activeIds = newActiveIds
|
||||
MobileTOCLinks.update(state.activeIds)
|
||||
}
|
||||
|
||||
ProgressCircle.update()
|
||||
}
|
||||
|
||||
static handleResize() {
|
||||
HeadingRegions.build()
|
||||
|
||||
const newActiveIds = HeadingRegions.getVisibleIds()
|
||||
if (JSON.stringify(newActiveIds) !== JSON.stringify(state.activeIds)) {
|
||||
state.activeIds = newActiveIds
|
||||
MobileTOCLinks.update(state.activeIds)
|
||||
}
|
||||
|
||||
ProgressCircle.update()
|
||||
}
|
||||
|
||||
static init() {
|
||||
state.reset()
|
||||
HeadingRegions.build()
|
||||
|
||||
if (!state.currentSectionText) return
|
||||
|
||||
if (state.headings.length === 0) {
|
||||
state.currentSectionText.textContent = INITIAL_OVERVIEW_TEXT
|
||||
window.addEventListener('scroll', ProgressCircle.update, {
|
||||
passive: true,
|
||||
})
|
||||
ProgressCircle.update()
|
||||
return
|
||||
}
|
||||
|
||||
state.activeIds = HeadingRegions.getVisibleIds()
|
||||
MobileTOCLinks.update(state.activeIds)
|
||||
ProgressCircle.update()
|
||||
|
||||
MobileTOCLinks.setupInteraction()
|
||||
window.addEventListener('scroll', this.handleScroll, { passive: true })
|
||||
window.addEventListener('resize', this.handleResize, { passive: true })
|
||||
}
|
||||
|
||||
static cleanup() {
|
||||
window.removeEventListener('scroll', this.handleScroll)
|
||||
window.removeEventListener('scroll', ProgressCircle.update)
|
||||
window.removeEventListener('resize', this.handleResize)
|
||||
state.activeIds = []
|
||||
state.headings = []
|
||||
state.regions = []
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('astro:page-load', () => MobileTOCController.init())
|
||||
document.addEventListener('astro:after-swap', () => {
|
||||
MobileTOCController.cleanup()
|
||||
MobileTOCController.init()
|
||||
})
|
||||
document.addEventListener('astro:before-swap', () =>
|
||||
MobileTOCController.cleanup(),
|
||||
)
|
||||
</script>
|
||||
365
src/components/TOCSidebar.astro
Normal file
@@ -0,0 +1,365 @@
|
||||
---
|
||||
import { ScrollArea } from '@/components/ui/scroll-area'
|
||||
import type { TOCSection } from '@/lib/data-utils'
|
||||
import { getParentId, isSubpost } from '@/lib/data-utils'
|
||||
import { cn, getHeadingMargin } from '@/lib/utils'
|
||||
|
||||
type Props = {
|
||||
sections: TOCSection[]
|
||||
currentPostId: string
|
||||
}
|
||||
|
||||
const { sections, currentPostId } = Astro.props
|
||||
const isCurrentSubpost = isSubpost(currentPostId)
|
||||
const parentId = isCurrentSubpost ? getParentId(currentPostId) : currentPostId
|
||||
---
|
||||
|
||||
{
|
||||
sections.length > 0 && (
|
||||
<div
|
||||
id="toc-sidebar-container"
|
||||
class="sticky top-20 col-start-1 row-span-1 mr-8 ml-auto hidden h-[calc(100vh-5rem)] max-w-md xl:block"
|
||||
>
|
||||
<ScrollArea
|
||||
client:load
|
||||
className="flex max-h-[calc(100vh-8rem)] flex-col overflow-y-auto"
|
||||
type="hover"
|
||||
data-toc-scroll-area
|
||||
>
|
||||
<div class="flex flex-col gap-2 px-4">
|
||||
<span class="text-lg font-medium">Table of Contents</span>
|
||||
{sections.map((section, index) => {
|
||||
const isFirstSubpost =
|
||||
section.type === 'subpost' &&
|
||||
(index === 0 || sections[index - 1].type === 'parent')
|
||||
|
||||
return (
|
||||
<>
|
||||
{isFirstSubpost && (
|
||||
<div class="mt-2 flex items-center gap-2">
|
||||
<div class="bg-border h-px flex-1" />
|
||||
<span class="text-muted-foreground text-xs font-medium">
|
||||
Subposts
|
||||
</span>
|
||||
<div class="bg-border h-px flex-1" />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{section.type === 'parent' ? (
|
||||
<ul class="flex list-none flex-col gap-y-2">
|
||||
{section.headings.map((heading) => (
|
||||
<li
|
||||
class={cn(
|
||||
'text-sm',
|
||||
getHeadingMargin(heading.depth),
|
||||
isCurrentSubpost
|
||||
? 'text-foreground/40'
|
||||
: 'text-foreground/60',
|
||||
)}
|
||||
>
|
||||
<a
|
||||
href={
|
||||
isCurrentSubpost
|
||||
? `/blog/${parentId}#${heading.slug}`
|
||||
: `#${heading.slug}`
|
||||
}
|
||||
class="marker:text-foreground/30 list-none underline decoration-transparent underline-offset-[3px] transition-colors duration-200 hover:decoration-inherit"
|
||||
data-heading-link={heading.slug}
|
||||
>
|
||||
{heading.text}
|
||||
</a>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
<div
|
||||
class={cn(
|
||||
'rounded-md border p-2',
|
||||
section.subpostId === currentPostId ? 'bg-muted/50' : '',
|
||||
)}
|
||||
>
|
||||
<ul class="flex list-none flex-col gap-y-2">
|
||||
<li
|
||||
class={cn(
|
||||
'text-xs font-medium',
|
||||
section.subpostId === currentPostId
|
||||
? 'text-foreground'
|
||||
: 'text-foreground/60',
|
||||
)}
|
||||
>
|
||||
<a
|
||||
href={
|
||||
section.subpostId === currentPostId
|
||||
? '#'
|
||||
: `/blog/${section.subpostId}`
|
||||
}
|
||||
class="marker:text-foreground/30 list-none underline decoration-transparent underline-offset-[3px] transition-colors duration-200 hover:decoration-inherit"
|
||||
data-heading-link={
|
||||
section.subpostId === currentPostId
|
||||
? 'top'
|
||||
: `${section.subpostId}-top`
|
||||
}
|
||||
>
|
||||
{section.title}
|
||||
</a>
|
||||
</li>
|
||||
{section.headings.map((heading) => (
|
||||
<li
|
||||
class={cn(
|
||||
'text-xs',
|
||||
getHeadingMargin(heading.depth),
|
||||
section.subpostId === currentPostId
|
||||
? 'text-foreground/60'
|
||||
: 'text-foreground/30',
|
||||
)}
|
||||
>
|
||||
<a
|
||||
href={
|
||||
section.subpostId === currentPostId
|
||||
? `#${heading.slug}`
|
||||
: `/blog/${section.subpostId}#${heading.slug}`
|
||||
}
|
||||
class="marker:text-foreground/30 hover:text-foreground/60 list-none underline decoration-transparent underline-offset-[3px] transition-colors duration-200 hover:decoration-inherit"
|
||||
data-heading-link={
|
||||
section.subpostId === currentPostId
|
||||
? heading.slug
|
||||
: `${section.subpostId}-${heading.slug}`
|
||||
}
|
||||
>
|
||||
{heading.text}
|
||||
</a>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
<script>
|
||||
const HEADER_OFFSET = 150
|
||||
|
||||
class TOCState {
|
||||
links: NodeListOf<Element> = document.querySelectorAll(
|
||||
'[data-heading-link]',
|
||||
)
|
||||
activeIds: string[] = []
|
||||
headings: HTMLElement[] = []
|
||||
regions: { id: string; start: number; end: number }[] = []
|
||||
scrollArea: HTMLElement | null = null
|
||||
tocScrollArea: HTMLElement | null = null
|
||||
|
||||
reset() {
|
||||
this.links = document.querySelectorAll(
|
||||
'#toc-sidebar-container [data-heading-link]',
|
||||
)
|
||||
this.activeIds = []
|
||||
this.headings = []
|
||||
this.regions = []
|
||||
const tocContainer = document.getElementById('toc-sidebar-container')
|
||||
this.scrollArea =
|
||||
tocContainer?.querySelector('[data-radix-scroll-area-viewport]') || null
|
||||
this.tocScrollArea =
|
||||
tocContainer?.querySelector('[data-toc-scroll-area]') || null
|
||||
}
|
||||
}
|
||||
|
||||
const state = new TOCState()
|
||||
|
||||
class HeadingRegions {
|
||||
static build() {
|
||||
state.headings = Array.from(
|
||||
document.querySelectorAll<HTMLElement>(
|
||||
'.prose h2, .prose h3, .prose h4, .prose h5, .prose h6',
|
||||
),
|
||||
)
|
||||
|
||||
if (state.headings.length === 0) {
|
||||
state.regions = []
|
||||
return
|
||||
}
|
||||
|
||||
state.regions = state.headings.map((heading, index) => {
|
||||
const nextHeading = state.headings[index + 1]
|
||||
return {
|
||||
id: heading.id,
|
||||
start: heading.offsetTop,
|
||||
end: nextHeading ? nextHeading.offsetTop : document.body.scrollHeight,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
static getVisibleIds(): string[] {
|
||||
if (state.headings.length === 0) return []
|
||||
|
||||
const viewportTop = window.scrollY + HEADER_OFFSET
|
||||
const viewportBottom = window.scrollY + window.innerHeight
|
||||
const visibleIds = new Set<string>()
|
||||
|
||||
const isInViewport = (top: number, bottom: number) =>
|
||||
(top >= viewportTop && top <= viewportBottom) ||
|
||||
(bottom >= viewportTop && bottom <= viewportBottom) ||
|
||||
(top <= viewportTop && bottom >= viewportBottom)
|
||||
|
||||
state.headings.forEach((heading) => {
|
||||
const headingBottom = heading.offsetTop + heading.offsetHeight
|
||||
if (isInViewport(heading.offsetTop, headingBottom)) {
|
||||
visibleIds.add(heading.id)
|
||||
}
|
||||
})
|
||||
|
||||
state.regions.forEach((region) => {
|
||||
if (region.start <= viewportBottom && region.end >= viewportTop) {
|
||||
const heading = document.getElementById(region.id)
|
||||
if (heading) {
|
||||
const headingBottom = heading.offsetTop + heading.offsetHeight
|
||||
if (
|
||||
region.end > headingBottom &&
|
||||
(headingBottom < viewportBottom || viewportTop < region.end)
|
||||
) {
|
||||
visibleIds.add(region.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return Array.from(visibleIds)
|
||||
}
|
||||
}
|
||||
|
||||
class TOCScrollMask {
|
||||
static update() {
|
||||
if (!state.scrollArea || !state.tocScrollArea) return
|
||||
|
||||
const { scrollTop, scrollHeight, clientHeight } = state.scrollArea
|
||||
const threshold = 5
|
||||
const isAtTop = scrollTop <= threshold
|
||||
const isAtBottom = scrollTop >= scrollHeight - clientHeight - threshold
|
||||
|
||||
state.tocScrollArea.classList.toggle('mask-t-from-90%', !isAtTop)
|
||||
state.tocScrollArea.classList.toggle('mask-b-from-90%', !isAtBottom)
|
||||
}
|
||||
}
|
||||
|
||||
class TOCLinks {
|
||||
static update(headingIds: string[]) {
|
||||
state.links.forEach((link) => {
|
||||
link.classList.remove('text-foreground')
|
||||
})
|
||||
|
||||
headingIds.forEach((id) => {
|
||||
if (id) {
|
||||
const activeLink = document.querySelector(
|
||||
`#toc-sidebar-container [data-heading-link="${id}"]`,
|
||||
)
|
||||
if (activeLink) {
|
||||
activeLink.classList.add('text-foreground')
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.scrollToActive(headingIds)
|
||||
}
|
||||
|
||||
static scrollToActive(headingIds: string[]) {
|
||||
if (!state.scrollArea || !headingIds.length) return
|
||||
|
||||
const activeLink = document.querySelector(
|
||||
`#toc-sidebar-container [data-heading-link="${headingIds[0]}"]`,
|
||||
)
|
||||
if (!activeLink) return
|
||||
|
||||
const { top: areaTop, height: areaHeight } =
|
||||
state.scrollArea.getBoundingClientRect()
|
||||
const { top: linkTop, height: linkHeight } =
|
||||
activeLink.getBoundingClientRect()
|
||||
|
||||
const currentLinkTop = linkTop - areaTop + state.scrollArea.scrollTop
|
||||
const targetScroll = Math.max(
|
||||
0,
|
||||
Math.min(
|
||||
currentLinkTop - (areaHeight - linkHeight) / 2,
|
||||
state.scrollArea.scrollHeight - state.scrollArea.clientHeight,
|
||||
),
|
||||
)
|
||||
|
||||
if (Math.abs(targetScroll - state.scrollArea.scrollTop) > 5) {
|
||||
state.scrollArea.scrollTop = targetScroll
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TOCController {
|
||||
static handleScroll() {
|
||||
const newActiveIds = HeadingRegions.getVisibleIds()
|
||||
|
||||
if (JSON.stringify(newActiveIds) !== JSON.stringify(state.activeIds)) {
|
||||
state.activeIds = newActiveIds
|
||||
TOCLinks.update(state.activeIds)
|
||||
}
|
||||
}
|
||||
|
||||
static handleTOCScroll = () => TOCScrollMask.update()
|
||||
|
||||
static handleResize() {
|
||||
HeadingRegions.build()
|
||||
const newActiveIds = HeadingRegions.getVisibleIds()
|
||||
|
||||
if (JSON.stringify(newActiveIds) !== JSON.stringify(state.activeIds)) {
|
||||
state.activeIds = newActiveIds
|
||||
TOCLinks.update(state.activeIds)
|
||||
}
|
||||
|
||||
TOCScrollMask.update()
|
||||
}
|
||||
|
||||
static init() {
|
||||
state.reset()
|
||||
HeadingRegions.build()
|
||||
|
||||
if (state.headings.length === 0) {
|
||||
TOCLinks.update([])
|
||||
return
|
||||
}
|
||||
|
||||
this.handleScroll()
|
||||
setTimeout(TOCScrollMask.update, 100)
|
||||
|
||||
const options = { passive: true }
|
||||
window.addEventListener('scroll', this.handleScroll, options)
|
||||
window.addEventListener('resize', this.handleResize, options)
|
||||
state.scrollArea?.addEventListener(
|
||||
'scroll',
|
||||
this.handleTOCScroll,
|
||||
options,
|
||||
)
|
||||
}
|
||||
|
||||
static cleanup() {
|
||||
window.removeEventListener('scroll', this.handleScroll)
|
||||
window.removeEventListener('resize', this.handleResize)
|
||||
state.scrollArea?.removeEventListener('scroll', this.handleTOCScroll)
|
||||
|
||||
Object.assign(state, {
|
||||
activeIds: [],
|
||||
headings: [],
|
||||
regions: [],
|
||||
scrollArea: null,
|
||||
tocScrollArea: null,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('astro:page-load', () => TOCController.init())
|
||||
document.addEventListener('astro:after-swap', () => {
|
||||
TOCController.cleanup()
|
||||
TOCController.init()
|
||||
})
|
||||
document.addEventListener('astro:before-swap', () => TOCController.cleanup())
|
||||
</script>
|
||||
72
src/components/ThemeToggle.astro
Normal file
@@ -0,0 +1,72 @@
|
||||
---
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Icon } from 'astro-icon/components'
|
||||
---
|
||||
|
||||
<Button
|
||||
id="theme-toggle"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
title="Toggle theme"
|
||||
className="-my-2 -me-2 size-8"
|
||||
>
|
||||
<Icon name="lucide:sun" class="size-4 dark:hidden" />
|
||||
<Icon name="lucide:moon" class="absolute hidden size-4 dark:block" />
|
||||
<span class="sr-only">Toggle theme</span>
|
||||
</Button>
|
||||
|
||||
<script is:inline data-astro-rerun>
|
||||
(() => {
|
||||
const theme = (() => {
|
||||
const stored = localStorage?.getItem('theme') ?? ''
|
||||
if (['dark', 'light'].includes(stored)) return stored
|
||||
return window.matchMedia('(prefers-color-scheme: dark)').matches
|
||||
? 'dark'
|
||||
: 'light'
|
||||
})()
|
||||
|
||||
document.documentElement.setAttribute('data-theme', theme)
|
||||
window.localStorage.setItem('theme', theme)
|
||||
})()
|
||||
</script>
|
||||
|
||||
<script>
|
||||
function handleToggleClick() {
|
||||
const element = document.documentElement
|
||||
const currentTheme = element.getAttribute('data-theme')
|
||||
const newTheme = currentTheme === 'dark' ? 'light' : 'dark'
|
||||
|
||||
element.classList.add('[&_*]:transition-none')
|
||||
element.setAttribute('data-theme', newTheme)
|
||||
window.getComputedStyle(element).getPropertyValue('opacity')
|
||||
|
||||
requestAnimationFrame(() => {
|
||||
element.classList.remove('[&_*]:transition-none')
|
||||
})
|
||||
|
||||
localStorage.setItem('theme', newTheme)
|
||||
}
|
||||
|
||||
function initThemeToggle() {
|
||||
document
|
||||
.getElementById('theme-toggle')
|
||||
?.addEventListener('click', handleToggleClick)
|
||||
}
|
||||
|
||||
initThemeToggle()
|
||||
|
||||
document.addEventListener('astro:after-swap', () => {
|
||||
const storedTheme = localStorage.getItem('theme') || 'light'
|
||||
const element = document.documentElement
|
||||
|
||||
element.classList.add('[&_*]:transition-none')
|
||||
window.getComputedStyle(element).getPropertyValue('opacity')
|
||||
element.setAttribute('data-theme', storedTheme)
|
||||
|
||||
requestAnimationFrame(() => {
|
||||
element.classList.remove('[&_*]:transition-none')
|
||||
})
|
||||
|
||||
initThemeToggle()
|
||||
})
|
||||
</script>
|
||||
74
src/components/ui/avatar.tsx
Normal file
@@ -0,0 +1,74 @@
|
||||
import * as React from 'react'
|
||||
import { Avatar as AvatarPrimitive } from 'radix-ui'
|
||||
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
function Avatar({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AvatarPrimitive.Root>) {
|
||||
return (
|
||||
<AvatarPrimitive.Root
|
||||
data-slot="avatar"
|
||||
className={cn(
|
||||
'relative flex size-8 shrink-0 overflow-hidden rounded-full',
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function AvatarImage({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AvatarPrimitive.Image>) {
|
||||
return (
|
||||
<AvatarPrimitive.Image
|
||||
data-slot="avatar-image"
|
||||
className={cn('aspect-square size-full', className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function AvatarFallback({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AvatarPrimitive.Fallback>) {
|
||||
return (
|
||||
<AvatarPrimitive.Fallback
|
||||
data-slot="avatar-fallback"
|
||||
className={cn(
|
||||
'bg-muted flex size-full items-center justify-center rounded-full',
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const AvatarComponent: React.FC<AvatarComponentProps> = ({
|
||||
src,
|
||||
alt,
|
||||
fallback,
|
||||
className,
|
||||
}) => {
|
||||
return (
|
||||
<Avatar className={className}>
|
||||
<AvatarImage src={src} alt={alt} />
|
||||
<AvatarFallback>{fallback}</AvatarFallback>
|
||||
</Avatar>
|
||||
)
|
||||
}
|
||||
|
||||
export default AvatarComponent
|
||||
|
||||
interface AvatarComponentProps {
|
||||
src?: string
|
||||
alt?: string
|
||||
fallback: string
|
||||
className?: string
|
||||
}
|
||||
|
||||
export { Avatar, AvatarImage, AvatarFallback }
|
||||
46
src/components/ui/badge.tsx
Normal file
@@ -0,0 +1,46 @@
|
||||
import * as React from 'react'
|
||||
import { Slot as SlotPrimitive } from 'radix-ui'
|
||||
import { cva, type VariantProps } from 'class-variance-authority'
|
||||
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
const badgeVariants = cva(
|
||||
'inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden',
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default:
|
||||
'border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90',
|
||||
muted:
|
||||
'border-transparent bg-muted text-foreground [a&]:hover:bg-muted/90',
|
||||
destructive:
|
||||
'border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/70',
|
||||
outline:
|
||||
'text-foreground [a&]:hover:bg-muted [a&]:hover:text-foreground',
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: 'default',
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
function Badge({
|
||||
className,
|
||||
variant,
|
||||
asChild = false,
|
||||
...props
|
||||
}: React.ComponentProps<'span'> &
|
||||
VariantProps<typeof badgeVariants> & { asChild?: boolean }) {
|
||||
const Comp = asChild ? SlotPrimitive.Root : 'span'
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="badge"
|
||||
className={cn(badgeVariants({ variant }), className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Badge, badgeVariants }
|
||||
108
src/components/ui/breadcrumb.tsx
Normal file
@@ -0,0 +1,108 @@
|
||||
import * as React from 'react'
|
||||
import { Slot as SlotPrimitive } from 'radix-ui'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { ChevronRight, MoreHorizontal } from 'lucide-react'
|
||||
|
||||
function Breadcrumb({ ...props }: React.ComponentProps<'nav'>) {
|
||||
return <nav aria-label="breadcrumb" data-slot="breadcrumb" {...props} />
|
||||
}
|
||||
|
||||
function BreadcrumbList({ className, ...props }: React.ComponentProps<'ol'>) {
|
||||
return (
|
||||
<ol
|
||||
data-slot="breadcrumb-list"
|
||||
className={cn(
|
||||
'text-muted-foreground flex flex-wrap items-center gap-1.5 text-sm break-words sm:gap-2.5',
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function BreadcrumbItem({ className, ...props }: React.ComponentProps<'li'>) {
|
||||
return (
|
||||
<li
|
||||
data-slot="breadcrumb-item"
|
||||
className={cn('inline-flex items-center gap-1.5', className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function BreadcrumbLink({
|
||||
asChild,
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<'a'> & {
|
||||
asChild?: boolean
|
||||
}) {
|
||||
const Comp = asChild ? SlotPrimitive.Root : 'a'
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="breadcrumb-link"
|
||||
className={cn('hover:text-foreground transition-colors', className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function BreadcrumbPage({ className, ...props }: React.ComponentProps<'span'>) {
|
||||
return (
|
||||
<span
|
||||
data-slot="breadcrumb-page"
|
||||
role="link"
|
||||
aria-disabled="true"
|
||||
aria-current="page"
|
||||
className={cn('text-foreground font-normal', className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function BreadcrumbSeparator({
|
||||
children,
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<'li'>) {
|
||||
return (
|
||||
<li
|
||||
data-slot="breadcrumb-separator"
|
||||
role="presentation"
|
||||
aria-hidden="true"
|
||||
className={cn('[&>svg]:size-3.5', className)}
|
||||
{...props}
|
||||
>
|
||||
{children ?? <ChevronRight />}
|
||||
</li>
|
||||
)
|
||||
}
|
||||
|
||||
function BreadcrumbEllipsis({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<'span'>) {
|
||||
return (
|
||||
<span
|
||||
data-slot="breadcrumb-ellipsis"
|
||||
role="presentation"
|
||||
aria-hidden="true"
|
||||
className={cn('flex size-9 items-center justify-center', className)}
|
||||
{...props}
|
||||
>
|
||||
<MoreHorizontal className="size-4" />
|
||||
<span className="sr-only">More</span>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Breadcrumb,
|
||||
BreadcrumbList,
|
||||
BreadcrumbItem,
|
||||
BreadcrumbLink,
|
||||
BreadcrumbPage,
|
||||
BreadcrumbSeparator,
|
||||
BreadcrumbEllipsis,
|
||||
}
|
||||
58
src/components/ui/button.tsx
Normal file
@@ -0,0 +1,58 @@
|
||||
import * as React from 'react'
|
||||
import { Slot as SlotPrimitive } from 'radix-ui'
|
||||
import { cva, type VariantProps } from 'class-variance-authority'
|
||||
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
const buttonVariants = cva(
|
||||
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: 'bg-primary text-primary-foreground hover:bg-primary/90',
|
||||
destructive:
|
||||
'bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60',
|
||||
outline:
|
||||
'border bg-background hover:bg-muted hover:text-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50',
|
||||
muted:
|
||||
'bg-muted text-foreground hover:bg-muted/80',
|
||||
ghost:
|
||||
'hover:bg-muted hover:text-foreground dark:hover:bg-muted/50',
|
||||
link: 'text-primary underline-offset-4 hover:underline',
|
||||
},
|
||||
size: {
|
||||
default: 'h-9 px-4 py-2 has-[>svg]:px-3',
|
||||
sm: 'h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5',
|
||||
lg: 'h-10 rounded-md px-6 has-[>svg]:px-4',
|
||||
icon: 'size-9',
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: 'default',
|
||||
size: 'default',
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
function Button({
|
||||
className,
|
||||
variant,
|
||||
size,
|
||||
asChild = false,
|
||||
...props
|
||||
}: React.ComponentProps<'button'> &
|
||||
VariantProps<typeof buttonVariants> & {
|
||||
asChild?: boolean
|
||||
}) {
|
||||
const Comp = asChild ? SlotPrimitive.Root : 'button'
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="button"
|
||||
className={cn(buttonVariants({ variant, size, className }))}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Button, buttonVariants }
|
||||
195
src/components/ui/pagination.tsx
Normal file
@@ -0,0 +1,195 @@
|
||||
import * as React from 'react'
|
||||
import {
|
||||
ChevronLeftIcon,
|
||||
ChevronRightIcon,
|
||||
MoreHorizontalIcon,
|
||||
} from 'lucide-react'
|
||||
|
||||
import { cn } from '@/lib/utils'
|
||||
import { Button, buttonVariants } from '@/components/ui/button'
|
||||
|
||||
function Pagination({ className, ...props }: React.ComponentProps<'nav'>) {
|
||||
return (
|
||||
<nav
|
||||
role="navigation"
|
||||
aria-label="pagination"
|
||||
data-slot="pagination"
|
||||
className={cn('mx-auto flex w-full justify-center', className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function PaginationContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<'ul'>) {
|
||||
return (
|
||||
<ul
|
||||
data-slot="pagination-content"
|
||||
className={cn('flex flex-row items-center gap-1', className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function PaginationItem({ ...props }: React.ComponentProps<'li'>) {
|
||||
return <li data-slot="pagination-item" {...props} />
|
||||
}
|
||||
|
||||
type PaginationLinkProps = {
|
||||
isActive?: boolean
|
||||
isDisabled?: boolean
|
||||
} & Pick<React.ComponentProps<typeof Button>, 'size'> &
|
||||
React.ComponentProps<'a'>
|
||||
|
||||
function PaginationLink({
|
||||
className,
|
||||
isActive,
|
||||
isDisabled,
|
||||
size = 'icon',
|
||||
...props
|
||||
}: PaginationLinkProps) {
|
||||
return (
|
||||
<a
|
||||
aria-current={isActive ? 'page' : undefined}
|
||||
data-slot="pagination-link"
|
||||
data-active={isActive}
|
||||
data-disabled={isDisabled}
|
||||
className={cn(
|
||||
buttonVariants({
|
||||
variant: isActive ? 'outline' : 'ghost',
|
||||
size,
|
||||
}),
|
||||
isDisabled && 'pointer-events-none opacity-50',
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function PaginationPrevious({
|
||||
className,
|
||||
isDisabled,
|
||||
...props
|
||||
}: React.ComponentProps<typeof PaginationLink>) {
|
||||
return (
|
||||
<PaginationLink
|
||||
aria-label="Go to previous page"
|
||||
size="default"
|
||||
className={cn('gap-1 px-2.5 sm:pl-2.5', className)}
|
||||
isDisabled={isDisabled}
|
||||
{...props}
|
||||
>
|
||||
<ChevronLeftIcon />
|
||||
<span className="hidden sm:block">Previous</span>
|
||||
</PaginationLink>
|
||||
)
|
||||
}
|
||||
|
||||
function PaginationNext({
|
||||
className,
|
||||
isDisabled,
|
||||
...props
|
||||
}: React.ComponentProps<typeof PaginationLink>) {
|
||||
return (
|
||||
<PaginationLink
|
||||
aria-label="Go to next page"
|
||||
size="default"
|
||||
className={cn('gap-1 px-2.5 sm:pr-2.5', className)}
|
||||
isDisabled={isDisabled}
|
||||
{...props}
|
||||
>
|
||||
<span className="hidden sm:block">Next</span>
|
||||
<ChevronRightIcon />
|
||||
</PaginationLink>
|
||||
)
|
||||
}
|
||||
|
||||
function PaginationEllipsis({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<'span'>) {
|
||||
return (
|
||||
<span
|
||||
aria-hidden
|
||||
data-slot="pagination-ellipsis"
|
||||
className={cn('flex size-9 items-center justify-center', className)}
|
||||
{...props}
|
||||
>
|
||||
<MoreHorizontalIcon className="size-4" />
|
||||
<span className="sr-only">More pages</span>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
const PaginationComponent: React.FC<PaginationProps> = ({
|
||||
currentPage,
|
||||
totalPages,
|
||||
baseUrl,
|
||||
}) => {
|
||||
const pages = Array.from({ length: totalPages }, (_, i) => i + 1)
|
||||
|
||||
const getPageUrl = (page: number) => {
|
||||
if (page === 1) return baseUrl
|
||||
return `${baseUrl}${page}`
|
||||
}
|
||||
|
||||
return (
|
||||
<Pagination>
|
||||
<PaginationContent className="flex-wrap">
|
||||
<PaginationItem>
|
||||
<PaginationPrevious
|
||||
href={currentPage > 1 ? getPageUrl(currentPage - 1) : undefined}
|
||||
isDisabled={currentPage === 1}
|
||||
/>
|
||||
</PaginationItem>
|
||||
|
||||
{pages.map((page) => (
|
||||
<PaginationItem key={page}>
|
||||
<PaginationLink
|
||||
href={getPageUrl(page)}
|
||||
isActive={page === currentPage}
|
||||
>
|
||||
{page}
|
||||
</PaginationLink>
|
||||
</PaginationItem>
|
||||
))}
|
||||
|
||||
{totalPages > 5 && (
|
||||
<PaginationItem>
|
||||
<PaginationEllipsis />
|
||||
</PaginationItem>
|
||||
)}
|
||||
|
||||
<PaginationItem>
|
||||
<PaginationNext
|
||||
href={
|
||||
currentPage < totalPages ? getPageUrl(currentPage + 1) : undefined
|
||||
}
|
||||
isDisabled={currentPage === totalPages}
|
||||
/>
|
||||
</PaginationItem>
|
||||
</PaginationContent>
|
||||
</Pagination>
|
||||
)
|
||||
}
|
||||
|
||||
interface PaginationProps {
|
||||
currentPage: number
|
||||
totalPages: number
|
||||
baseUrl: string
|
||||
}
|
||||
|
||||
export default PaginationComponent
|
||||
|
||||
export {
|
||||
Pagination,
|
||||
PaginationContent,
|
||||
PaginationLink,
|
||||
PaginationItem,
|
||||
PaginationPrevious,
|
||||
PaginationNext,
|
||||
PaginationEllipsis,
|
||||
}
|
||||
56
src/components/ui/scroll-area.tsx
Normal file
@@ -0,0 +1,56 @@
|
||||
import * as React from 'react'
|
||||
import { ScrollArea as ScrollAreaPrimitive } from 'radix-ui'
|
||||
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
function ScrollArea({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ScrollAreaPrimitive.Root>) {
|
||||
return (
|
||||
<ScrollAreaPrimitive.Root
|
||||
data-slot="scroll-area"
|
||||
className={cn('relative', className)}
|
||||
{...props}
|
||||
>
|
||||
<ScrollAreaPrimitive.Viewport
|
||||
data-slot="scroll-area-viewport"
|
||||
className="ring-ring/10 dark:ring-ring/20 dark:outline-ring/40 outline-ring/50 size-full rounded-[inherit] transition-[color,box-shadow] focus-visible:ring-4 focus-visible:outline-1"
|
||||
>
|
||||
{children}
|
||||
</ScrollAreaPrimitive.Viewport>
|
||||
<ScrollBar />
|
||||
<ScrollAreaPrimitive.Corner />
|
||||
</ScrollAreaPrimitive.Root>
|
||||
)
|
||||
}
|
||||
|
||||
function ScrollBar({
|
||||
className,
|
||||
orientation = 'vertical',
|
||||
...props
|
||||
}: React.ComponentProps<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>) {
|
||||
return (
|
||||
<ScrollAreaPrimitive.ScrollAreaScrollbar
|
||||
data-slot="scroll-area-scrollbar"
|
||||
orientation={orientation}
|
||||
className={cn(
|
||||
'flex touch-none p-px transition-colors select-none',
|
||||
orientation === 'vertical' &&
|
||||
'h-full w-2.5 border-l border-l-transparent',
|
||||
orientation === 'horizontal' &&
|
||||
'h-2.5 flex-col border-t border-t-transparent',
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ScrollAreaPrimitive.ScrollAreaThumb
|
||||
data-slot="scroll-area-thumb"
|
||||
className="bg-border relative flex-1 rounded-full"
|
||||
/>
|
||||
</ScrollAreaPrimitive.ScrollAreaScrollbar>
|
||||
)
|
||||
}
|
||||
|
||||
export { ScrollArea, ScrollBar }
|
||||
26
src/components/ui/separator.tsx
Normal file
@@ -0,0 +1,26 @@
|
||||
import * as React from 'react'
|
||||
import { Separator as SeparatorPrimitive } from 'radix-ui'
|
||||
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
function Separator({
|
||||
className,
|
||||
orientation = 'horizontal',
|
||||
decorative = true,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SeparatorPrimitive.Root>) {
|
||||
return (
|
||||
<SeparatorPrimitive.Root
|
||||
data-slot="separator-root"
|
||||
decorative={decorative}
|
||||
orientation={orientation}
|
||||
className={cn(
|
||||
'bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px',
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Separator }
|
||||
55
src/consts.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import type { IconMap, SocialLink, Site } from '@/types'
|
||||
|
||||
export const SITE: Site = {
|
||||
title: 'astro-erudite',
|
||||
description:
|
||||
'astro-erudite is a opinionated, unstyled blogging template—built with Astro, Tailwind, and shadcn/ui.',
|
||||
href: 'https://astro-erudite.vercel.app',
|
||||
author: 'jktrn',
|
||||
locale: 'en-US',
|
||||
featuredPostCount: 2,
|
||||
postsPerPage: 3,
|
||||
}
|
||||
|
||||
export const NAV_LINKS: SocialLink[] = [
|
||||
{
|
||||
href: '/blog',
|
||||
label: 'blog',
|
||||
},
|
||||
{
|
||||
href: '/authors',
|
||||
label: 'authors',
|
||||
},
|
||||
{
|
||||
href: '/about',
|
||||
label: 'about',
|
||||
},
|
||||
]
|
||||
|
||||
export const SOCIAL_LINKS: SocialLink[] = [
|
||||
{
|
||||
href: 'https://github.com/jktrn',
|
||||
label: 'GitHub',
|
||||
},
|
||||
{
|
||||
href: 'https://twitter.com/enscry',
|
||||
label: 'Twitter',
|
||||
},
|
||||
{
|
||||
href: 'mailto:jason@enscribe.dev',
|
||||
label: 'Email',
|
||||
},
|
||||
{
|
||||
href: '/rss.xml',
|
||||
label: 'RSS',
|
||||
},
|
||||
]
|
||||
|
||||
export const ICON_MAP: IconMap = {
|
||||
Website: 'lucide:globe',
|
||||
GitHub: 'lucide:github',
|
||||
LinkedIn: 'lucide:linkedin',
|
||||
Twitter: 'lucide:twitter',
|
||||
Email: 'lucide:mail',
|
||||
RSS: 'lucide:rss',
|
||||
}
|
||||
49
src/content.config.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { glob } from 'astro/loaders'
|
||||
import { defineCollection, z } from 'astro:content'
|
||||
|
||||
const blog = defineCollection({
|
||||
loader: glob({ pattern: '**/*.{md,mdx}', base: './src/content/blog' }),
|
||||
schema: ({ image }) =>
|
||||
z.object({
|
||||
title: z.string(),
|
||||
description: z.string(),
|
||||
date: z.coerce.date(),
|
||||
order: z.number().optional(),
|
||||
image: image().optional(),
|
||||
tags: z.array(z.string()).optional(),
|
||||
authors: z.array(z.string()).optional(),
|
||||
draft: z.boolean().optional(),
|
||||
}),
|
||||
})
|
||||
|
||||
const authors = defineCollection({
|
||||
loader: glob({ pattern: '**/*.{md,mdx}', base: './src/content/authors' }),
|
||||
schema: z.object({
|
||||
name: z.string(),
|
||||
pronouns: z.string().optional(),
|
||||
avatar: z.string().url().or(z.string().startsWith('/')),
|
||||
bio: z.string().optional(),
|
||||
mail: z.string().email().optional(),
|
||||
website: z.string().url().optional(),
|
||||
twitter: z.string().url().optional(),
|
||||
github: z.string().url().optional(),
|
||||
linkedin: z.string().url().optional(),
|
||||
discord: z.string().url().optional(),
|
||||
}),
|
||||
})
|
||||
|
||||
const projects = defineCollection({
|
||||
loader: glob({ pattern: '**/*.{md,mdx}', base: './src/content/projects' }),
|
||||
schema: ({ image }) =>
|
||||
z.object({
|
||||
name: z.string(),
|
||||
description: z.string(),
|
||||
tags: z.array(z.string()),
|
||||
image: image(),
|
||||
link: z.string().url(),
|
||||
startDate: z.coerce.date().optional(),
|
||||
endDate: z.coerce.date().optional(),
|
||||
}),
|
||||
})
|
||||
|
||||
export const collections = { blog, authors, projects }
|
||||
10
src/content/authors/enscribe.md
Normal file
@@ -0,0 +1,10 @@
|
||||
---
|
||||
name: 'enscribe'
|
||||
pronouns: 'he/him'
|
||||
avatar: 'https://gravatar.com/avatar/9bfdc4ec972793cf05cb91efce5f4aaaec2a0da1bf4ec34dad0913f1d845faf6.webp?size=256'
|
||||
bio: 'd(-_-)b'
|
||||
website: 'https://enscribe.dev'
|
||||
twitter: 'https://twitter.com/enscry'
|
||||
github: 'https://github.com/jktrn'
|
||||
mail: 'jason@enscribe.dev'
|
||||
---
|
||||
BIN
src/content/blog/2023-post/banner.png
Normal file
|
After Width: | Height: | Size: 93 KiB |
10
src/content/blog/2023-post/index.mdx
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
---
|
||||
title: '2023 Post'
|
||||
description: 'This is a dummy post written in the year 2023.'
|
||||
date: 2023-06-01
|
||||
tags: ['v1.0.0']
|
||||
image: './banner.png'
|
||||
authors: ['enscribe']
|
||||
---
|
||||
|
||||
This is a dummy post written in the year 2023.
|
||||
BIN
src/content/blog/2024-post/banner.png
Normal file
|
After Width: | Height: | Size: 93 KiB |
154
src/content/blog/2024-post/index.mdx
vendored
Normal file
@@ -0,0 +1,154 @@
|
||||
---
|
||||
title: '2024 Post'
|
||||
description: 'This is a dummy post written in the year 2024 (with multiple authors).'
|
||||
date: 2024-06-01
|
||||
tags: ['v1.0.0']
|
||||
image: './banner.png'
|
||||
authors: ['enscribe', 'jktrn']
|
||||
---
|
||||
|
||||
This is a dummy post written in the year 2024! Here is a long blog post with heavily nested headers, which can be used to test the table of contents:
|
||||
|
||||
## Test 2
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
### Test 3
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
#### Test 4
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
#### Test 4
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
### Test 3
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
#### Test 4
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
##### Test 5
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
### Test 3
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
### Test 3
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
#### Test 4
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
#### Test 4
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
### Test 3
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
#### Test 4
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
##### Test 5
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
### Test 3
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
### Test 3
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
#### Test 4
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
#### Test 4
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
### Test 3
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
#### Test 4
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
##### Test 5
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
### Test 3
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
### Test 3
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
#### Test 4
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
#### Test 4
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
### Test 3
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
#### Test 4
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
##### Test 5
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
###### Test 6
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
### Test 3
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
#### Test 4
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
#### Test 4
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
### Test 3
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
#### Test 4
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
##### Test 5
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
|
||||
### Test 3
|
||||
|
||||
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
|
||||
BIN
src/content/blog/callouts-component/banner.png
Normal file
|
After Width: | Height: | Size: 92 KiB |
442
src/content/blog/callouts-component/index.mdx
vendored
Normal file
@@ -0,0 +1,442 @@
|
||||
---
|
||||
title: 'v1.5.0: “A Callout Component for Nerds”'
|
||||
description: 'A quick update introduces our first content-based component: the callout!'
|
||||
date: 2025-04-24
|
||||
tags: ['v1.5.0']
|
||||
image: './banner.png'
|
||||
authors: ['enscribe']
|
||||
---
|
||||
|
||||
import Callout from '@/components/Callout.astro'
|
||||
import { Icon } from 'astro-icon/components'
|
||||
|
||||
## Our (hesitantly) first content-based component
|
||||
|
||||
This new version of astro-erudite, v1.5.0, introduces our first content-based component: the callout! I was a bit hesitant about adding this component because, frankly, the entire philosophy behind this project was to be as minimalistic as possible—I wanted to simply provide boilerplate to remove the "busy work" factor that often takes away from the writing process.
|
||||
|
||||
However, just based on some blog posts I've seen that use this template, I felt like there would be a universal desire just to have this component around in the case where it'd be needed. The primary inspiration came when user [@rezaarezvan](https://github.com/rezaarezvan) sent in a PR to add their site, [rezaarezvan.com](https://rezaarezvan.com), to the examples section in the README. They had years upon years of accumulated notes and resources on their site, most of which were in the form of LaTeX-style academic content that requires "blocks" for things like definitions, theorems, and proofs. I sent in an encouraging reply to the PR and then started building the component:
|
||||
|
||||
> [[@jktrn]](https://github.com/jktrn/astro-erudite/pull/29#issuecomment-2814894034) your blog posts are literally insane btw @rezaarezvan how have you written multiple textbooks worth of educational resources???
|
||||
>
|
||||
> i think i might add latex-style theorem/lemma/corollary/def/proof/eg/ex/remark blocks to astro-erudite so i can accommodate for these academia-style blogs, like e.g. for exercises it'd just be a component with an expandable section to hide the answer
|
||||
|
||||
### How does it work?
|
||||
|
||||
I've added a simple `Callout.astro` to `src/components` that now comes shipped with the template. It's a very easy-to-read component that has an insanely long configuration scheme for all of the different types of callouts that I've added. Fundamentally, it follows the same paradigm as [shadcn/ui](https://ui.shadcn.com) which uses [class-variance-authority](https://cva.style/docs) to create different "variants" on top of a base styling scheme:
|
||||
|
||||
```astro title="src/components/Callout.astro" collapse={12-126} {8-10,131}
|
||||
---
|
||||
import { cn } from '@/lib/utils'
|
||||
import { Icon } from 'astro-icon/components'
|
||||
import { cva, type VariantProps } from 'class-variance-authority'
|
||||
|
||||
const calloutConfig = {
|
||||
note: {
|
||||
style: 'border-blue-500 dark:bg-blue-950/5',
|
||||
textColor: 'text-blue-700 dark:text-blue-300',
|
||||
icon: 'lucide:info',
|
||||
},
|
||||
tip: {
|
||||
style: 'border-green-500 dark:bg-green-950/5',
|
||||
textColor: 'text-green-700 dark:text-green-300',
|
||||
icon: 'lucide:lightbulb',
|
||||
},
|
||||
warning: {
|
||||
style: 'border-amber-500 dark:bg-amber-950/5',
|
||||
textColor: 'text-amber-700 dark:text-amber-300',
|
||||
icon: 'lucide:alert-triangle',
|
||||
},
|
||||
danger: {
|
||||
style: 'border-red-500 dark:bg-red-950/5',
|
||||
textColor: 'text-red-700 dark:text-red-300',
|
||||
icon: 'lucide:shield-alert',
|
||||
},
|
||||
important: {
|
||||
style: 'border-purple-500 dark:bg-purple-950/5',
|
||||
textColor: 'text-purple-700 dark:text-purple-300',
|
||||
icon: 'lucide:message-square-warning',
|
||||
},
|
||||
definition: {
|
||||
style: 'border-purple-500 dark:bg-purple-950/5',
|
||||
textColor: 'text-purple-700 dark:text-purple-300',
|
||||
icon: 'lucide:book-open',
|
||||
},
|
||||
theorem: {
|
||||
style: 'border-teal-500 dark:bg-teal-950/5',
|
||||
textColor: 'text-teal-700 dark:text-teal-300',
|
||||
icon: 'lucide:check-circle',
|
||||
},
|
||||
lemma: {
|
||||
style: 'border-sky-400 dark:bg-sky-950/5',
|
||||
textColor: 'text-sky-700 dark:text-sky-300',
|
||||
icon: 'lucide:puzzle',
|
||||
},
|
||||
proof: {
|
||||
style: 'border-gray-500 dark:bg-gray-950/5',
|
||||
textColor: 'text-gray-700 dark:text-gray-300',
|
||||
icon: 'lucide:check-square',
|
||||
},
|
||||
corollary: {
|
||||
style: 'border-cyan-500 dark:bg-cyan-950/5',
|
||||
textColor: 'text-cyan-700 dark:text-cyan-300',
|
||||
icon: 'lucide:git-branch',
|
||||
},
|
||||
proposition: {
|
||||
style: 'border-slate-500 dark:bg-slate-950/5',
|
||||
textColor: 'text-slate-700 dark:text-slate-300',
|
||||
icon: 'lucide:file-text',
|
||||
},
|
||||
axiom: {
|
||||
style: 'border-violet-600 dark:bg-violet-950/5',
|
||||
textColor: 'text-violet-700 dark:text-violet-300',
|
||||
icon: 'lucide:anchor',
|
||||
},
|
||||
conjecture: {
|
||||
style: 'border-pink-500 dark:bg-pink-950/5',
|
||||
textColor: 'text-pink-700 dark:text-pink-300',
|
||||
icon: 'lucide:help-circle',
|
||||
},
|
||||
notation: {
|
||||
style: 'border-slate-400 dark:bg-slate-950/5',
|
||||
textColor: 'text-slate-700 dark:text-slate-300',
|
||||
icon: 'lucide:pen-tool',
|
||||
},
|
||||
remark: {
|
||||
style: 'border-gray-400 dark:bg-gray-950/5',
|
||||
textColor: 'text-gray-700 dark:text-gray-300',
|
||||
icon: 'lucide:message-circle',
|
||||
},
|
||||
intuition: {
|
||||
style: 'border-yellow-500 dark:bg-yellow-950/5',
|
||||
textColor: 'text-yellow-700 dark:text-yellow-300',
|
||||
icon: 'lucide:lightbulb',
|
||||
},
|
||||
recall: {
|
||||
style: 'border-blue-300 dark:bg-blue-950/5',
|
||||
textColor: 'text-blue-600 dark:text-blue-300',
|
||||
icon: 'lucide:rotate-ccw',
|
||||
},
|
||||
explanation: {
|
||||
style: 'border-lime-500 dark:bg-lime-950/5',
|
||||
textColor: 'text-lime-700 dark:text-lime-300',
|
||||
icon: 'lucide:help-circle',
|
||||
},
|
||||
example: {
|
||||
style: 'border-emerald-500 dark:bg-emerald-950/5',
|
||||
textColor: 'text-emerald-700 dark:text-emerald-300',
|
||||
icon: 'lucide:code',
|
||||
},
|
||||
exercise: {
|
||||
style: 'border-indigo-500 dark:bg-indigo-950/5',
|
||||
textColor: 'text-indigo-700 dark:text-indigo-300',
|
||||
icon: 'lucide:dumbbell',
|
||||
},
|
||||
problem: {
|
||||
style: 'border-orange-600 dark:bg-orange-950/5',
|
||||
textColor: 'text-orange-700 dark:text-orange-300',
|
||||
icon: 'lucide:alert-circle',
|
||||
},
|
||||
answer: {
|
||||
style: 'border-teal-500 dark:bg-teal-950/5',
|
||||
textColor: 'text-teal-700 dark:text-teal-300',
|
||||
icon: 'lucide:check',
|
||||
},
|
||||
solution: {
|
||||
style: 'border-emerald-600 dark:bg-emerald-950/5',
|
||||
textColor: 'text-emerald-700 dark:text-emerald-300',
|
||||
icon: 'lucide:check-circle-2',
|
||||
},
|
||||
summary: {
|
||||
style: 'border-sky-500 dark:bg-sky-950/5',
|
||||
textColor: 'text-sky-700 dark:text-sky-300',
|
||||
icon: 'lucide:list',
|
||||
},
|
||||
} as const
|
||||
|
||||
const capitalize = (str: string) => str.charAt(0).toUpperCase() + str.slice(1)
|
||||
|
||||
const calloutVariants = cva('relative px-4 py-3 my-6 border-l-4 text-sm', {
|
||||
variants: {
|
||||
variant: Object.fromEntries(
|
||||
Object.entries(calloutConfig).map(([key, config]) => [key, config.style]),
|
||||
),
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: 'note',
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
As such, if you feel like there's any variant that you're missing, it's insanely trivial to add it yourself. It's less trivial, however, to figure out what colors to use since I've essentially taken up every good Tailwind color for these!
|
||||
|
||||
### How do I use these?
|
||||
|
||||
Within any `src/content/blog/**/*.mdx` file, you can now use the `Callout` component by importing it like so underneath your frontmatter:
|
||||
|
||||
```mdx title="src/content/blog/callouts-component/index.mdx" add={10}
|
||||
---
|
||||
title: 'v1.5.0: “A Callout Component for Nerds”'
|
||||
description: 'A quick update introduces our first content-based component: the callout!'
|
||||
date: 2025-04-24
|
||||
tags: ['v1.5.0']
|
||||
image: './1200x630.png'
|
||||
authors: ['enscribe']
|
||||
---
|
||||
|
||||
import Callout from '@/components/Callout.astro'
|
||||
```
|
||||
|
||||
Then, you can use the component like so. This is just an example but you should actually read the text since it's relevant to the article:
|
||||
|
||||
````mdx showLineNumbers=false collapse={3-11}
|
||||
<Callout title="About Github-flavored alerts" variant="important">
|
||||
I know that Github typically uses the following syntax for "alerts" (which is what they call these callouts, you can see their documentation [here](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts)):
|
||||
```md showLineNumbers=false
|
||||
> [!NOTE]
|
||||
> Useful information that users should know, even when skimming content.
|
||||
```
|
||||
The above syntax is supposed to render like this:
|
||||
<Callout>
|
||||
Useful information that users should know, even when skimming content.
|
||||
</Callout>
|
||||
I believe they do this so they can keep you within the Markdown-like syntax system. However, since this is MDX, I thought we'd be better off just using the component paradigm since it's a bit impractical to make a rehype plugin that can parse this form of syntax (also, solutions for this already exist, such as [lin-stephanie/rehype-callouts](https://github.com/lin-stephanie/rehype-callouts)). Additionally, I find it a pain to work with the `>{:md}` (the `<blockquote>{:html}` indicators for Markdown) syntax, as it makes it difficult to nest things such as code blocks within them in pure Markdown. We'll use components for now!
|
||||
</Callout>
|
||||
````
|
||||
|
||||
<Callout title="About Github-flavored alerts" variant="important">
|
||||
I know that Github typically uses the following syntax for "alerts" (which is what they call these callouts, you can see their documentation [here](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts)):
|
||||
```md showLineNumbers=false
|
||||
> [!NOTE]
|
||||
> Useful information that users should know, even when skimming content.
|
||||
```
|
||||
The above syntax is supposed to render like this:
|
||||
<Callout>
|
||||
Useful information that users should know, even when skimming content.
|
||||
</Callout>
|
||||
I believe they do this so they can keep you within the Markdown-like syntax system. However, since this is MDX, I thought we'd be better off just using the component paradigm since it's a bit impractical to make a rehype plugin that can parse this form of syntax (also, solutions for this already exist, such as [lin-stephanie/rehype-callouts](https://github.com/lin-stephanie/rehype-callouts)). Additionally, I find it a pain to work with the `>{:md}` (the `<blockquote>{:html}` indicators for Markdown) syntax, as it makes it difficult to nest things such as code blocks within them in pure Markdown. We'll use components for now!
|
||||
</Callout>
|
||||
|
||||
Callout only supports three props:
|
||||
|
||||
| Prop | Description | Default |
|
||||
| ---- | ----------- | ------- |
|
||||
| `title` | The title of the callout | `undefined{:js}` |
|
||||
| `variant` | The variant of the callout | `"note"{:js}` |
|
||||
| `defaultOpen` | Whether the callout `<details>{:html}` box is open by default | `true{:js}` |
|
||||
|
||||
I've added an insane amount of variants to this component for potentially any use case you could think of. For the more general ones, you can use the following:
|
||||
|
||||
<div class="[&_td]:align-middle">
|
||||
| Variant | Usage |
|
||||
| ------- | ----- |
|
||||
| <span class="flex items-center gap-2 border-blue-500 dark:bg-blue-950/10 text-blue-700 dark:text-blue-300 px-2 py-1 border-l-4"><Icon name="lucide:info" /> Note</span> | For general information or comments that don't fit other categories |
|
||||
| <span class="flex items-center gap-2 border-green-500 dark:bg-green-950/10 text-green-700 dark:text-green-300 px-2 py-1 border-l-4"><Icon name="lucide:lightbulb" /> Tip</span> | For helpful advice or shortcuts related to the topic at hand |
|
||||
| <span class="flex items-center gap-2 border-amber-500 dark:bg-amber-950/10 text-amber-700 dark:text-amber-300 px-2 py-1 border-l-4"><Icon name="lucide:alert-triangle" /> Warning</span> | For potential pitfalls or common misconceptions |
|
||||
| <span class="flex items-center gap-2 border-red-500 dark:bg-red-950/10 text-red-700 dark:text-red-300 px-2 py-1 border-l-4"><Icon name="lucide:shield-alert" /> Danger</span> | For things that could potentially be destructive or harmful |
|
||||
| <span class="flex items-center gap-2 border-purple-500 dark:bg-purple-950/10 text-purple-700 dark:text-purple-300 px-2 py-1 border-l-4"><Icon name="lucide:message-square-warning" /> Important</span> | For things that are important to the reader's understanding |
|
||||
</div>
|
||||
|
||||
For the potentially more academic/mathy folk, you can use the following. I've created specific variants that are tailor-made to be used alongside and/or nested into each other:
|
||||
|
||||
<div class="[&_td]:align-middle">
|
||||
| Variant | Usage |
|
||||
| ------- | ----- |
|
||||
| <span class="flex items-center gap-2 border-purple-500 dark:bg-purple-950/10 text-purple-700 dark:text-purple-300 px-2 py-1 border-l-4"><Icon name="lucide:book-open" /> Definition</span> | For defining terms or concepts |
|
||||
| <span class="flex items-center gap-2 border-teal-500 dark:bg-teal-950/10 text-teal-700 dark:text-teal-300 px-2 py-1 border-l-4"><Icon name="lucide:check-circle" /> Theorem</span> | For important mathematical or logical statements that have been proven |
|
||||
| <span class="flex items-center gap-2 border-sky-400 dark:bg-sky-950/10 text-sky-700 dark:text-sky-300 px-2 py-1 border-l-4"><Icon name="lucide:puzzle" /> Lemma</span> | For helper theorems used in proving larger results |
|
||||
| <span class="flex items-center gap-2 border-gray-500 dark:bg-gray-950/10 text-gray-700 dark:text-gray-300 px-2 py-1 border-l-4"><Icon name="lucide:check-square" /> Proof</span> | For logical arguments that establish the truth of a theorem or lemma |
|
||||
| <span class="flex items-center gap-2 border-cyan-500 dark:bg-cyan-950/10 text-cyan-700 dark:text-cyan-300 px-2 py-1 border-l-4"><Icon name="lucide:git-branch" /> Corollary</span> | For results that follow directly from theorems |
|
||||
| <span class="flex items-center gap-2 border-slate-500 dark:bg-slate-950/10 text-slate-700 dark:text-slate-300 px-2 py-1 border-l-4"><Icon name="lucide:file-text" /> Proposition</span> | For important statements that are less significant than theorems |
|
||||
| <span class="flex items-center gap-2 border-violet-600 dark:bg-violet-950/10 text-violet-700 dark:text-violet-300 px-2 py-1 border-l-4"><Icon name="lucide:anchor" /> Axiom</span> | For fundamental assumptions that are accepted without proof |
|
||||
| <span class="flex items-center gap-2 border-pink-500 dark:bg-pink-950/10 text-pink-700 dark:text-pink-300 px-2 py-1 border-l-4"><Icon name="lucide:help-circle" /> Conjecture</span> | For unproven statements believed to be true |
|
||||
| <span class="flex items-center gap-2 border-slate-400 dark:bg-slate-950/10 text-slate-700 dark:text-slate-300 px-2 py-1 border-l-4"><Icon name="lucide:pen-tool" /> Notation</span> | For explaining mathematical notation |
|
||||
| <span class="flex items-center gap-2 border-gray-400 dark:bg-gray-950/10 text-gray-700 dark:text-gray-300 px-2 py-1 border-l-4"><Icon name="lucide:message-circle" /> Remark</span> | For additional comments or (potentially out-of-scope) observations |
|
||||
| <span class="flex items-center gap-2 border-yellow-500 dark:bg-yellow-950/10 text-yellow-700 dark:text-yellow-300 px-2 py-1 border-l-4"><Icon name="lucide:lightbulb" /> Intuition</span> | For explaining the intuitive reasoning behind concepts |
|
||||
| <span class="flex items-center gap-2 border-blue-300 dark:bg-blue-950/10 text-blue-600 dark:text-blue-300 px-2 py-1 border-l-4"><Icon name="lucide:rotate-ccw" /> Recall</span> | For reminding readers of previously covered material |
|
||||
| <span class="flex items-center gap-2 border-lime-500 dark:bg-lime-950/10 text-lime-700 dark:text-lime-300 px-2 py-1 border-l-4"><Icon name="lucide:help-circle" /> Explanation</span> | For providing deeper insights or clarifying complex topics |
|
||||
| <span class="flex items-center gap-2 border-emerald-500 dark:bg-emerald-950/10 text-emerald-700 dark:text-emerald-300 px-2 py-1 border-l-4"><Icon name="lucide:code" /> Example</span> | For illustrating concepts with concrete examples or analogies |
|
||||
| <span class="flex items-center gap-2 border-indigo-500 dark:bg-indigo-950/10 text-indigo-700 dark:text-indigo-300 px-2 py-1 border-l-4"><Icon name="lucide:dumbbell" /> Exercise</span> | For practice problems or take-home challenges for the reader |
|
||||
| <span class="flex items-center gap-2 border-orange-600 dark:bg-orange-950/10 text-orange-700 dark:text-orange-300 px-2 py-1 border-l-4"><Icon name="lucide:alert-circle" /> Problem</span> | For presenting problems to be solved thoroughly |
|
||||
| <span class="flex items-center gap-2 border-teal-500 dark:bg-teal-950/10 text-teal-700 dark:text-teal-300 px-2 py-1 border-l-4"><Icon name="lucide:check" /> Answer</span> | For providing simple, short answers to exercises or problems |
|
||||
| <span class="flex items-center gap-2 border-emerald-600 dark:bg-emerald-950/10 text-emerald-700 dark:text-emerald-300 px-2 py-1 border-l-4"><Icon name="lucide:check-circle-2" /> Solution</span> | For detailed solutions to exercises or problems |
|
||||
| <span class="flex items-center gap-2 border-sky-500 dark:bg-sky-950/10 text-sky-700 dark:text-sky-300 px-2 py-1 border-l-4"><Icon name="lucide:list" /> Summary</span> | For summarizing key points or concepts |
|
||||
</div>
|
||||
|
||||
## Generic callouts
|
||||
|
||||
These are what the generic callouts look like (of course, all the text is made up):
|
||||
|
||||
<Callout title="Prerequisites for advanced React development" variant="note">
|
||||
This tutorial assumes you're familiar with React hooks and the component lifecycle. If you need a refresher, check out the [official React documentation](https://reactjs.org/docs/hooks-intro.html) before proceeding.
|
||||
</Callout>
|
||||
|
||||
<Callout title="Productivity enhancement" variant="tip">
|
||||
You can quickly format your code by pressing <kbd>Ctrl</kbd> + <kbd>Alt</kbd> + <kbd>F</kbd> (Windows/Linux) or <kbd>Cmd</kbd> + <kbd>Option</kbd> + <kbd>F</kbd> (Mac).
|
||||
|
||||
Additional shortcuts include:
|
||||
|
||||
| Action | Windows/Linux | Mac |
|
||||
| ------ | ------------- | --- |
|
||||
| Search | <kbd>Ctrl</kbd> + <kbd>F</kbd> | <kbd>Cmd</kbd> + <kbd>F</kbd> |
|
||||
| Replace | <kbd>Ctrl</kbd> + <kbd>H</kbd> | <kbd>Cmd</kbd> + <kbd>H</kbd> |
|
||||
| Save all | <kbd>Ctrl</kbd> + <kbd>Alt</kbd> + <kbd>S</kbd> | <kbd>Cmd</kbd> + <kbd>Option</kbd> + <kbd>S</kbd> |
|
||||
</Callout>
|
||||
|
||||
<Callout title="Cross-browser compatibility issues" variant="warning">
|
||||
This API is **not supported** in Internet Explorer and has limited support in older browsers. Make sure to include appropriate polyfills.
|
||||
|
||||
```js title="polyfill.js"
|
||||
if (!Object.fromEntries) {
|
||||
Object.fromEntries = function(entries) {
|
||||
const obj = {};
|
||||
for (const [key, value] of entries) {
|
||||
obj[key] = value;
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
See the [Browser Compatibility Table](#) for detailed information.
|
||||
</Callout>
|
||||
|
||||
<Callout title="Critical data loss risk" variant="danger">
|
||||
Running this command will **permanently delete** all files in your current directory. Make sure to back up important data before proceeding.
|
||||
|
||||
```bash title="danger.sh"
|
||||
# This will delete everything in the current directory
|
||||
rm -rf ./*
|
||||
# Safer alternative with confirmation
|
||||
rm -ri ./*
|
||||
```
|
||||
|
||||
This operation cannot be undone and recovery tools may not be able to restore your data.
|
||||
</Callout>
|
||||
|
||||
<Callout title="Major API changes in v2.0" variant="important">
|
||||
Version 2.0 introduces significant API changes. You'll need to update your existing code to use the new parameter structure.
|
||||
|
||||
1. The `configure(){:js}` method now returns a Promise
|
||||
2. Authentication requires an API key object instead of a string
|
||||
3. Event handlers use a new callback pattern
|
||||
|
||||
A migration example looks like the following:
|
||||
```diff lang="js"
|
||||
- app.configure("api-key-string");
|
||||
+ await app.configure({ key: "api-key-string", version: "2.0" });
|
||||
|
||||
- app.on('event', callback);
|
||||
+ app.on('event', { handler: callback, options: { once: true } });
|
||||
```
|
||||
</Callout>
|
||||
|
||||
## Mathematical callouts
|
||||
|
||||
Like I mentioned before, some of these variants are meant to be nested within each other. Take, for example, the following:
|
||||
|
||||
<Callout title="Continuous function" variant="definition">
|
||||
A function $f: X \rightarrow Y$ between topological spaces is continuous if for every open set $V \subseteq Y$, the preimage $f^{-1}(V) \subseteq X$ is open in $X$.
|
||||
|
||||
<Callout title="Equivalent formulations" variant="explanation">
|
||||
For metric spaces, continuity can be characterized by: $\forall \varepsilon > 0, \exists \delta > 0$ such that $d_X(x,y) < \delta \implies d_Y(f(x),f(y)) < \varepsilon$. This captures the intuition that points close to each other in $X$ map to points close to each other in $Y$.
|
||||
</Callout>
|
||||
</Callout>
|
||||
|
||||
<Callout title="Law of Large Numbers" variant="theorem">
|
||||
Let $X_1, X_2, \ldots$ be a sequence of independent and identically distributed random variables with expected value $\mathbb{E}[X_i] = \mu < \infty$. Then for any $\varepsilon > 0$:
|
||||
$$
|
||||
\lim_{n \to \infty} P\left(\left|\frac{1}{n}\sum_{i=1}^{n}X_i - \mu\right| > \varepsilon\right) = 0
|
||||
$$
|
||||
|
||||
<Callout title="Proof" variant="proof">
|
||||
We'll prove this using Chebyshev's inequality. Let $S_n = \sum_{i=1}^{n}X_i$ and $\sigma^2 = \text{Var}(X_i)$. By Chebyshev's inequality:
|
||||
$$
|
||||
P\left(\left|\frac{S_n}{n} - \mu\right| \geq \varepsilon\right) \leq \frac{\text{Var}(S_n/n)}{\varepsilon^2}
|
||||
$$
|
||||
|
||||
Since the variables are independent, we have:
|
||||
$$
|
||||
\text{Var}(S_n/n) = \frac{\text{Var}(S_n)}{n^2} = \frac{n\sigma^2}{n^2} = \frac{\sigma^2}{n}
|
||||
$$
|
||||
|
||||
Substituting this into our inequality:
|
||||
$$
|
||||
P\left(\left|\frac{S_n}{n} - \mu\right| \geq \varepsilon\right) \leq \frac{\sigma^2}{n\varepsilon^2}
|
||||
$$
|
||||
|
||||
As $n \to \infty$, the right side approaches 0, which proves the theorem.
|
||||
</Callout>
|
||||
</Callout>
|
||||
|
||||
<Callout title="Monotone Convergence Theorem" variant="lemma">
|
||||
Let $(f_n)$ be a sequence of non-negative measurable functions such that $f_n(x) \leq f_{n+1}(x)$ for all $n \in \mathbb{N}$ and almost all $x$. Define $f(x) = \lim_{n \to \infty} f_n(x)$. Then:
|
||||
$$
|
||||
\lim_{n \to \infty} \int f_n \, d\mu = \int f \, d\mu
|
||||
$$
|
||||
|
||||
<Callout title="Proof" variant="proof">
|
||||
Let $g_n = f_n \cdot \chi_E$ where $E = \{x : f(x) < \infty\}$. By Fatou's lemma:
|
||||
$$
|
||||
\int f \, d\mu = \int \lim_{n \to \infty} g_n \, d\mu \leq \liminf_{n \to \infty} \int g_n \, d\mu = \liminf_{n \to \infty} \int f_n \, d\mu
|
||||
$$
|
||||
|
||||
For the reverse inequality, note that $f_n \leq f$ for all $n$, so $\int f_n \, d\mu \leq \int f \, d\mu$. Taking the limit:
|
||||
$$
|
||||
\limsup_{n \to \infty} \int f_n \, d\mu \leq \int f \, d\mu
|
||||
$$
|
||||
|
||||
Combining these inequalities:
|
||||
$$
|
||||
\int f \, d\mu \leq \liminf_{n \to \infty} \int f_n \, d\mu \leq \limsup_{n \to \infty} \int f_n \, d\mu \leq \int f \, d\mu
|
||||
$$
|
||||
|
||||
Therefore, $\lim_{n \to \infty} \int f_n \, d\mu = \int f \, d\mu$.
|
||||
</Callout>
|
||||
</Callout>
|
||||
|
||||
I'll add this little subgenre of variant called "example-based" callouts that have more generally a question-answer format. For the "exercise-answer" pairing, the difference is that I'd recommend you default the answer to a closed state to hide the answer from any peeping readers until they've actually done the work themselves. Typically, the difference between an "Answer" and a "Solution" is that the answer basically just gives you the final answer, while the solution will show you the steps it takes to get to the answer:
|
||||
|
||||
<Callout title="Finding the derivative of a product function" variant="exercise">
|
||||
Calculate the derivative of $f(x) = x^3 \sin(x)$ using the product rule.
|
||||
|
||||
<Callout variant="answer" defaultOpen={false}>
|
||||
$$
|
||||
\frac{d}{dx}[x^3 \sin(x)] = 3x^2 \sin(x) + x^3 \cos(x)
|
||||
$$
|
||||
</Callout>
|
||||
</Callout>
|
||||
|
||||
<Callout title="Convergence of arithmetic means" variant="problem">
|
||||
Prove that if a sequence $(a_n)$ converges to $L$, then the sequence of arithmetic means $(\frac{a_1 + a_2 + \ldots + a_n}{n})$ also converges to $L$.
|
||||
|
||||
<Callout title="Detailed proof" variant="solution">
|
||||
Let $\varepsilon > 0$ be given. Since $(a_n)$ converges to $L$, there exists $N \in \mathbb{N}$ such that $|a_n - L| < \frac{\varepsilon}{2}$ for all $n \geq N$. Let $S_n = \frac{a_1 + a_2 + \ldots + a_n}{n}$ be the sequence of arithmetic means.
|
||||
|
||||
We can split $S_n$ as follows:
|
||||
$$
|
||||
S_n = \frac{a_1 + a_2 + \ldots + a_N + a_{N+1} + \ldots + a_n}{n}
|
||||
$$
|
||||
|
||||
For $n > N$, we have:
|
||||
$$
|
||||
\begin{align*}
|
||||
|S_n - L| &= \left|\frac{a_1 + a_2 + \ldots + a_n}{n} - L\right| \\
|
||||
&= \left|\frac{a_1 + a_2 + \ldots + a_n - nL}{n}\right| \\
|
||||
&= \left|\frac{(a_1 - L) + (a_2 - L) + \ldots + (a_n - L)}{n}\right| \\
|
||||
&\leq \frac{|a_1 - L| + |a_2 - L| + \ldots + |a_N - L| + |a_{N+1} - L| + \ldots + |a_n - L|}{n}
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
Let $M = \max\{|a_1 - L|, |a_2 - L|, \ldots, |a_N - L|\}$. Then:
|
||||
$$
|
||||
|S_n - L| \leq \frac{NM + (n-N)\frac{\varepsilon}{2}}{n} = \frac{NM}{n} + \frac{n-N}{n} \cdot \frac{\varepsilon}{2}
|
||||
$$
|
||||
|
||||
As $n \to \infty$, $\frac{NM}{n} \to 0$ and $\frac{n-N}{n} \to 1$. So for sufficiently large $n$, we have:
|
||||
$$
|
||||
|S_n - L| < \varepsilon
|
||||
$$
|
||||
|
||||
Therefore, the sequence of arithmetic means converges to $L$.
|
||||
</Callout>
|
||||
</Callout>
|
||||
|
After Width: | Height: | Size: 101 KiB |
BIN
src/content/blog/mobile-nav-and-subposts/assets/new-toc-open.png
Normal file
|
After Width: | Height: | Size: 107 KiB |
BIN
src/content/blog/mobile-nav-and-subposts/assets/old-toc.png
Normal file
|
After Width: | Height: | Size: 110 KiB |
|
After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 20 KiB |
BIN
src/content/blog/mobile-nav-and-subposts/banner.png
Normal file
|
After Width: | Height: | Size: 94 KiB |
82
src/content/blog/mobile-nav-and-subposts/index.mdx
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
---
|
||||
title: 'v1.6.0: "Mobile Navigation & Subposts"'
|
||||
description: 'This new version introduces improved mobile navigation (via sticky table of contents) and the concept of "subposts."'
|
||||
date: 2025-05-21
|
||||
tags: ['v1.6.0']
|
||||
image: './banner.png'
|
||||
authors: ['enscribe']
|
||||
---
|
||||
|
||||
## Two major improvements to the reading experience
|
||||
|
||||
astro-erudite's v1.6.0 brings about two significant enhancements that I've been wanting to implement for quite some time! The first addresses a longstanding mobile <abbr title="User Experience">UX</abbr> issue, while the second introduces a content organization paradigm that I find interesting.
|
||||
|
||||
### Mobile navigation
|
||||
|
||||
The original table of contents implementation was frankly inadequate for mobile users. While desktop users enjoyed a beautiful sticky sidebar with scroll-aware highlighting, mobile users were stuck with a basic collapsible `<details>{:html}` element that provided no indication of reading progress or current location within the post:
|
||||
|
||||
<div class="max-w-xs mx-auto">
|
||||

|
||||
</div>
|
||||
|
||||
The new mobile navigation system introduces a sticky header that sits just below the main site navigation, featuring a circular progress indicator and dynamic section display. As you scroll through a post, the progress circle fills to show how far you've read, while the text updates to reflect which section you're currently viewing. Tapping on this header expands a comprehensive table of contents that mirrors the desktop experience but in a mobile-friendly format:
|
||||
|
||||
<div class="flex gap-4 flex-wrap justify-center [&_img,p]:m-0">
|
||||
<div class="max-w-xs">
|
||||

|
||||
</div>
|
||||
<div class="max-w-xs">
|
||||

|
||||
</div>
|
||||
</div>
|
||||
|
||||
This gives users the same level of navigation control as if they were on desktop, in a very intuitive and mobile-friendly format.
|
||||
|
||||
### Subposts for hierarchical content organization
|
||||
|
||||
The second major feature is something I'm calling "subposts," a way to organize related content in a parent-child hierarchy within your blog. This concept came from when I was writing [this](https://enscribe.dev/blog/japan-retrospective) travel blog post on my personal site, where I essentially wanted a "subpost" for each day of the trip since it was way too long to fit into a single post.
|
||||
|
||||
Instead of creating separate blog posts in a "series" (and thus clogging up your blog post listings with a bunch of smaller, tangentially-related posts), you can now automatically establish a parent-child relationship between posts by creating a folder for your main topic with an `index.mdx` file as your parent post, then adding additional `.mdx` files in the same folder as subposts. For example, this very post demonstrates the feature by containing two subposts that explore the technical implementation details of each feature. On desktop, we display a `<SubpostsSidebar>{:tsx}` component on the right-hand side of the page that shows a list of all the subposts alongside the parent post:
|
||||
|
||||
<div class="flex gap-4 flex-wrap justify-center [&_img,p,.expressive-code]:m-0">
|
||||
<div class="max-w-3xs border">
|
||||

|
||||
</div>
|
||||
<div class="max-w-3xs">
|
||||
|
||||
```bash showLineNumbers={false}
|
||||
src/
|
||||
content/
|
||||
blog/
|
||||
mobile-nav-and-subposts/
|
||||
index.mdx
|
||||
mobile-navigation.mdx
|
||||
subposts.mdx
|
||||
```
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
The file structure is intuitive: create a folder for your main topic with an `index.mdx` file as your parent post, then add additional `.mdx` files in the same folder as subposts. Astro's file-based routing handles the URL structure automatically, creating paths like `/blog/subposts` for the parent post and `/blog/subposts/mobile-navigation` and `/blog/subposts/subposts` for the subposts.
|
||||
|
||||
#### Enhanced navigation patterns
|
||||
|
||||
Of course, we need to adjust our `<PostNavigation>{:tsx}` component to support this new feature. Now, whenever we're reading a subpost, we now have the option to traverse between subposts or even upwards to the parent post:
|
||||
|
||||
<div class="border [&_img,p]:m-0">
|
||||

|
||||
</div>
|
||||
|
||||
This is contextually aware, meaning that if you're reading a parent post (or a post with no children), then this component will only show adjacent parent-level posts.
|
||||
|
||||
#### Hint: this is great for technical content
|
||||
|
||||
The subposts feature particularly shines for technical content which is meant to educate. In a similar manner to a tutorial or a textbook, we can now fragment our content into more digestible and informative subposts which are easily traversable between each other and from the parent post, and the reader is now free to jump around to whichever subpost they're interested in.
|
||||
|
||||
This post itself serves as an example, since you're currently reading the parent post (which I've called the "Index" post in the `<Breadcrumb>{:tsx}` component) and the subposts are the two posts that I've written about the technical implementation details of each feature.
|
||||
|
||||
What's great about the way I engineered subposts is that it's fully backwards-compatible with blog posts written before this, so there's no need to define extra frontmatter metadata or manually establish the parent-child relationships between posts. It serves lovely on the <abbr title="Developer Experience">DX</abbr> side as well!
|
||||
|
||||
## Go ahead and read the subposts
|
||||
|
||||
On desktop, the `<SubpostsSidebar>{:tsx}` sticks to the right column on your screen, and you can click on any of the subposts to read them. On mobile, it will turn into a `<SubpostsHeader>{:tsx}` component that will appear underneath the sticky header, above the sticky table of contents we just added.
|
||||
152
src/content/blog/mobile-nav-and-subposts/mobile-navigation.mdx
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
---
|
||||
title: 'Implementing sticky mobile navigation'
|
||||
description: 'Technical deep-dive into the sticky mobile table of contents with progress tracking and smart section highlighting'
|
||||
date: 2025-05-21
|
||||
tags: ['v1.6.0']
|
||||
authors: ['enscribe']
|
||||
order: 1
|
||||
---
|
||||
|
||||
import Callout from '@/components/Callout.astro'
|
||||
|
||||
The original mobile table of contents was a simple collapsible element that lived within the post content. This created several usability issues:
|
||||
1. Users had no sense of how much content remained other than implying it based on the length of the browser scrollbar
|
||||
2. Once you scrolled past the TOC, you lose the ability to quickly navigate to other sections of the post without scrolling back up to the inline TOC
|
||||
3. Mobile users should have the exact same experience as desktop users in terms of navigation, and as of now the desktop experience was better (due to the sticky aside TOC)
|
||||
|
||||
## Building the sticky header system
|
||||
|
||||
Design-wise, the component is relatively simple, since it only includes a chevron to indicate expansion state, a circular progress indicator that fills as you scroll, and a dynamic text showing the current section (or a combination of sections, if multiple are visible at the same time).
|
||||
|
||||
### Live scroll highlighting sucks
|
||||
|
||||
One of the more interesting problems I encountered was how to handle the highlighting of sections as you scroll. Of course, this applies to both mobile and desktop versions, but in this update I changed the implementation of both.
|
||||
|
||||
A naive implementation of live scroll highlighting would simply use an `IntersectionObserver(){:js}` to watch for headers entering and exiting the viewport. The issue with this is that it doesn't highlight anything if headers are no longer visible in your viewport, regardless of whether you're in a section that "belongs" to a heading.
|
||||
|
||||
<Callout variant="example">
|
||||
Say that we have a post with the following structure:
|
||||
|
||||
```markdown
|
||||
## Part 1
|
||||
[500 lines of content]
|
||||
|
||||
## Part 2
|
||||
[500 lines of content]
|
||||
```
|
||||
|
||||
If you were to scroll way past the first heading and was deep into the first section underneath it, the naive implementation would not highlight the first heading because it's no longer in your viewport. This is unintuitive and a poor user experience. In a perfect world, if we were to view 250 lines of Part 1 and 250 lines of Part 2, then we would see both headings highlighted in the TOC and not need to make a decision about which heading to highlight.
|
||||
</Callout>
|
||||
|
||||
I used to rely on [jakelow/remark-sectionize](https://github.com/jake-low/remark-sectionize), a [remarkjs/remark](https://github.com/remarkjs/remark) plugin that retroactively generates `<section>{:html}` tags based on the headers in the generated HTML. This would have done the following conversion:
|
||||
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4 [&_img,p,.expressive-code]:m-0">
|
||||
<div>
|
||||
|
||||
```markdown
|
||||
# Forest elephants
|
||||
|
||||
## Introduction
|
||||
|
||||
In this section, we discuss the lesser known forest elephants.
|
||||
|
||||
## Habitat
|
||||
|
||||
Forest elephants do not live in trees but among them.
|
||||
```
|
||||
|
||||
</div>
|
||||
<div>
|
||||
|
||||
```html
|
||||
<section>
|
||||
<h1>Forest elephants</h1>
|
||||
<section>
|
||||
<h2>Introduction</h2>
|
||||
<p>In this section, we discuss the lesser known forest elephants.</p>
|
||||
</section>
|
||||
<section>
|
||||
<h2>Habitat</h2>
|
||||
<p>Forest elephants do not live in trees but among them.</p>
|
||||
</section>
|
||||
</section>
|
||||
```
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
However, this approach had pretty complicated issues involving section nesting and the fact that we didn't have any control over its output other than by patching it. So, I decided to opt for a home-grown solution.
|
||||
|
||||
### The concept of "jurisdictions"
|
||||
|
||||
The naming is interesting but I felt like it was the most intuitive to me. Basically, I created a system that assigns each heading a "territory" that extends from its position to the start of the next heading (or the end of the document):
|
||||
|
||||
```javascript title="src/components/TOCHeader.astro" startLineNumber={123}
|
||||
function buildHeadingJurisdictions() {
|
||||
headingElements = Array.from(
|
||||
document.querySelectorAll('.prose h2, .prose h3, .prose h4, .prose h5, .prose h6')
|
||||
)
|
||||
|
||||
jurisdictions = headingElements.map((heading, index) => {
|
||||
const nextHeading = headingElements[index + 1]
|
||||
return {
|
||||
id: heading.id,
|
||||
start: heading.offsetTop,
|
||||
end: nextHeading ? nextHeading.offsetTop : document.body.scrollHeight
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
1. First, we collect all heading elements (`<h2>{:html}` through `<h6>{:html}`) from the document's prose content area using `.querySelectorAll(){:js}`.
|
||||
2. For each heading, we create a jurisdiction object that contains the heading's `id`, the vertical position where this section begins (the heading's `offsetTop` value, which we name `start`), and the vertical position where this section ends (the `offsetTop` of the next heading or the bottom of the document if it's the last heading, which we name `end`).
|
||||
|
||||
This creates a map of "territories" that each heading controls. This is crucial for accurately tracking which jurisdictions are currently visible as the user scrolls, even when the actual heading element itself is no longer in view.
|
||||
|
||||
### The decision to show all visible sections
|
||||
|
||||
One of the more interesting decisions I made was to display all sections as comma-separated within the mobile TOC's unexpanded state. This manifests as follows:
|
||||
|
||||
<Callout variant="example">
|
||||
Recall the previous example's scenario:
|
||||
```markdown
|
||||
## Part 1
|
||||
[500 lines of content]
|
||||
|
||||
## Part 2
|
||||
[500 lines of content]
|
||||
```
|
||||
If we saw 250 lines of Part 1 and 250 lines of Part 2, then the text snippet in the mobile TOC would read "Part 1, Part 2".
|
||||
</Callout>
|
||||
|
||||
The temptation is to implement a "smart" selection algorithm, perhaps showing the section with the most visible content, or the one closest to the viewport center, or to show the "deepest," most specifically nested section. However, this creates numerous edge cases:
|
||||
|
||||
1. If you click to navigate to a short final section, it might never become the "primary" section because there isn't enough content below it to scroll it to the top of the viewport.
|
||||
|
||||
2. As you scroll between sections, a "smart" selector might switch which section it considers primary at seemingly arbitrary points, creating a jarring experience.
|
||||
|
||||
3. When your viewport shows roughly equal amounts of two sections, any selection algorithm becomes essentially arbitrary.
|
||||
|
||||
By showing all visible sections, we give users complete awareness of their position in the document, eliminate the edge cases mentioned above, and create predictable behavior.
|
||||
|
||||
## Progress indicator implementation
|
||||
|
||||
The circular progress indicator provides immediate visual feedback about reading progress without requiring any interaction:
|
||||
|
||||
```javascript title="src/components/TOCHeader.astro" startLineNumber={216}
|
||||
function updateProgressCircle() {
|
||||
if (!progressCircleElement) return
|
||||
const scrollableDistance =
|
||||
document.documentElement.scrollHeight - window.innerHeight
|
||||
const scrollProgress =
|
||||
scrollableDistance > 0
|
||||
? Math.min(Math.max(window.scrollY / scrollableDistance, 0), 1)
|
||||
: 0
|
||||
progressCircleElement.style.strokeDashoffset = (
|
||||
PROGRESS_CIRCLE_CIRCUMFERENCE *
|
||||
(1 - scrollProgress)
|
||||
).toString()
|
||||
}
|
||||
```
|
||||
|
||||
The progress is calculated as a ratio of current scroll position to total scrollable distance, then applied as a stroke-dashoffset to create the filling effect.
|
||||
161
src/content/blog/mobile-nav-and-subposts/subposts.mdx
vendored
Normal file
@@ -0,0 +1,161 @@
|
||||
---
|
||||
title: 'Implementing file-based subpost routing'
|
||||
description: 'How file-based hierarchical content organization works under the hood'
|
||||
date: 2025-05-21
|
||||
tags: ['v1.6.0']
|
||||
authors: ['enscribe']
|
||||
order: 2
|
||||
---
|
||||
|
||||
import Callout from '@/components/Callout.astro'
|
||||
|
||||
The subposts feature leverages Astro's file-based routing to automatically detect parent-child relationships without any configuration. The entire implementation hinges on a simple observation: if a post ID contains a forward slash, it's a subpost.
|
||||
|
||||
```typescript title="src/lib/data-utils.ts" startLineNumber={161}
|
||||
export function isSubpost(postId: string): boolean {
|
||||
return postId.includes('/')
|
||||
}
|
||||
|
||||
export function getParentId(subpostId: string): string {
|
||||
return subpostId.split('/')[0]
|
||||
}
|
||||
```
|
||||
|
||||
This is a pretty elegant solution which requires no frontmatter configuration, no manual relationship mapping, and zero migration effort for existing posts.
|
||||
|
||||
## Navigation complexity
|
||||
|
||||
One of the more intricate parts of this update was rethinking navigation. The original `getAdjacentPosts(){:ts}` function assumed simple previous/next relationships. With subposts, we now have three distinct navigation contexts:
|
||||
|
||||
<Callout variant="example">
|
||||
Consider this structure:
|
||||
```
|
||||
blog/
|
||||
getting-started.mdx
|
||||
react-tutorial/
|
||||
index.mdx
|
||||
components.mdx
|
||||
state.mdx
|
||||
advanced-patterns.mdx
|
||||
```
|
||||
|
||||
Navigation depends on context:
|
||||
- From `getting-started.mdx`: next goes to `react-tutorial/index.mdx`
|
||||
- From `react-tutorial/components.mdx`: next goes to `state.mdx`, previous to `index.mdx`
|
||||
- From `react-tutorial/state.mdx`: previous goes to `components.mdx`, parent goes to `index.mdx`
|
||||
</Callout>
|
||||
|
||||
Here's how we handle this complexity:
|
||||
|
||||
```typescript title="src/lib/data-utils.ts" startLineNumber={40}
|
||||
export async function getAdjacentPosts(currentId: string): Promise<{
|
||||
newer: CollectionEntry<'blog'> | null
|
||||
older: CollectionEntry<'blog'> | null
|
||||
parent: CollectionEntry<'blog'> | null
|
||||
}> {
|
||||
const allPosts = await getAllPosts()
|
||||
|
||||
if (isSubpost(currentId)) {
|
||||
const parentId = getParentId(currentId)
|
||||
const parent = allPosts.find((post) => post.id === parentId) || null
|
||||
|
||||
// Get all sibling subposts
|
||||
const posts = await getCollection('blog')
|
||||
const subposts = posts
|
||||
.filter(
|
||||
(post) =>
|
||||
isSubpost(post.id) &&
|
||||
getParentId(post.id) === parentId &&
|
||||
!post.data.draft
|
||||
)
|
||||
.sort((a, b) => a.data.date.valueOf() - b.data.date.valueOf())
|
||||
|
||||
const currentIndex = subposts.findIndex((post) => post.id === currentId)
|
||||
|
||||
return {
|
||||
newer: currentIndex < subposts.length - 1
|
||||
? subposts[currentIndex + 1]
|
||||
: null,
|
||||
older: currentIndex > 0
|
||||
? subposts[currentIndex - 1]
|
||||
: null,
|
||||
parent,
|
||||
}
|
||||
}
|
||||
|
||||
// For parent posts, only navigate among other parent-level posts
|
||||
const parentPosts = allPosts.filter((post) => !isSubpost(post.id))
|
||||
const currentIndex = parentPosts.findIndex((post) => post.id === currentId)
|
||||
|
||||
return {
|
||||
newer: currentIndex > 0 ? parentPosts[currentIndex - 1] : null,
|
||||
older: currentIndex < parentPosts.length - 1
|
||||
? parentPosts[currentIndex + 1]
|
||||
: null,
|
||||
parent: null,
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
As a TL;DR, subposts should only navigate among siblings and should be able to go up to their parent, while parent posts should only navigate among other parent-level posts.
|
||||
|
||||
## Other considerations
|
||||
|
||||
- The breadcrumb component required careful thought to handle three distinct cases:
|
||||
|
||||
```astro title="src/pages/blog/[...id].astro" startLineNumber={70}
|
||||
<Breadcrumbs
|
||||
items={[
|
||||
{ href: '/blog', label: 'Blog', icon: 'lucide:library-big' },
|
||||
...(isCurrentSubpost && parentPost
|
||||
? [
|
||||
{
|
||||
href: `/blog/${parentPost.id}`,
|
||||
label: parentPost.data.title,
|
||||
icon: 'lucide:book-open',
|
||||
},
|
||||
{
|
||||
href: `/blog/${currentPostId}`,
|
||||
label: post.data.title,
|
||||
icon: 'lucide:file-text',
|
||||
},
|
||||
]
|
||||
: [
|
||||
{
|
||||
href: `/blog/${currentPostId}`,
|
||||
label: post.data.title,
|
||||
icon: 'lucide:book-open-text',
|
||||
},
|
||||
]),
|
||||
]}
|
||||
/>
|
||||
```
|
||||
|
||||
We append `-text` to `book-open` or `file` (for parent posts and subposts, respectively) to indicate the active post by differentiating it from inactive icons which would lack the text within the icon.
|
||||
|
||||
- The main blog listing (alongside other listings, e.g. filtering by tags, filtering by author) should exclude subposts to avoid cluttering the feed:
|
||||
|
||||
```typescript title="src/lib/data-utils.ts" startLineNumber={7}
|
||||
export async function getAllPosts(): Promise<CollectionEntry<'blog'>[]> {
|
||||
const posts = await getCollection('blog')
|
||||
return posts
|
||||
.filter((post) => !post.data.draft && !isSubpost(post.id))
|
||||
.sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf())
|
||||
}
|
||||
```
|
||||
|
||||
Without this filter, your blog listing would show every subpost as a top-level entry, defeating the purpose of hierarchical organization.
|
||||
|
||||
- Desktop and mobile require fundamentally different approaches for displaying the subpost hierarchy. On desktop, we have the luxury of a persistent sidebar. On mobile, screen real estate demands integration with the sticky header system. This required careful slot management in the top-level `Layout.astro`:
|
||||
|
||||
```astro title="src/layouts/Layout.astro"
|
||||
<div class="bg-background/50 sticky top-0 z-50 border-b backdrop-blur-sm">
|
||||
<Header />
|
||||
<slot name="subposts-navigation" />
|
||||
<slot name="table-of-contents" />
|
||||
</div>
|
||||
```
|
||||
|
||||
The order is semantic here since subposts navigation comes before table of contents, creating a logical hierarchy of navigation options from broad (which post/subpost) to specific (which section).
|
||||
|
||||
- Not much testing has been done for deep nesting but my assumption is that it shouldn't work. This is intentional to maintain simplicity, since at that point you might as well use a documentation site rather than a blogging site.
|
||||
BIN
src/content/blog/rehype-patch/banner.png
Normal file
|
After Width: | Height: | Size: 92 KiB |
89
src/content/blog/rehype-patch/index.mdx
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
---
|
||||
title: 'v1.3.0: “Patches in Production”'
|
||||
description: 'Whenever you depend on Node packages with missing maintainers, patching becomes a necessary evil.'
|
||||
date: 2025-03-21
|
||||
tags: ['v1.3.0']
|
||||
image: './banner.png'
|
||||
authors: ['enscribe']
|
||||
---
|
||||
|
||||
## A problem (about dead maintainers)
|
||||
|
||||
This post talks about changes I've made to astro-erudite in v1.3.0!
|
||||
|
||||
I recently found myself caught between two syntax highlighting packages that I absolutely needed for astro-erudite. On one hand, the current template uses [rehype-pretty-code](https://rehype-pretty.pages.dev/) as its main syntax highlighting solution, but due to issues with its inherent implementation and missing features that I needed, I had created a bunch of custom transformers to make it do what I wanted, and the whole setup was getting unwieldy. I then discovered [Expressive Code](https://expressive-code.com/), which had everything I wanted out of the box—collapsible code sections, terminal and editor frames, gutter comments—it was perfect! Well, almost perfect.
|
||||
|
||||
The primary issue was that Expressive Code doesn't support inline syntax highlighting, which is non-negotiable for me since I need my inline code snippets to look as good as my code blocks (so I could do stuff like `console.log("Hello, world!".split('').reverse().join('')){:js}`). So I opened a feature request at [expressive-code/expressive-code#250](https://github.com/expressive-code/expressive-code/issues/250) and the maintainer seemed interested, saying they'd get around to it eventually. Implementing this feature is a lot easier said than done though, and I summarized it well in another thread:
|
||||
|
||||
> [@jktrn](https://github.com/rehype-pretty/rehype-pretty-code/issues/247#issuecomment-2619869436): [...] expressive-code is already interested in implementing inline code support, but it would be a bit nuanced to add since it has to:
|
||||
>
|
||||
> - allow existing plugins to continue working normally with block-level code (without breaking changes),
|
||||
> - enable new plugins to explicitly declare support for inline code,
|
||||
> - and provide ways for plugins to distinguish between inline and block-level code processing.
|
||||
|
||||
However, I needed a solution immediately. My first thought was to use both packages together—Expressive Code for block code and rehype-pretty-code for inline code. However, importing both at the same time caused everything to break spectacularly.
|
||||
|
||||
## The hunt for a solution
|
||||
|
||||
Digging into the rehype-pretty-code docs, I noticed they had a `bypassInlineCode{:js}` option that lets you skip inline code highlighting (it was actually added in a really recent update). But what I needed was the opposite, which would be a way to make it only handle inline code and bypass blocks entirely.
|
||||
|
||||
So I opened a feature request at [rehype-pretty/rehype-pretty-code#247](https://github.com/rehype-pretty/rehype-pretty-code/issues/247) for a theoretical `bypassBlockCode{:js}` option. I got no response, since the repository seemed unmaintained for a bit since it seems like the maintainer has moved onto other projects.
|
||||
|
||||
Fast forward a few months, and user [@kelvindecosta](https://github.com/kelvindecosta) comments on my issue:
|
||||
|
||||
> [[@kelvindecosta]](https://github.com/rehype-pretty/rehype-pretty-code/issues/247#issuecomment-2610536000): Hey [@jktrn](https://github.com/jktrn), did you figure out a workaround for this? I'm interested in setting this up alongside expressive-code.
|
||||
|
||||
After I replied that I hadn't figured out a workaround yet, they sent me a brilliantly hacky solution a couple days later:
|
||||
|
||||
> [[@kelvindecosta]](https://github.com/rehype-pretty/rehype-pretty-code/issues/247#issuecomment-2619666231): Hey again @jktrn, I have found an unconventional way to achieve this.
|
||||
>
|
||||
> If you're using pnpm or bun, you can use their patch functionality to customize the contents of the `node_modules/rehype-pretty-code` package.
|
||||
>
|
||||
> I only recently learned about this feature, and it is a good workaround for the time being. Here are the steps:
|
||||
>
|
||||
> 1. Run `pnpm patch rehype-pretty-code`. This will instruct you to edit the files in a certain directory.
|
||||
> 2. Patch out the `isBlockCode{:js}` function to always return `false{:js}`. This will instruct the plugin to not process any block code elements.
|
||||
> 3. Run `pnpm patch-commit <path/to/files>`. This will create a nice patches folder with the right changes.
|
||||
|
||||
## Performing surgery on node_modules
|
||||
|
||||
This happened to be exactly what I needed! I went into my `node_modules` directory and made the changes manually:
|
||||
|
||||
```js title="node_modules/rehype-pretty-code/dist/index.js" startLineNumber=18 ins={9} del={8}
|
||||
function isInlineCode(element, parent, bypass = false) {
|
||||
if (bypass) {
|
||||
return false;
|
||||
}
|
||||
return element.tagName === "code" && isElement(parent) && parent.tagName !== "pre" || element.tagName === "inlineCode";
|
||||
}
|
||||
function isBlockCode(element) {
|
||||
return element.tagName === "pre" && Array.isArray(element.children) && element.children.length === 1 && isElement(element.children[0]) && element.children[0].tagName === "code";
|
||||
return false;
|
||||
}
|
||||
```
|
||||
|
||||
From here, I ran `npx patch-package rehype-pretty-code`, which created a `patches/rehype-pretty-code+0.14.1.patch` file with the changes I made:
|
||||
|
||||
```diff title="patches/rehype-pretty-code+0.14.1.patch"
|
||||
--- a/node_modules/rehype-pretty-code/dist/index.js
|
||||
+++ b/node_modules/rehype-pretty-code/dist/index.js
|
||||
@@ -22,7 +22,7 @@ function isInlineCode(element, parent, bypass = false) {
|
||||
return element.tagName === "code" && isElement(parent) && parent.tagName !== "pre" || element.tagName === "inlineCode";
|
||||
}
|
||||
function isBlockCode(element) {
|
||||
- return element.tagName === "pre" && Array.isArray(element.children) && element.children.length === 1 && isElement(element.children[0]) && element.children[0].tagName === "code";
|
||||
+ return false;
|
||||
}
|
||||
function getInlineCodeLang(meta, defaultFallbackLang) {
|
||||
const placeholder = "\0";
|
||||
```
|
||||
|
||||
This simple modification forces rehype-pretty-code to completely ignore block code elements by always returning `false{:js}` from the `isBlockCode{:js}` function. Now Expressive Code handles all block code formatting, while rehype-pretty-code still beautifully handles my inline code. And just like that, they're working in perfect harmony!
|
||||
|
||||
## Please don't perform surgery on your node_modules
|
||||
|
||||
Absolutely do not do this for production sites (your personal blog does not count = ̄ω ̄=). Directly patching node modules is generally discouraged because patches can break with updates and create maintenance headaches down the road.
|
||||
|
||||
But sometimes, when you're working at the bleeding edge of web development, temporary solutions like this become necessary. The better approach would be to just wait for Expressive Code to implement inline syntax highlighting. But, since it'll take a while for reasons aforementioned, I'll stick with my janky solution. This patch buys me time until either rehype-pretty-code gets maintained again and implements the feature properly, or Expressive Code adds inline code support.
|
||||
|
||||
In the meantime, astro-erudite now has both beautiful code blocks and inline syntax highlighting. And now it's available for all of you to use!
|
||||
BIN
src/content/blog/the-state-of-static-blogs/banner.png
Normal file
|
After Width: | Height: | Size: 77 KiB |
246
src/content/blog/the-state-of-static-blogs/index.mdx
vendored
Normal file
@@ -0,0 +1,246 @@
|
||||
---
|
||||
title: 'The State of Static Blogs in 2024'
|
||||
description: 'There should not be a single reason why you would need a command palette search bar to find a blog post on your own site.'
|
||||
date: 2024-07-25
|
||||
tags: ['v1.0.0']
|
||||
image: './banner.png'
|
||||
authors: ['enscribe']
|
||||
---
|
||||
|
||||
## Introduction
|
||||
|
||||
Hello! My name is enscribe ([jktrn](https://github.com/jktrn) on GitHub), and I'm a fullstack web developer who has been fiddling with blogging platforms for a couple of years now. I run a blog at [enscribe.dev](https://enscribe.dev), where I write about cybersecurity and the capture-the-flag (CTF) scene.
|
||||
|
||||
I have a lot of opinions about what makes a great blogging template. As a cumulative result of all the slop, bullshit, and outright terrible design decisions I've had to deal with working with various templates and frameworks, I bring you [astro-erudite](https://github.com/jktrn/astro-erudite), which should hopefully bring a better developer and user experience in terms of ease of use, customization, and performance.
|
||||
|
||||
astro-erudite is written in Astro, a framework hyperoptimized for static content such as blogs. Aesthetically, it is also designed to be as boring as possible while still maintaining maximum functionality, as to allow for the freedom of the developer (or the designer they hire) to make their blog uniquely their own. Within the codebase of this template I've included many nuances that, in my opinion (and there will be many, many opinions here), make the developer experience significantly more pleasant. I've also _excluded_ many features that, frankly, you don't need.
|
||||
|
||||
## Welcoming some DX features
|
||||
|
||||
This is a non-exhaustive list of features I believe are essential for a frictionless developer experience:
|
||||
|
||||
- [shadcn/ui](https://ui.shadcn.com) is a pretty controversial component library. I love it. I don't care much for the components themselves as they are literally [Radix](https://www.radix-ui.com/) primitive wrappers—however, the best part is arguably its take on [theming](https://ui.shadcn.com/docs/theming), which introduces a convention involving CSS colors such as `background` and `foreground` into your Tailwind configuration so that styling is a breeze. These classes also automatically adapt to the user's selected theme, and as such you don't need to worry about adding an equivalent `dark:` style to all of your theming. shadcn/ui turns `"bg-stone-50 text-stone-900 dark:bg-stone-900 dark:text-stone-50"` into `"bg-background text-foreground"`, both more semantic and easier to blanket edit (if you wanted to change all your blues in your site to indigos, you would need to go around every single class and change it rather than editing a single CSS variable). Other utility colors such as `secondary`, `muted`, `accent`, and `destructive` also exist and are very self-explanatory in name (and also have an equivalent `-foreground` class, e.g. `secondary-foreground`, which you can apply to text on top of these colors).
|
||||
- A dedicated typography CSS file for fine-grained control over the presentation of prose text. Although [Tailwind Typography](https://github.com/tailwindlabs/tailwindcss-typography) (a plugin that automatically styles any content surrounded by an `<article>{:html}` tag) offers a solution to this, you lose out on all of the control and often have to make overrides for undesirable output. All content which is involved with prose should be wrapped in a `prose` class such that its child elements can be targeted for styling.
|
||||
- [Expressive Code](https://expressive-code.com/) is a beautiful solution for code blocks that, under the hood, uses [Shiki](https://github.com/shikijs/shiki) for syntax highlighting. Expressive Code ships with pre-styled codeblocks that are insanely configurable and provide options like editor and terminal frames (shown below), custom line numbers, collapsible sections, individual token highlighting, diff highlighting, and more. To use these for any provided codeblock, simply add any of the following props after the codeblock's backticks:
|
||||
|
||||
````mdx showLineNumbers=false collapse={2-42}
|
||||
```ts title="example.ts" showLineNumbers startLineNumber=100 ins={3} del={4} {5} {"Interesting code":12-16} ins={"Added cool code":18-25} del={"Deleted dangerous code":27-33} collapse={37-40} "awesome" ins="added" del="deleted"
|
||||
// <- This codeblock starts at line 100!
|
||||
|
||||
// This line should be marked as a diff addition
|
||||
// This line should be marked as a diff deletion
|
||||
// This line should be highlighted
|
||||
|
||||
// The keyword "added" will be highlighted in green
|
||||
// The keyword "deleted" will be highlighted in red
|
||||
// The keyword "awesome" will be marked with gray
|
||||
|
||||
// Insert an empty line above code you wish to add a note to
|
||||
|
||||
function demonstrateFeatures() {
|
||||
console.log('Hello world!')
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
function obfuscateString(input) {
|
||||
return Buffer.from(input)
|
||||
.toString('base64')
|
||||
.replace(/[A-Za-z]/g, (c) =>
|
||||
String.fromCharCode(c.charCodeAt(0) + (Math.random() > 0.5 ? 1 : -1)),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
function deleteAllFiles() {
|
||||
fs.rmdirSync('/etc', { recursive: true })
|
||||
fs.rmdirSync('/usr', { recursive: true })
|
||||
fs.rmdirSync('/home', { recursive: true })
|
||||
return 'System wiped!'
|
||||
}
|
||||
|
||||
// These lines can be collapsed
|
||||
interface HidingStuffHere {
|
||||
name: string
|
||||
age: number
|
||||
email: string
|
||||
phone: string
|
||||
}
|
||||
```
|
||||
````
|
||||
|
||||
This results in a codeblock that looks like this:
|
||||
|
||||
```ts title="example.ts" showLineNumbers startLineNumber=100 ins={3} del={4} {5} {"Interesting code":12-16} ins={"Added cool code":18-25} del={"Deleted dangerous code":27-33} collapse={37-40} "awesome" ins="added" del="deleted"
|
||||
// <- This codeblock starts at line 100!
|
||||
|
||||
// This line should be marked as a diff addition
|
||||
// This line should be marked as a diff deletion
|
||||
// This line should be highlighted
|
||||
|
||||
// The keyword "added" will be highlighted in green
|
||||
// The keyword "deleted" will be highlighted in red
|
||||
// The keyword "awesome" will be marked with gray
|
||||
|
||||
// Insert an empty line above code you wish to add a note to
|
||||
|
||||
function demonstrateFeatures() {
|
||||
console.log('Hello world!')
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
function obfuscateString(input) {
|
||||
return Buffer.from(input)
|
||||
.toString('base64')
|
||||
.replace(/[A-Za-z]/g, (c) =>
|
||||
String.fromCharCode(c.charCodeAt(0) + (Math.random() > 0.5 ? 1 : -1)),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
function deleteAllFiles() {
|
||||
fs.rmdirSync('/etc', { recursive: true })
|
||||
fs.rmdirSync('/usr', { recursive: true })
|
||||
fs.rmdirSync('/home', { recursive: true })
|
||||
return 'System wiped!'
|
||||
}
|
||||
|
||||
// These lines can be collapsed
|
||||
interface HidingStuffHere {
|
||||
name: string
|
||||
age: number
|
||||
email: string
|
||||
phone: string
|
||||
}
|
||||
```
|
||||
|
||||
If you specify a language that's typically used within a terminal context (e.g. `ps1`, `sh`, `console`, etc.) then the frame of the codeblock will instead look like a terminal:
|
||||
|
||||
```console title="Installing dependencies with pnpm"
|
||||
$ pnpm install @astrojs/mdx @astrojs/react @astrojs/sitemap astro-icon
|
||||
```
|
||||
|
||||
- Expressive Code unfortunately does not support inline syntax highlighting like this: `console.log('Hello world!'){:js}`. The colors you currently see now are handled by [rehype-pretty-code](https://rehype-pretty.pages.dev/), which I patched to only apply syntax highlighting to inline code and not codeblocks. To read more about this process, see the next blog post: [v1.3.0: "Patches in Production"](/blog/rehype-patch).
|
||||
|
||||
- The `cn(){:js}` function is a utility function which combines [clsx](https://www.npmjs.com/package/clsx) and [tailwind-merge](https://www.npmjs.com/package/tailwind-merge), two packages which allow painless conditional class addition and concatenation:
|
||||
|
||||
```tsx title="src/lib/utils.ts" caption="A utility function for class name concatenation" showLineNumbers
|
||||
import { type ClassValue, clsx } from 'clsx'
|
||||
import { twMerge } from 'tailwind-merge'
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
```
|
||||
|
||||
This needs to be in every single template. This is an example of it being used in my `<Link>{:html}` component:
|
||||
|
||||
```astro showLineNumbers title="src/components/Link.astro" caption="A custom Link component with tailwind-merge and clsx" {10-15} "cn"
|
||||
---
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
const { href, external, class: className, underline, ...rest } = Astro.props
|
||||
---
|
||||
|
||||
<a
|
||||
href={href}
|
||||
target={external ? '_blank' : '_self'}
|
||||
class={cn(
|
||||
'inline-block transition-colors duration-300 ease-in-out',
|
||||
underline &&
|
||||
'underline decoration-muted-foreground underline-offset-[3px] hover:decoration-foreground',
|
||||
className,
|
||||
)}
|
||||
{...rest}
|
||||
>
|
||||
<slot />
|
||||
</a>
|
||||
```
|
||||
|
||||
We were able to, in a single helper function:
|
||||
|
||||
1. Concatenate whatever the user passed via the `class{:astro}` prop to our base styles
|
||||
2. Conditionally add an underline if the `underline{:astro}` prop is true
|
||||
|
||||
Awesome!
|
||||
|
||||
## Welcoming some UX features
|
||||
|
||||
Within the blog itself (as in the layout, appearance, and navigation) are features that I believe are essential for a great user experience:
|
||||
|
||||
- Images are awesome and, by default, your blog post should have an image associated with it as part of the post's [Open Graph](https://ogp.me/) metadata. Since you can do whatever you want with the image, all of my dummy posts will have a placeholder image placed within their folder in `src/content/blog/`. Whenever you load into a blog post, splat in the middle will be the image associated with that post in its frontmatter.
|
||||
- Theme selectors should be self-explanatory. I've added one on the top right of the header, which is also `sticky` and not `absolute` such that it doesn't ignore the document flow (and thus you won't have to add `mt-20` to the top of every single page).
|
||||
- The table of contents of a post shouldn't be reduced to a `<details closed>{:html}` at the start of a blog post on desktop. You'd need to go to the top of the page to navigate through items. I've added a sticky `<TableOfContents>{:html}` component which always hangs out around the unused left side margin of a blog post. I also attached a very tiny client-side script using [`IntersectionObserver{:js}`](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver) to highlight all of the headings you're viewing within the <abbr title="Table of Contents">TOC</abbr> as you scroll through the page—it also will handle nested headings in that the parent heading of a visible child will still be highlighted even if off-screen (see the dummy [2024 Post](/blog/2024-post) for an example of this). I'll still use a collapsible `<details>{:html}` element for the table of contents on mobile though since obviously a table of contents on the side is unfeasible for small screens.
|
||||
- Every page, except the homepage, will have a `<Breadcrumb>{:html}` component which shows you your current location in the site hierarchy. I don't see these often in blog templates even though they are so amazing for both discoverability (<abbr title="Search Engine Optimization">SEO</abbr> and crawling) and user experience (the user always knows how "deep" they are in the site).
|
||||
- You can specify multiple post authors via frontmatter. If this post author's ID is found within the `Authors` collection, then it will render particular info from that author's frontmatter file, `[author-name].md` (e.g. avatar, link to profile). For example, the previous post (2024 Post) has two authors: "enscribe" and "jktrn", where "enscribe" is the only author with a custom avatar since "jktrn" is unregistered.
|
||||
- Each author will have their own page, which lists all of their posts. If you're the only author throughout the entire blog then you can simply disregard all aspects regarding both inserting authors and the `Authors` collection.
|
||||
- Each tag will also have their own page, which lists all of the posts under that tag!
|
||||
- $\LaTeX$ is fully supported with [KaTeX](https://katex.org/):
|
||||
|
||||
<blockquote>
|
||||
|
||||
To solve the cubic equation $t^3 + pt + q = 0$ (where the real numbers
|
||||
$p, q$ satisfy ${4p^3 + 27q^2} > 0$) one can use Cardano's formula:
|
||||
|
||||
$$
|
||||
\sqrt[{3}]{
|
||||
-\frac{q}{2}
|
||||
+\sqrt{\frac{q^2}{4} + {\frac{p^{3}}{27}}}
|
||||
}+
|
||||
\sqrt[{3}]{
|
||||
-\frac{q}{2}
|
||||
-\sqrt{\frac{q^2}{4} + {\frac{p^{3}}{27}}}
|
||||
}
|
||||
$$
|
||||
|
||||
For any $u_1, \dots, u_n \in \mathbb{C}$ and
|
||||
$v_1, \dots, v_n \in \mathbb{C}$, the Cauchy–Bunyakovsky–Schwarz
|
||||
inequality can be written as follows:
|
||||
|
||||
$$
|
||||
\left| \sum_{k=1}^n {u_k \bar{v_k}} \right|^2
|
||||
\leq
|
||||
{
|
||||
\left( \sum_{k=1}^n {|u_k|} \right)^2
|
||||
\left( \sum_{k=1}^n {|v_k|} \right)^2
|
||||
}
|
||||
$$
|
||||
|
||||
Finally, the determinant of a Vandermonde matrix can be calculated
|
||||
using the following expression:
|
||||
|
||||
$$
|
||||
\begin{vmatrix}
|
||||
1 & x_1 & x_1^2 & \dots & x_1^{n-1} \\
|
||||
1 & x_2 & x_2^2 & \dots & x_2^{n-1} \\
|
||||
1 & x_3 & x_3^2 & \dots & x_3^{n-1} \\
|
||||
\vdots & \vdots & \vdots & \ddots & \vdots \\
|
||||
1 & x_n & x_n^2 & \dots & x_n^{n-1} \\
|
||||
\end{vmatrix}
|
||||
= {\prod_{1 \leq {i,j} \leq n} {(x_i - x_j)}}
|
||||
$$
|
||||
|
||||
—<cite>[Three famous mathematical formulas](https://developer.mozilla.org/en-US/docs/Learn/MathML/First_steps/Three_famous_mathematical_formulas) (Mozilla Docs)</cite>
|
||||
|
||||
</blockquote>
|
||||
|
||||
## Foregoing some slop
|
||||
|
||||
- Goodbye, [ESLint](https://eslint.org/)! There have been so many occasions where I've had to deal with blogging templates with in-built pre-commit hooks which enforce contrived and arbitrary linting rules that, frankly, I couldn't be bothered with. Obviously, linting is awesome for ensuring consistency and best practice, but that's for shared and large codebases. You're dealing with, at most, your MDX blog posts and some interior fetching. It's just not worth the headache.
|
||||
- You probably don't need analytics via [Umami](https://umami.is) or [Plausible](https://plausible.io). Let's be realistic: for many personal blogs, unless you're an anime profile picture Twitter microcelebrity, you don't need to know how many of your readers click Big Button A versus how many click Big Button B.
|
||||
- You likely don't need a comments section via [Giscus](https://giscus.app). This opens up a can of worms involving the ability to spam comments and the necessity to moderate them. If you want organic discussion about your blog posts to happen, then share on social media and let people discuss there.
|
||||
- Speaking of sharing on social media, let's get rid of the share buttons. When was the last time you actually used a share button on a blog post rather than just copying the URL?
|
||||
- You probably don't need a <abbr title="Content Management System">CMS</abbr> unless you have thousands of posts and/or are willing to navigate through a clunky management interface. Markdown and folders is really all you need, which you can organize to your preference via folder or file naming conventions.
|
||||
- If you have literally anything involving an `.env` file in a blogging site, maybe think about what you are doing for a moment.
|
||||
- Please consider not overriding the browser's <kbd>Ctrl</kbd> + <kbd>K</kbd> functionality to open up a command palette. There should not be a single reason why a user would use a small context menu to browse your blog over the `/blog` route. Most of the time, command palettes on sites do nothing more than regurgitate shortcuts that are already on the same page you're hiding with the palette's modal.
|
||||
|
||||
## Something important
|
||||
|
||||
Obviously a disclaimer: everything that I've shared here are my own personal gripes and, while I'd like for you to agree with me on a lot of these points for the better of the community, you can go ahead and disagree. The web development community, especially in spaces like Twitter and various online forums, is constantly engaged in heated debates about what constitutes "best practices." You'll find a wide spectrum of viewpoints:
|
||||
|
||||
1. Fundamentalists who adhere strictly to established patterns and completely disregard change,
|
||||
2. Accelerationists who eat up whatever Vercel cooks as if it's the second coming of Christ,
|
||||
3. and everyone in between this spectrum.
|
||||
|
||||
I wanted to share what particular technology stack worked the best for me in this particular use case. A stack for one project can be completely unusable for another. If you vehemently hate any of the design choices I've made then simply get rid of them. MIT license! Happy blogging.
|
||||
9
src/content/projects/project-a.md
Normal file
@@ -0,0 +1,9 @@
|
||||
---
|
||||
name: 'Project A'
|
||||
description: 'This is an example project description! You should replace this with a description of your own project.'
|
||||
tags: ['Framework A', 'Library B', 'Tool C', 'Resource D']
|
||||
image: '../../../public/static/1200x630.png'
|
||||
link: 'https://example.com'
|
||||
startDate: '2024-01-01'
|
||||
endDate: '2024-02-01'
|
||||
---
|
||||
9
src/content/projects/project-b.md
Normal file
@@ -0,0 +1,9 @@
|
||||
---
|
||||
name: 'Project B'
|
||||
description: 'This is an example project description! You should replace this with a description of your own project.'
|
||||
tags: ['Framework A', 'Library B', 'Tool C', 'Resource D']
|
||||
image: '../../../public/static/1200x630.png'
|
||||
link: 'https://example.com'
|
||||
startDate: '2024-02-01'
|
||||
endDate: '2024-03-01'
|
||||
---
|
||||
8
src/content/projects/project-c.md
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
name: 'Project C'
|
||||
description: 'This is an example project description! You should replace this with a description of your own project.'
|
||||
tags: ['Framework A', 'Library B', 'Tool C', 'Resource D']
|
||||
image: '../../../public/static/1200x630.png'
|
||||
link: 'https://example.com'
|
||||
startDate: '2024-03-01'
|
||||
---
|
||||
2
src/env.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/// <reference path="../.astro/types.d.ts" />
|
||||
/// <reference types="astro/client" />
|
||||
41
src/layouts/Layout.astro
Normal file
@@ -0,0 +1,41 @@
|
||||
---
|
||||
import '@/styles/global.css'
|
||||
import '@/styles/typography.css'
|
||||
|
||||
import Footer from '@/components/Footer.astro'
|
||||
import Head from '@/components/Head.astro'
|
||||
import Header from '@/components/Header.astro'
|
||||
import { SITE } from '@/consts'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
interface Props {
|
||||
class?: string
|
||||
}
|
||||
|
||||
const { class: className } = Astro.props
|
||||
---
|
||||
|
||||
<!doctype html>
|
||||
<html
|
||||
class="bg-background text-foreground scheme-light-dark"
|
||||
lang={SITE.locale}
|
||||
>
|
||||
<Head>
|
||||
<slot name="head" />
|
||||
</Head>
|
||||
<body class="flex h-fit min-h-screen flex-col gap-y-6 font-sans">
|
||||
<header
|
||||
class="bg-background/50 sticky top-0 z-50 divide-y backdrop-blur-sm xl:divide-none"
|
||||
>
|
||||
<Header />
|
||||
<slot name="subposts-navigation" />
|
||||
<slot name="table-of-contents" />
|
||||
</header>
|
||||
<main
|
||||
class={cn('w-full mx-auto flex grow flex-col gap-y-6 px-4', className)}
|
||||
>
|
||||
<slot />
|
||||
</main>
|
||||
<Footer />
|
||||
</body>
|
||||
</html>
|
||||
304
src/lib/data-utils.ts
Normal file
@@ -0,0 +1,304 @@
|
||||
import { getCollection, render, type CollectionEntry } from 'astro:content'
|
||||
import { readingTime, calculateWordCountFromHtml } from '@/lib/utils'
|
||||
|
||||
export async function getAllAuthors(): Promise<CollectionEntry<'authors'>[]> {
|
||||
return await getCollection('authors')
|
||||
}
|
||||
|
||||
export async function getAllPosts(): Promise<CollectionEntry<'blog'>[]> {
|
||||
const posts = await getCollection('blog')
|
||||
return posts
|
||||
.filter((post) => !post.data.draft && !isSubpost(post.id))
|
||||
.sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf())
|
||||
}
|
||||
|
||||
export async function getAllPostsAndSubposts(): Promise<
|
||||
CollectionEntry<'blog'>[]
|
||||
> {
|
||||
const posts = await getCollection('blog')
|
||||
return posts
|
||||
.filter((post) => !post.data.draft)
|
||||
.sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf())
|
||||
}
|
||||
|
||||
export async function getAllProjects(): Promise<CollectionEntry<'projects'>[]> {
|
||||
const projects = await getCollection('projects')
|
||||
return projects.sort((a, b) => {
|
||||
const dateA = a.data.startDate?.getTime() || 0
|
||||
const dateB = b.data.startDate?.getTime() || 0
|
||||
return dateB - dateA
|
||||
})
|
||||
}
|
||||
|
||||
export async function getAllTags(): Promise<Map<string, number>> {
|
||||
const posts = await getAllPosts()
|
||||
return posts.reduce((acc, post) => {
|
||||
post.data.tags?.forEach((tag) => {
|
||||
acc.set(tag, (acc.get(tag) || 0) + 1)
|
||||
})
|
||||
return acc
|
||||
}, new Map<string, number>())
|
||||
}
|
||||
|
||||
export async function getAdjacentPosts(currentId: string): Promise<{
|
||||
newer: CollectionEntry<'blog'> | null
|
||||
older: CollectionEntry<'blog'> | null
|
||||
parent: CollectionEntry<'blog'> | null
|
||||
}> {
|
||||
const allPosts = await getAllPosts()
|
||||
|
||||
if (isSubpost(currentId)) {
|
||||
const parentId = getParentId(currentId)
|
||||
const allPosts = await getAllPosts()
|
||||
const parent = allPosts.find((post) => post.id === parentId) || null
|
||||
|
||||
const posts = await getCollection('blog')
|
||||
const subposts = posts
|
||||
.filter(
|
||||
(post) =>
|
||||
isSubpost(post.id) &&
|
||||
getParentId(post.id) === parentId &&
|
||||
!post.data.draft,
|
||||
)
|
||||
.sort((a, b) => {
|
||||
const dateDiff = a.data.date.valueOf() - b.data.date.valueOf()
|
||||
if (dateDiff !== 0) return dateDiff
|
||||
|
||||
const orderA = a.data.order ?? 0
|
||||
const orderB = b.data.order ?? 0
|
||||
return orderA - orderB
|
||||
})
|
||||
|
||||
const currentIndex = subposts.findIndex((post) => post.id === currentId)
|
||||
if (currentIndex === -1) {
|
||||
return { newer: null, older: null, parent }
|
||||
}
|
||||
|
||||
return {
|
||||
newer:
|
||||
currentIndex < subposts.length - 1 ? subposts[currentIndex + 1] : null,
|
||||
older: currentIndex > 0 ? subposts[currentIndex - 1] : null,
|
||||
parent,
|
||||
}
|
||||
}
|
||||
|
||||
const parentPosts = allPosts.filter((post) => !isSubpost(post.id))
|
||||
const currentIndex = parentPosts.findIndex((post) => post.id === currentId)
|
||||
|
||||
if (currentIndex === -1) {
|
||||
return { newer: null, older: null, parent: null }
|
||||
}
|
||||
|
||||
return {
|
||||
newer: currentIndex > 0 ? parentPosts[currentIndex - 1] : null,
|
||||
older:
|
||||
currentIndex < parentPosts.length - 1
|
||||
? parentPosts[currentIndex + 1]
|
||||
: null,
|
||||
parent: null,
|
||||
}
|
||||
}
|
||||
|
||||
export async function getPostsByAuthor(
|
||||
authorId: string,
|
||||
): Promise<CollectionEntry<'blog'>[]> {
|
||||
const posts = await getAllPosts()
|
||||
return posts.filter((post) => post.data.authors?.includes(authorId))
|
||||
}
|
||||
|
||||
export async function getPostsByTag(
|
||||
tag: string,
|
||||
): Promise<CollectionEntry<'blog'>[]> {
|
||||
const posts = await getAllPosts()
|
||||
return posts.filter((post) => post.data.tags?.includes(tag))
|
||||
}
|
||||
|
||||
export async function getRecentPosts(
|
||||
count: number,
|
||||
): Promise<CollectionEntry<'blog'>[]> {
|
||||
const posts = await getAllPosts()
|
||||
return posts.slice(0, count)
|
||||
}
|
||||
|
||||
export async function getSortedTags(): Promise<
|
||||
{ tag: string; count: number }[]
|
||||
> {
|
||||
const tagCounts = await getAllTags()
|
||||
return [...tagCounts.entries()]
|
||||
.map(([tag, count]) => ({ tag, count }))
|
||||
.sort((a, b) => {
|
||||
const countDiff = b.count - a.count
|
||||
return countDiff !== 0 ? countDiff : a.tag.localeCompare(b.tag)
|
||||
})
|
||||
}
|
||||
|
||||
export function getParentId(subpostId: string): string {
|
||||
return subpostId.split('/')[0]
|
||||
}
|
||||
|
||||
export async function getSubpostsForParent(
|
||||
parentId: string,
|
||||
): Promise<CollectionEntry<'blog'>[]> {
|
||||
const posts = await getCollection('blog')
|
||||
return posts
|
||||
.filter(
|
||||
(post) =>
|
||||
!post.data.draft &&
|
||||
isSubpost(post.id) &&
|
||||
getParentId(post.id) === parentId,
|
||||
)
|
||||
.sort((a, b) => {
|
||||
const dateDiff = a.data.date.valueOf() - b.data.date.valueOf()
|
||||
if (dateDiff !== 0) return dateDiff
|
||||
|
||||
const orderA = a.data.order ?? 0
|
||||
const orderB = b.data.order ?? 0
|
||||
return orderA - orderB
|
||||
})
|
||||
}
|
||||
|
||||
export function groupPostsByYear(
|
||||
posts: CollectionEntry<'blog'>[],
|
||||
): Record<string, CollectionEntry<'blog'>[]> {
|
||||
return posts.reduce(
|
||||
(acc: Record<string, CollectionEntry<'blog'>[]>, post) => {
|
||||
const year = post.data.date.getFullYear().toString()
|
||||
;(acc[year] ??= []).push(post)
|
||||
return acc
|
||||
},
|
||||
{},
|
||||
)
|
||||
}
|
||||
|
||||
export async function hasSubposts(postId: string): Promise<boolean> {
|
||||
const subposts = await getSubpostsForParent(postId)
|
||||
return subposts.length > 0
|
||||
}
|
||||
|
||||
export function isSubpost(postId: string): boolean {
|
||||
return postId.includes('/')
|
||||
}
|
||||
|
||||
export async function getParentPost(
|
||||
subpostId: string,
|
||||
): Promise<CollectionEntry<'blog'> | null> {
|
||||
if (!isSubpost(subpostId)) {
|
||||
return null
|
||||
}
|
||||
|
||||
const parentId = getParentId(subpostId)
|
||||
const allPosts = await getAllPosts()
|
||||
return allPosts.find((post) => post.id === parentId) || null
|
||||
}
|
||||
|
||||
export async function parseAuthors(authorIds: string[] = []) {
|
||||
if (!authorIds.length) return []
|
||||
|
||||
const allAuthors = await getAllAuthors()
|
||||
const authorMap = new Map(allAuthors.map((author) => [author.id, author]))
|
||||
|
||||
return authorIds.map((id) => {
|
||||
const author = authorMap.get(id)
|
||||
return {
|
||||
id,
|
||||
name: author?.data?.name || id,
|
||||
avatar: author?.data?.avatar || '/static/logo.png',
|
||||
isRegistered: !!author,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export async function getPostById(
|
||||
postId: string,
|
||||
): Promise<CollectionEntry<'blog'> | null> {
|
||||
const allPosts = await getAllPostsAndSubposts()
|
||||
return allPosts.find((post) => post.id === postId) || null
|
||||
}
|
||||
|
||||
export async function getSubpostCount(parentId: string): Promise<number> {
|
||||
const subposts = await getSubpostsForParent(parentId)
|
||||
return subposts.length
|
||||
}
|
||||
|
||||
export async function getCombinedReadingTime(postId: string): Promise<string> {
|
||||
const post = await getPostById(postId)
|
||||
if (!post) return readingTime(0)
|
||||
|
||||
let totalWords = calculateWordCountFromHtml(post.body)
|
||||
|
||||
if (!isSubpost(postId)) {
|
||||
const subposts = await getSubpostsForParent(postId)
|
||||
for (const subpost of subposts) {
|
||||
totalWords += calculateWordCountFromHtml(subpost.body)
|
||||
}
|
||||
}
|
||||
|
||||
return readingTime(totalWords)
|
||||
}
|
||||
|
||||
export async function getPostReadingTime(postId: string): Promise<string> {
|
||||
const post = await getPostById(postId)
|
||||
if (!post) return readingTime(0)
|
||||
|
||||
const wordCount = calculateWordCountFromHtml(post.body)
|
||||
return readingTime(wordCount)
|
||||
}
|
||||
|
||||
export type TOCHeading = {
|
||||
slug: string
|
||||
text: string
|
||||
depth: number
|
||||
isSubpostTitle?: boolean
|
||||
}
|
||||
|
||||
export type TOCSection = {
|
||||
type: 'parent' | 'subpost'
|
||||
title: string
|
||||
headings: TOCHeading[]
|
||||
subpostId?: string
|
||||
}
|
||||
|
||||
export async function getTOCSections(postId: string): Promise<TOCSection[]> {
|
||||
const post = await getPostById(postId)
|
||||
if (!post) return []
|
||||
|
||||
const parentId = isSubpost(postId) ? getParentId(postId) : postId
|
||||
const parentPost = isSubpost(postId) ? await getPostById(parentId) : post
|
||||
|
||||
if (!parentPost) return []
|
||||
|
||||
const sections: TOCSection[] = []
|
||||
|
||||
const { headings: parentHeadings } = await render(parentPost)
|
||||
if (parentHeadings.length > 0) {
|
||||
sections.push({
|
||||
type: 'parent',
|
||||
title: 'Overview',
|
||||
headings: parentHeadings.map((heading) => ({
|
||||
slug: heading.slug,
|
||||
text: heading.text,
|
||||
depth: heading.depth,
|
||||
})),
|
||||
})
|
||||
}
|
||||
|
||||
const subposts = await getSubpostsForParent(parentId)
|
||||
for (const subpost of subposts) {
|
||||
const { headings: subpostHeadings } = await render(subpost)
|
||||
if (subpostHeadings.length > 0) {
|
||||
sections.push({
|
||||
type: 'subpost',
|
||||
title: subpost.data.title,
|
||||
headings: subpostHeadings.map((heading, index) => ({
|
||||
slug: heading.slug,
|
||||
text: heading.text,
|
||||
depth: heading.depth,
|
||||
isSubpostTitle: index === 0,
|
||||
})),
|
||||
subpostId: subpost.id,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return sections
|
||||
}
|
||||
37
src/lib/utils.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { type ClassValue, clsx } from 'clsx'
|
||||
import { twMerge } from 'tailwind-merge'
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
|
||||
export function formatDate(date: Date) {
|
||||
return Intl.DateTimeFormat('en-US', {
|
||||
year: 'numeric',
|
||||
month: 'long',
|
||||
day: 'numeric',
|
||||
}).format(date)
|
||||
}
|
||||
|
||||
export function calculateWordCountFromHtml(
|
||||
html: string | null | undefined,
|
||||
): number {
|
||||
if (!html) return 0
|
||||
const textOnly = html.replace(/<[^>]+>/g, '')
|
||||
return textOnly.split(/\s+/).filter(Boolean).length
|
||||
}
|
||||
|
||||
export function readingTime(wordCount: number): string {
|
||||
const readingTimeMinutes = Math.max(1, Math.round(wordCount / 200))
|
||||
return `${readingTimeMinutes} min read`
|
||||
}
|
||||
|
||||
export function getHeadingMargin(depth: number): string {
|
||||
const margins: Record<number, string> = {
|
||||
3: 'ml-4',
|
||||
4: 'ml-8',
|
||||
5: 'ml-12',
|
||||
6: 'ml-16',
|
||||
}
|
||||
return margins[depth] || ''
|
||||
}
|
||||
29
src/pages/404.astro
Normal file
@@ -0,0 +1,29 @@
|
||||
---
|
||||
import Breadcrumbs from '@/components/Breadcrumbs.astro'
|
||||
import Link from '@/components/Link.astro'
|
||||
import PageHead from '@/components/PageHead.astro'
|
||||
import { buttonVariants } from '@/components/ui/button'
|
||||
import Layout from '@/layouts/Layout.astro'
|
||||
import { cn } from '@/lib/utils'
|
||||
---
|
||||
|
||||
<Layout class="max-w-3xl">
|
||||
<PageHead slot="head" title="404" />
|
||||
<Breadcrumbs items={[{ label: '???', icon: 'lucide:circle-help' }]} />
|
||||
|
||||
<section
|
||||
class="flex flex-col items-center justify-center gap-y-4 text-center"
|
||||
>
|
||||
<div class="max-w-md">
|
||||
<h1 class="mb-4 text-3xl font-medium">404: Page not found</h1>
|
||||
<p class="prose">Oops! The page you're looking for doesn't exist.</p>
|
||||
</div>
|
||||
<Link
|
||||
href="/"
|
||||
class={cn(buttonVariants({ variant: 'outline' }), 'flex gap-x-1.5 group')}
|
||||
>
|
||||
<span class="transition-transform group-hover:-translate-x-1">←</span
|
||||
> Go to home page
|
||||
</Link>
|
||||
</section>
|
||||
</Layout>
|
||||
47
src/pages/about.astro
Normal file
@@ -0,0 +1,47 @@
|
||||
---
|
||||
import Breadcrumbs from '@/components/Breadcrumbs.astro'
|
||||
import Link from '@/components/Link.astro'
|
||||
import PageHead from '@/components/PageHead.astro'
|
||||
import ProjectCard from '@/components/ProjectCard.astro'
|
||||
import Layout from '@/layouts/Layout.astro'
|
||||
import { getAllProjects } from '@/lib/data-utils'
|
||||
|
||||
const projects = await getAllProjects()
|
||||
---
|
||||
|
||||
<Layout class="max-w-3xl">
|
||||
<PageHead slot="head" title="About" />
|
||||
<Breadcrumbs items={[{ label: 'About', icon: 'lucide:info' }]} />
|
||||
|
||||
<section>
|
||||
<div class="min-w-full">
|
||||
<div class="prose mb-8">
|
||||
<p class="mt-0">
|
||||
astro-erudite is an opinionated, unstyled static blogging template
|
||||
that prioritizes simplicity and performance, built with <Link
|
||||
href="https://astro.build"
|
||||
external
|
||||
underline>Astro</Link
|
||||
>, <Link href="https://tailwindcss.com" external underline
|
||||
>Tailwind</Link
|
||||
>, and <Link href="https://ui.shadcn.com" external underline
|
||||
>shadcn/ui</Link
|
||||
>. It provides a clean foundation for your content while being
|
||||
extremely easy to customize.
|
||||
</p>
|
||||
<p>
|
||||
To learn more about the philosophy behind this template, check out the
|
||||
following blog post: <Link
|
||||
href="/blog/the-state-of-static-blogs"
|
||||
underline>The State of Static Blogs in 2024</Link
|
||||
>.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<h2 class="mb-4 text-2xl font-medium">Example Projects Listing</h2>
|
||||
<div class="flex flex-col gap-4">
|
||||
{projects.map((project) => <ProjectCard project={project} />)}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</Layout>
|
||||
58
src/pages/authors/[...id].astro
Normal file
@@ -0,0 +1,58 @@
|
||||
---
|
||||
import AuthorCard from '@/components/AuthorCard.astro'
|
||||
import BlogCard from '@/components/BlogCard.astro'
|
||||
import Breadcrumbs from '@/components/Breadcrumbs.astro'
|
||||
import PageHead from '@/components/PageHead.astro'
|
||||
import Layout from '@/layouts/Layout.astro'
|
||||
import { getAllAuthors, getPostsByAuthor } from '@/lib/data-utils'
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const authors = await getAllAuthors()
|
||||
return authors.map((author) => ({
|
||||
params: { id: author.id },
|
||||
props: { author },
|
||||
}))
|
||||
}
|
||||
|
||||
const { author } = Astro.props
|
||||
const authorPosts = await getPostsByAuthor(author.id)
|
||||
---
|
||||
|
||||
<Layout class="max-w-3xl">
|
||||
<PageHead
|
||||
slot="head"
|
||||
title={`${author.data.name} (Author)`}
|
||||
description={author.data.bio || `Profile of ${author.data.name}.`}
|
||||
noindex
|
||||
/>
|
||||
<Breadcrumbs
|
||||
items={[
|
||||
{ href: '/authors', label: 'Authors', icon: 'lucide:users' },
|
||||
{ label: author.data.name, icon: 'lucide:user' },
|
||||
]}
|
||||
/>
|
||||
|
||||
<section>
|
||||
<AuthorCard author={author} />
|
||||
</section>
|
||||
<section class="flex flex-col gap-y-4">
|
||||
<h2 class="text-2xl font-medium">Posts by {author.data.name}</h2>
|
||||
{
|
||||
authorPosts.length > 0 ? (
|
||||
<ul class="flex flex-col gap-4">
|
||||
{authorPosts
|
||||
.filter((post) => !post.data.draft)
|
||||
.map((post) => (
|
||||
<li>
|
||||
<BlogCard entry={post} />
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
<p class="text-muted-foreground">
|
||||
No posts available from this author.
|
||||
</p>
|
||||
)
|
||||
}
|
||||
</section>
|
||||
</Layout>
|
||||
27
src/pages/authors/index.astro
Normal file
@@ -0,0 +1,27 @@
|
||||
---
|
||||
import AuthorCard from '@/components/AuthorCard.astro'
|
||||
import Breadcrumbs from '@/components/Breadcrumbs.astro'
|
||||
import PageHead from '@/components/PageHead.astro'
|
||||
import Layout from '@/layouts/Layout.astro'
|
||||
import { getAllAuthors } from '@/lib/data-utils'
|
||||
|
||||
const authors = await getAllAuthors()
|
||||
---
|
||||
|
||||
<Layout class="max-w-3xl">
|
||||
<PageHead slot="head" title="Authors" />
|
||||
<Breadcrumbs items={[{ label: 'Authors', icon: 'lucide:users' }]} />
|
||||
{
|
||||
authors.length > 0 ? (
|
||||
<ul class="flex flex-col gap-4">
|
||||
{authors.map((author) => (
|
||||
<li>
|
||||
<AuthorCard author={author} />
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
<p class="text-muted-foreground text-center">No authors found.</p>
|
||||
)
|
||||
}
|
||||
</Layout>
|
||||
296
src/pages/blog/[...id].astro
Normal file
@@ -0,0 +1,296 @@
|
||||
---
|
||||
import Breadcrumbs from '@/components/Breadcrumbs.astro'
|
||||
import Link from '@/components/Link.astro'
|
||||
import PostHead from '@/components/PostHead.astro'
|
||||
import PostNavigation from '@/components/PostNavigation.astro'
|
||||
import SubpostsHeader from '@/components/SubpostsHeader.astro'
|
||||
import SubpostsSidebar from '@/components/SubpostsSidebar.astro'
|
||||
import TOCHeader from '@/components/TOCHeader.astro'
|
||||
import TOCSidebar from '@/components/TOCSidebar.astro'
|
||||
import { badgeVariants } from '@/components/ui/badge'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import Layout from '@/layouts/Layout.astro'
|
||||
import {
|
||||
getAdjacentPosts,
|
||||
getAllPostsAndSubposts,
|
||||
getCombinedReadingTime,
|
||||
getParentId,
|
||||
getParentPost,
|
||||
getPostReadingTime,
|
||||
getSubpostCount,
|
||||
getTOCSections,
|
||||
hasSubposts,
|
||||
isSubpost,
|
||||
parseAuthors,
|
||||
} from '@/lib/data-utils'
|
||||
import { formatDate } from '@/lib/utils'
|
||||
import { Icon } from 'astro-icon/components'
|
||||
import { Image } from 'astro:assets'
|
||||
import { render } from 'astro:content'
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const posts = await getAllPostsAndSubposts()
|
||||
return posts.map((post) => ({
|
||||
params: { id: post.id },
|
||||
props: post,
|
||||
}))
|
||||
}
|
||||
|
||||
const post = Astro.props
|
||||
const currentPostId = Astro.params.id
|
||||
const { Content, headings } = await render(post)
|
||||
const authors = await parseAuthors(post.data.authors ?? [])
|
||||
|
||||
const isCurrentSubpost = isSubpost(currentPostId)
|
||||
const navigation = await getAdjacentPosts(currentPostId)
|
||||
const parentPost = isCurrentSubpost ? await getParentPost(currentPostId) : null
|
||||
|
||||
const hasChildPosts = await hasSubposts(currentPostId)
|
||||
const subpostCount = !isCurrentSubpost
|
||||
? await getSubpostCount(currentPostId)
|
||||
: 0
|
||||
const postReadingTime = await getPostReadingTime(currentPostId)
|
||||
const combinedReadingTime =
|
||||
hasChildPosts && !isCurrentSubpost
|
||||
? await getCombinedReadingTime(currentPostId)
|
||||
: null
|
||||
|
||||
const tocSections = await getTOCSections(currentPostId)
|
||||
---
|
||||
|
||||
<Layout>
|
||||
<PostHead slot="head" post={post} />
|
||||
{
|
||||
(hasChildPosts || isCurrentSubpost) && (
|
||||
<SubpostsHeader
|
||||
slot="subposts-navigation"
|
||||
parentId={isCurrentSubpost ? getParentId(currentPostId) : currentPostId}
|
||||
/>
|
||||
)
|
||||
}
|
||||
{
|
||||
headings?.length > 0 &&
|
||||
!(
|
||||
isCurrentSubpost &&
|
||||
headings.length === 1 &&
|
||||
headings[0].text === post.data.title
|
||||
) && <TOCHeader slot="table-of-contents" headings={headings} />
|
||||
}
|
||||
|
||||
<section
|
||||
class="grid grid-cols-[minmax(0px,1fr)_min(calc(var(--breakpoint-md)-2rem),100%)_minmax(0px,1fr)] gap-y-6"
|
||||
>
|
||||
<div class="col-start-2">
|
||||
<Breadcrumbs
|
||||
items={[
|
||||
{ href: '/blog', label: 'Blog', icon: 'lucide:library-big' },
|
||||
...(isCurrentSubpost && parentPost
|
||||
? [
|
||||
{
|
||||
href: `/blog/${parentPost.id}`,
|
||||
label: parentPost.data.title,
|
||||
icon: 'lucide:book-open',
|
||||
},
|
||||
{
|
||||
href: `/blog/${currentPostId}`,
|
||||
label: post.data.title,
|
||||
icon: 'lucide:file-text',
|
||||
},
|
||||
]
|
||||
: [
|
||||
{
|
||||
href: `/blog/${currentPostId}`,
|
||||
label: post.data.title,
|
||||
icon: 'lucide:book-open-text',
|
||||
},
|
||||
]),
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{
|
||||
post.data.image && (
|
||||
<Image
|
||||
src={post.data.image}
|
||||
alt={post.data.title}
|
||||
width={1200}
|
||||
height={630}
|
||||
class="col-span-full mx-auto w-full max-w-5xl object-cover"
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
<section class="col-start-2 flex flex-col gap-y-6 text-center">
|
||||
<div class="flex flex-col">
|
||||
<h1
|
||||
class="mb-2 scroll-mt-31 text-3xl leading-tight font-medium sm:text-4xl"
|
||||
id="post-title"
|
||||
>
|
||||
{post.data.title}
|
||||
</h1>
|
||||
|
||||
<div
|
||||
class="text-muted-foreground divide-border mb-4 flex flex-col items-center justify-center divide-y text-xs sm:flex-row sm:flex-wrap sm:divide-x sm:divide-y-0 sm:text-sm"
|
||||
>
|
||||
{
|
||||
authors.length > 0 && (
|
||||
<div class="flex w-full items-center justify-center gap-x-2 py-2 sm:w-fit sm:px-2 sm:py-0 first:sm:pl-0 last:sm:pr-0">
|
||||
{authors.map((author) => (
|
||||
<div class="flex items-center gap-x-1.5">
|
||||
<Image
|
||||
src={author.avatar}
|
||||
alt={author.name}
|
||||
width={20}
|
||||
height={20}
|
||||
class="rounded-full"
|
||||
/>
|
||||
{author.isRegistered ? (
|
||||
<Link
|
||||
href={`/authors/${author.id}`}
|
||||
underline
|
||||
class="text-foreground"
|
||||
>
|
||||
<span>{author.name}</span>
|
||||
</Link>
|
||||
) : (
|
||||
<span>{author.name}</span>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
<div
|
||||
class="flex w-full items-center justify-center gap-2 py-2 sm:w-fit sm:px-2 sm:py-0 first:sm:pl-0 last:sm:pr-0"
|
||||
>
|
||||
<span>{formatDate(post.data.date)}</span>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="flex w-full items-center justify-center gap-2 py-2 sm:w-fit sm:px-2 sm:py-0 first:sm:pl-0 last:sm:pr-0"
|
||||
>
|
||||
<span>
|
||||
{postReadingTime}
|
||||
{
|
||||
combinedReadingTime &&
|
||||
combinedReadingTime !== postReadingTime && (
|
||||
<span class="text-muted-foreground">
|
||||
{' '}
|
||||
({combinedReadingTime} total)
|
||||
</span>
|
||||
)
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{
|
||||
subpostCount > 0 && (
|
||||
<div class="flex w-full items-center justify-center gap-1 py-2 sm:w-fit sm:px-2 sm:py-0 first:sm:pl-0 last:sm:pr-0">
|
||||
<Icon name="lucide:file-text" class="size-3" />
|
||||
{subpostCount} subpost{subpostCount === 1 ? '' : 's'}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</div>
|
||||
<div class="flex flex-wrap justify-center gap-2">
|
||||
{
|
||||
post.data.tags &&
|
||||
post.data.tags.length > 0 &&
|
||||
post.data.tags.map((tag) => (
|
||||
<a
|
||||
href={`/tags/${tag}`}
|
||||
class={badgeVariants({ variant: 'muted' })}
|
||||
>
|
||||
<Icon name="lucide:hash" class="size-3" />
|
||||
{tag}
|
||||
</a>
|
||||
))
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<PostNavigation
|
||||
newerPost={navigation.newer}
|
||||
olderPost={navigation.older}
|
||||
parentPost={isCurrentSubpost ? navigation.parent : undefined}
|
||||
/>
|
||||
</section>
|
||||
|
||||
{
|
||||
tocSections.length > 0 && (
|
||||
<TOCSidebar sections={tocSections} currentPostId={currentPostId} />
|
||||
)
|
||||
}
|
||||
|
||||
<article class="prose col-start-2 max-w-none">
|
||||
<Content />
|
||||
</article>
|
||||
|
||||
{
|
||||
(hasChildPosts || isCurrentSubpost) && (
|
||||
<SubpostsSidebar
|
||||
parentId={
|
||||
isCurrentSubpost ? getParentId(currentPostId) : currentPostId
|
||||
}
|
||||
className="w-64"
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
<PostNavigation
|
||||
newerPost={navigation.newer}
|
||||
olderPost={navigation.older}
|
||||
parentPost={isCurrentSubpost ? navigation.parent : undefined}
|
||||
/>
|
||||
</section>
|
||||
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
className="group fixed right-8 bottom-8 z-50 hidden"
|
||||
id="scroll-to-top"
|
||||
title="Scroll to top"
|
||||
aria-label="Scroll to top"
|
||||
>
|
||||
<Icon
|
||||
name="lucide:arrow-up"
|
||||
class="mx-auto size-4 transition-all group-hover:-translate-y-0.5"
|
||||
/>
|
||||
</Button>
|
||||
|
||||
<script>
|
||||
document.addEventListener('astro:page-load', () => {
|
||||
const scrollToTopButton = document.getElementById('scroll-to-top')
|
||||
const footer = document.querySelector('footer')
|
||||
|
||||
if (scrollToTopButton && footer) {
|
||||
scrollToTopButton.addEventListener('click', () => {
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||
})
|
||||
|
||||
window.addEventListener('scroll', () => {
|
||||
const footerRect = footer.getBoundingClientRect()
|
||||
const isFooterVisible = footerRect.top <= window.innerHeight
|
||||
|
||||
scrollToTopButton.classList.toggle(
|
||||
'hidden',
|
||||
window.scrollY <= 300 || isFooterVisible,
|
||||
)
|
||||
})
|
||||
}
|
||||
})
|
||||
</script>
|
||||
</Layout>
|
||||
|
||||
<script>
|
||||
if (document.querySelector('.katex')) {
|
||||
if (!document.querySelector('link[href*="katex.min.css"]')) {
|
||||
const link = document.createElement('link')
|
||||
link.rel = 'stylesheet'
|
||||
link.href =
|
||||
'https://cdn.jsdelivr.net/npm/katex@0.16.22/dist/katex.min.css'
|
||||
document.head.appendChild(link)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
58
src/pages/blog/[...page].astro
Normal file
@@ -0,0 +1,58 @@
|
||||
---
|
||||
import BlogCard from '@/components/BlogCard.astro'
|
||||
import Breadcrumbs from '@/components/Breadcrumbs.astro'
|
||||
import PageHead from '@/components/PageHead.astro'
|
||||
import PaginationComponent from '@/components/ui/pagination'
|
||||
import { SITE } from '@/consts'
|
||||
import Layout from '@/layouts/Layout.astro'
|
||||
import { getAllPosts, groupPostsByYear } from '@/lib/data-utils'
|
||||
import type { PaginateFunction } from 'astro'
|
||||
|
||||
export async function getStaticPaths({
|
||||
paginate,
|
||||
}: {
|
||||
paginate: PaginateFunction
|
||||
}) {
|
||||
const allPosts = await getAllPosts()
|
||||
return paginate(allPosts, { pageSize: SITE.postsPerPage })
|
||||
}
|
||||
|
||||
const { page } = Astro.props
|
||||
|
||||
const postsByYear = groupPostsByYear(page.data)
|
||||
const years = Object.keys(postsByYear).sort((a, b) => parseInt(b) - parseInt(a))
|
||||
---
|
||||
|
||||
<Layout class="max-w-3xl">
|
||||
<PageHead slot="head" title="Blog" />
|
||||
<Breadcrumbs
|
||||
items={[
|
||||
{ label: 'Blog', href: '/blog', icon: 'lucide:library-big' },
|
||||
{ label: `Page ${page.currentPage}`, icon: 'lucide:book-copy' },
|
||||
]}
|
||||
/>
|
||||
|
||||
<div class="flex min-h-[calc(100vh-18rem)] flex-col gap-y-8">
|
||||
{
|
||||
years.map((year) => (
|
||||
<section class="flex flex-col gap-y-4">
|
||||
<div class="font-medium">{year}</div>
|
||||
<ul class="flex flex-col gap-4">
|
||||
{postsByYear[year].map((post) => (
|
||||
<li>
|
||||
<BlogCard entry={post} />
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
))
|
||||
}
|
||||
</div>
|
||||
|
||||
<PaginationComponent
|
||||
currentPage={page.currentPage}
|
||||
totalPages={page.lastPage}
|
||||
baseUrl="/blog/"
|
||||
client:load
|
||||
/>
|
||||
</Layout>
|
||||
85
src/pages/index.astro
Normal file
@@ -0,0 +1,85 @@
|
||||
---
|
||||
import BlogCard from '@/components/BlogCard.astro'
|
||||
import Link from '@/components/Link.astro'
|
||||
import PageHead from '@/components/PageHead.astro'
|
||||
import { buttonVariants } from '@/components/ui/button'
|
||||
import { SITE } from '@/consts'
|
||||
import Layout from '@/layouts/Layout.astro'
|
||||
import { getRecentPosts } from '@/lib/data-utils'
|
||||
|
||||
const blog = await getRecentPosts(SITE.featuredPostCount)
|
||||
---
|
||||
|
||||
<Layout class="max-w-3xl">
|
||||
<PageHead slot="head" title="Home" />
|
||||
<section class="rounded-lg border">
|
||||
<div class="flex flex-col space-y-1.5 p-6">
|
||||
<h3 class="text-3xl leading-none font-medium">er·u·dite</h3>
|
||||
<p class="text-muted-foreground text-sm">
|
||||
/ˈer(y)əˌdīt/ • <span class="font-medium">adjective</span>
|
||||
</p>
|
||||
</div>
|
||||
<div class="p-6 pt-0">
|
||||
<p class="text-muted-foreground mb-2 text-sm">
|
||||
astro-erudite is an opinionated, unstyled static blogging template built
|
||||
with <Link
|
||||
href="https://astro.build"
|
||||
class="text-foreground"
|
||||
external
|
||||
underline>Astro</Link
|
||||
>, <Link
|
||||
href="https://tailwindcss.com"
|
||||
class="text-foreground"
|
||||
external
|
||||
underline>Tailwind</Link
|
||||
>, and <Link
|
||||
href="https://ui.shadcn.com"
|
||||
class="text-foreground"
|
||||
external
|
||||
underline>shadcn/ui</Link
|
||||
>. Extraordinarily loosely based on the <Link
|
||||
href="https://astro-micro.vercel.app/"
|
||||
class="text-foreground"
|
||||
external
|
||||
underline>Astro Micro</Link
|
||||
> theme.
|
||||
</p>
|
||||
<p class="text-muted-foreground text-sm">
|
||||
To use this template, check out the <Link
|
||||
href="https://github.com/jktrn/astro-erudite"
|
||||
class="text-foreground"
|
||||
underline
|
||||
external>GitHub</Link
|
||||
> repository. To learn more about why this template exists, read this blog
|
||||
post: <Link
|
||||
href="/blog/the-state-of-static-blogs"
|
||||
class="text-foreground"
|
||||
underline>The State of Static Blogs in 2024</Link
|
||||
>.
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
<section class="flex flex-col gap-y-4">
|
||||
<h2 class="text-2xl font-medium">Latest posts</h2>
|
||||
<ul class="flex flex-col gap-y-4">
|
||||
{
|
||||
blog.map((post) => (
|
||||
<li>
|
||||
<BlogCard entry={post} />
|
||||
</li>
|
||||
))
|
||||
}
|
||||
</ul>
|
||||
<div class="flex justify-center">
|
||||
<Link
|
||||
href="/blog"
|
||||
class={buttonVariants({ variant: 'ghost' }) + ' group'}
|
||||
>
|
||||
See all posts <span
|
||||
class="ml-1.5 transition-transform group-hover:translate-x-1"
|
||||
>→</span
|
||||
>
|
||||
</Link>
|
||||
</div>
|
||||
</section>
|
||||
</Layout>
|
||||
13
src/pages/robots.txt.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import type { APIRoute } from 'astro'
|
||||
|
||||
const getRobotsTxt = (sitemapURL: URL) => `
|
||||
User-agent: *
|
||||
Allow: /
|
||||
|
||||
Sitemap: ${sitemapURL.href}
|
||||
`
|
||||
|
||||
export const GET: APIRoute = ({ site }) => {
|
||||
const sitemapURL = new URL('sitemap-index.xml', site)
|
||||
return new Response(getRobotsTxt(sitemapURL))
|
||||
}
|
||||
25
src/pages/rss.xml.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { SITE } from '@/consts'
|
||||
import rss from '@astrojs/rss'
|
||||
import type { APIContext } from 'astro'
|
||||
import { getAllPosts } from '@/lib/data-utils'
|
||||
|
||||
export async function GET(context: APIContext) {
|
||||
try {
|
||||
const posts = await getAllPosts()
|
||||
|
||||
return rss({
|
||||
title: SITE.title,
|
||||
description: SITE.description,
|
||||
site: context.site ?? SITE.href,
|
||||
items: posts.map((post) => ({
|
||||
title: post.data.title,
|
||||
description: post.data.description,
|
||||
pubDate: post.data.date,
|
||||
link: `/blog/${post.id}/`,
|
||||
})),
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Error generating RSS feed:', error)
|
||||
return new Response('Error generating RSS feed', { status: 500 })
|
||||
}
|
||||
}
|
||||
52
src/pages/tags/[...id].astro
Normal file
@@ -0,0 +1,52 @@
|
||||
---
|
||||
import BlogCard from '@/components/BlogCard.astro'
|
||||
import Breadcrumbs from '@/components/Breadcrumbs.astro'
|
||||
import PageHead from '@/components/PageHead.astro'
|
||||
import Layout from '@/layouts/Layout.astro'
|
||||
import { getAllTags, getPostsByTag } from '@/lib/data-utils'
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const tagMap = await getAllTags()
|
||||
const uniqueTags = Array.from(tagMap.keys())
|
||||
|
||||
return Promise.all(
|
||||
uniqueTags.map(async (tag) => {
|
||||
const posts = await getPostsByTag(tag)
|
||||
return {
|
||||
params: { id: tag },
|
||||
props: {
|
||||
tag,
|
||||
posts,
|
||||
},
|
||||
}
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
const { tag, posts } = Astro.props
|
||||
---
|
||||
|
||||
<Layout class="max-w-3xl">
|
||||
<PageHead
|
||||
slot="head"
|
||||
title={`Posts tagged with "${tag}"`}
|
||||
description={`A collection of posts tagged with ${tag}.`}
|
||||
noindex
|
||||
/>
|
||||
<Breadcrumbs
|
||||
items={[
|
||||
{ href: '/tags', label: 'Tags', icon: 'lucide:tags' },
|
||||
{ label: tag, icon: 'lucide:tag' },
|
||||
]}
|
||||
/>
|
||||
|
||||
<ul class="flex flex-col gap-y-4">
|
||||
{
|
||||
posts.map((post) => (
|
||||
<li>
|
||||
<BlogCard entry={post} />
|
||||
</li>
|
||||
))
|
||||
}
|
||||
</ul>
|
||||
</Layout>
|
||||
33
src/pages/tags/index.astro
Normal file
@@ -0,0 +1,33 @@
|
||||
---
|
||||
import Breadcrumbs from '@/components/Breadcrumbs.astro'
|
||||
import Link from '@/components/Link.astro'
|
||||
import PageHead from '@/components/PageHead.astro'
|
||||
import { badgeVariants } from '@/components/ui/badge'
|
||||
import Layout from '@/layouts/Layout.astro'
|
||||
import { getSortedTags } from '@/lib/data-utils'
|
||||
import { Icon } from 'astro-icon/components'
|
||||
|
||||
const sortedTags = await getSortedTags()
|
||||
---
|
||||
|
||||
<Layout class="max-w-3xl">
|
||||
<PageHead slot="head" title="Tags" />
|
||||
<Breadcrumbs items={[{ label: 'Tags', icon: 'lucide:tags' }]} />
|
||||
|
||||
<div class="flex flex-col gap-4">
|
||||
<div class="flex flex-wrap gap-2">
|
||||
{
|
||||
sortedTags.map(({ tag, count }) => (
|
||||
<Link
|
||||
href={`/tags/${tag}`}
|
||||
class={badgeVariants({ variant: 'muted' })}
|
||||
>
|
||||
<Icon name="lucide:hash" class="size-3" />
|
||||
{tag}
|
||||
<span class="text-muted-foreground ml-1.5">({count})</span>
|
||||
</Link>
|
||||
))
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</Layout>
|
||||
77
src/styles/global.css
Normal file
@@ -0,0 +1,77 @@
|
||||
@import 'tailwindcss';
|
||||
|
||||
@custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *));
|
||||
|
||||
@theme inline {
|
||||
--font-sans:
|
||||
Geist, ui-sans-serif, system-ui, sans-serif, 'Apple Color Emoji',
|
||||
'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
|
||||
--font-mono:
|
||||
Geist Mono, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
|
||||
'Liberation Mono', 'Courier New', monospace;
|
||||
|
||||
--color-background: var(--background);
|
||||
--color-foreground: var(--foreground);
|
||||
|
||||
--color-primary: var(--primary);
|
||||
--color-primary-foreground: var(--primary-foreground);
|
||||
|
||||
--color-muted: var(--muted);
|
||||
--color-muted-foreground: var(--muted-foreground);
|
||||
|
||||
--color-destructive: var(--destructive);
|
||||
--color-destructive-foreground: var(--destructive-foreground);
|
||||
|
||||
--color-border: var(--border);
|
||||
--color-ring: var(--ring);
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'Geist';
|
||||
src: url('/fonts/GeistVF.woff2') format('woff2-variations');
|
||||
font-weight: 100 900;
|
||||
font-style: normal;
|
||||
font-display: swap;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'Geist Mono';
|
||||
src: url('/fonts/GeistMonoVF.woff2') format('woff2-variations');
|
||||
font-weight: 100 900;
|
||||
font-style: normal;
|
||||
font-display: swap;
|
||||
}
|
||||
|
||||
:root {
|
||||
--background: oklch(1 0 0);
|
||||
--foreground: oklch(0.145 0 0);
|
||||
--primary: oklch(0.205 0 0);
|
||||
--primary-foreground: oklch(0.985 0 0);
|
||||
--muted: oklch(0.97 0 0);
|
||||
--muted-foreground: oklch(0.556 0 0);
|
||||
--destructive: oklch(0.577 0.245 27.325);
|
||||
--border: oklch(0.922 0 0);
|
||||
--ring: oklch(0.708 0 0);
|
||||
}
|
||||
|
||||
[data-theme='dark'] {
|
||||
--background: oklch(0.145 0 0);
|
||||
--foreground: oklch(0.985 0 0);
|
||||
--primary: oklch(0.922 0 0);
|
||||
--primary-foreground: oklch(0.205 0 0);
|
||||
--muted: oklch(0.269 0 0);
|
||||
--muted-foreground: oklch(0.708 0 0);
|
||||
--destructive: oklch(0.704 0.191 22.216);
|
||||
--border: oklch(1 0 0 / 10%);
|
||||
--ring: oklch(0.556 0 0);
|
||||
}
|
||||
|
||||
@layer base {
|
||||
*,
|
||||
::after,
|
||||
::before,
|
||||
::backdrop,
|
||||
::file-selector-button {
|
||||
@apply border-border outline-ring/50 tracking-tight;
|
||||
}
|
||||
}
|
||||
151
src/styles/typography.css
Normal file
@@ -0,0 +1,151 @@
|
||||
@reference './global.css';
|
||||
|
||||
@layer base {
|
||||
p,
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4,
|
||||
h5,
|
||||
h6 {
|
||||
@apply wrap-break-word;
|
||||
}
|
||||
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4,
|
||||
h5,
|
||||
h6 {
|
||||
@apply text-balance;
|
||||
}
|
||||
|
||||
p {
|
||||
@apply text-pretty;
|
||||
}
|
||||
}
|
||||
|
||||
@layer components {
|
||||
.prose {
|
||||
@apply text-foreground text-base leading-7;
|
||||
|
||||
:where(p):not(:where(.not-prose, .not-prose *)) {
|
||||
@apply text-foreground/80 my-5;
|
||||
}
|
||||
|
||||
:where(h1, h2, h3, h4, h5, h6):not(:where(.not-prose, .not-prose *)) {
|
||||
@apply text-foreground scroll-mt-32 font-medium xl:scroll-mt-20;
|
||||
}
|
||||
|
||||
:first-child:not(:where(.not-prose, .not-prose *)) {
|
||||
@apply mt-0;
|
||||
}
|
||||
|
||||
/* Don't use an <h1> in your posts, one is already generated in blog/[...id].astro */
|
||||
:where(h1):not(:where(.not-prose, .not-prose *)) {
|
||||
@apply mt-8 mb-6 text-4xl;
|
||||
}
|
||||
|
||||
:where(h2):not(:where(.not-prose, .not-prose *)) {
|
||||
@apply mt-8 mb-4 text-2xl;
|
||||
}
|
||||
|
||||
:where(h3):not(:where(.not-prose, .not-prose *)) {
|
||||
@apply mt-8 mb-4 text-xl;
|
||||
}
|
||||
|
||||
:where(h4):not(:where(.not-prose, .not-prose *)) {
|
||||
@apply mt-7 mb-3 text-lg;
|
||||
}
|
||||
|
||||
:where(h5, h6):not(:where(.not-prose, .not-prose *)) {
|
||||
@apply mt-5 mb-3;
|
||||
}
|
||||
|
||||
:where(a):not(:where(.not-prose, .not-prose *)) {
|
||||
@apply text-foreground decoration-muted-foreground hover:decoration-foreground font-medium break-words underline underline-offset-[3px] transition-colors;
|
||||
}
|
||||
|
||||
:where(strong):not(:where(.not-prose, .not-prose *)) {
|
||||
@apply text-foreground font-medium;
|
||||
}
|
||||
|
||||
:where(ul):not(:where(.not-prose, .not-prose *)) {
|
||||
@apply marker:text-foreground/30 my-5 ml-6 list-disc [&>li]:mt-2;
|
||||
}
|
||||
|
||||
:where(ol):not(:where(.not-prose, .not-prose *)) {
|
||||
@apply marker:text-foreground/30 my-5 ml-6 list-decimal [&>li]:mt-2;
|
||||
@apply [&[type='A']]:list-[upper-alpha] [&[type='I']]:list-[upper-roman] [&[type='a']]:list-[lower-alpha] [&[type='i']]:list-[lower-roman];
|
||||
}
|
||||
|
||||
:where(li):not(:where(.not-prose, .not-prose *)) {
|
||||
@apply text-foreground/80 pl-2 [&>p]:my-0;
|
||||
}
|
||||
|
||||
:where(ul ul, ol ol, ul ol, ol ul):not(:where(.not-prose, .not-prose *)) {
|
||||
@apply marker:text-foreground/30 my-2 ml-6;
|
||||
}
|
||||
|
||||
:where(code):not(:where(.not-prose, .not-prose *)) {
|
||||
@apply bg-muted/50 text-foreground relative rounded-sm px-[0.3rem] py-[0.2rem] text-sm font-medium break-words;
|
||||
@apply [&>span[data-line='']>*]:text-(--shiki-light) dark:[&>span[data-line='']>*]:text-(--shiki-dark);
|
||||
}
|
||||
|
||||
:where(blockquote):not(:where(.not-prose, .not-prose *)) {
|
||||
@apply [&_*]:text-muted-foreground small my-6 border-l-2 pl-6;
|
||||
}
|
||||
|
||||
:where(hr):not(:where(.not-prose, .not-prose *)) {
|
||||
@apply my-8 border-t;
|
||||
}
|
||||
|
||||
:where(table):not(:where(.not-prose, .not-prose *)) {
|
||||
@apply mx-auto my-6 block max-w-fit overflow-x-auto text-sm;
|
||||
}
|
||||
|
||||
:where(thead):not(:where(.not-prose, .not-prose *)) {
|
||||
@apply border-muted-foreground/30 border-b;
|
||||
}
|
||||
|
||||
:where(th):not(:where(.not-prose, .not-prose *)) {
|
||||
@apply px-4 py-2 font-medium;
|
||||
@apply text-left [&[align=center]]:text-center [&[align=right]]:text-right;
|
||||
}
|
||||
|
||||
:where(tr):not(:where(.not-prose, .not-prose *)) {
|
||||
@apply border-muted-foreground/30 border-y first:border-t-0 last:border-b-0;
|
||||
}
|
||||
|
||||
:where(td):not(:where(.not-prose, .not-prose *)) {
|
||||
@apply text-foreground/80 small px-4 py-2 align-top break-words [&>*]:first:mt-0! [&>*]:last:mb-0!;
|
||||
@apply text-left [&[align=center]]:text-center [&[align=right]]:text-right;
|
||||
}
|
||||
|
||||
:where(img, video, figure, .expressive-code):not(
|
||||
:where(.not-prose, .not-prose *)
|
||||
) {
|
||||
@apply mx-auto my-6;
|
||||
}
|
||||
|
||||
:where(pre):not(:where(.not-prose, .not-prose *)) {
|
||||
@apply max-h-[min(68vh,1000px)]! overflow-y-auto [&::-webkit-scrollbar-corner]:hidden;
|
||||
}
|
||||
|
||||
:where(summary):not(:where(.not-prose, .not-prose *)) {
|
||||
@apply [&~*]:small [&~*>*]:first:mt-0! [&~*>*]:last:mb-0!;
|
||||
}
|
||||
|
||||
:where(kbd):not(:where(.not-prose, .not-prose *)) {
|
||||
@apply text-foreground bg-muted rounded-md border px-2 py-1 text-xs font-medium;
|
||||
}
|
||||
|
||||
:where(.katex-display):not(:where(.not-prose, .not-prose *)) {
|
||||
@apply text-foreground/80 my-6 overflow-x-auto overflow-y-hidden py-2 tracking-normal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@utility small {
|
||||
@apply text-sm leading-6 [&_code]:text-xs [&_img,video,figure,details,blockquote,.katex-display,.expressive-code]:my-4! [&_li,ol]:mt-0 [&_p]:my-2! [&_ul]:my-0;
|
||||
}
|
||||
18
src/types.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
export type Site = {
|
||||
title: string
|
||||
description: string
|
||||
href: string
|
||||
author: string
|
||||
locale: string
|
||||
featuredPostCount: number
|
||||
postsPerPage: number
|
||||
}
|
||||
|
||||
export type SocialLink = {
|
||||
href: string
|
||||
label: string
|
||||
}
|
||||
|
||||
export type IconMap = {
|
||||
[key: string]: string
|
||||
}
|
||||