Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
a6da2c3
style: express color tokens in oklch
veksen Oct 6, 2026
e8aa0e6
feat(resources): floating sidebar card over a waves banner
veksen Oct 6, 2026
433ca8b
feat(resources): article header, type and aside from the 2026 design
veksen Oct 6, 2026
acb377b
fix(resources): render prev/next titles as gradient text
veksen Oct 6, 2026
47a4abc
feat(resources): use the header and drawer below 1024px
veksen Oct 6, 2026
2d6e35d
fix(a11y): make the mobile menu toggle a button with two visible bars
veksen Oct 6, 2026
49c61f7
style(resources): tighten the table of contents to the sidebar rhythm
veksen Oct 6, 2026
a71d582
style(resources): drop the translucent bar behind the mobile header
veksen Oct 6, 2026
e1a1f45
feat(resources): full-bleed code on phones with scroll edge fades
veksen Oct 7, 2026
f8e0a45
fix(resources): let the sticky sidebar and aside follow scroll direction
veksen Oct 7, 2026
a918147
fix(resources): keep the drawer's scroll lock when the tree re-renders
veksen Oct 7, 2026
fc156c7
fix: close the mobile drawer when the viewport passes its breakpoint
veksen Oct 7, 2026
e4fddb3
perf(resources): let the browser scroll the sticky card between stops
veksen Oct 7, 2026
3bc3e69
fix(resources): let the folder holding the current page collapse
veksen Oct 7, 2026
9bbc75e
fix(resources): refresh code scroll fades when the web font loads
veksen Oct 7, 2026
8cc485b
fix(resources): wrap long words in the article title
veksen Oct 7, 2026
e32d1aa
fix(resources): keep the meta row on its 21px line height
veksen Oct 7, 2026
e0f7a44
style(resources): size code and spacing correctly next to headings
veksen Oct 7, 2026
e446b66
fix(resources): skip the empty aside below 1200px
veksen Oct 7, 2026
f1b29c5
fix(resources): drop the self-link from a category home's breadcrumb
veksen Oct 7, 2026
9c21a1c
fix(resources): keep the banner's fade intact above 1440px
veksen Oct 7, 2026
6702d16
fix(resources): apply icon opacity once
veksen Oct 7, 2026
48298a5
fix(resources): raise the card's theme switch to readable contrast
veksen Oct 7, 2026
54a30f4
feat(resources): give the resources index the redesigned header
veksen Oct 13, 2026
f03f90c
fix(resources): list every resource on paths outside a category
veksen Oct 13, 2026
fc03c50
refactor: rename ResourceArticle to Article
veksen Oct 13, 2026
de2b8ac
feat(article): render the site footer on every article page
veksen Oct 13, 2026
cd4340f
feat: move site pages and spotlights onto the 2026 layout
veksen Oct 13, 2026
014cf11
feat: redesign the 404 pages on the article layout
veksen Oct 13, 2026
f551806
fix: wrap markdown links at spaces instead of mid-word
veksen Oct 13, 2026
d8fe3e9
fix(article): keep meta bullets with the item that follows them
veksen Oct 13, 2026
29e0138
refactor: drop the old column layout and header components
veksen Oct 13, 2026
36eaaab
fix: line the phone header and narrow aside up with the content
veksen Oct 13, 2026
6acdd12
fix: restore the sidebar card's gradient border
veksen Oct 13, 2026
3588940
fix: point table-of-contents links at the ids rehype-slug writes
veksen Oct 13, 2026
7286377
fix: pin the menu bars inside the button's content box
veksen Oct 13, 2026
fbcf57a
content: drop the duplicate "Beginners" heading
veksen Oct 13, 2026
2efcea6
style(article): keep role pills inside the 23px text line
veksen Oct 13, 2026
fb34d78
style(article): set code in regular weight
veksen Oct 13, 2026
a3f75da
style: set the site footer in the article's secondary type
veksen Oct 13, 2026
a926b8d
fix: load IBM Plex Sans italics
veksen Oct 13, 2026
2dfcfab
feat(spotlights): give spotlight articles a table of contents
veksen Oct 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
337 changes: 337 additions & 0 deletions src/components/Article/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,337 @@
import React, { FC, ReactNode, useRef } from "react"

import type { Author } from "../../appTypes"
import ChevronRight from "../../icons/chevron-right.svg?react"
import ChevronRightSmall from "../../icons/chevron-right-sm.svg?react"
import { useScrollAwareSticky } from "../../hooks/useScrollAwareSticky"
import { cn } from "../../lib/cn"
import { IExternalResource, IFileOrFolder, ITocItem } from "../../types"
import { humanize, sentenceCase, traversePaths } from "../../utils"
import { AppLink } from "../AppLink"
import { Footer } from "../Footer"
import { PageSidebarLink } from "../PageSidebarLink"
import { Toc } from "../Toc"

interface IArticleProps {
// Omitted on section pages (the resources index): the breadcrumb is then
// just Home, and there is no meta line.
relativePath?: string
// Section root for the breadcrumb ("/resources"); needed with relativePath.
basePath?: string
// Explicit crumbs after Home, for pages that are not content files (404s).
crumbs?: { path: string; title: string }[]
title: string
authors?: Author[]
createdAt?: string
timeToRead?: number
toc?: ITocItem[]
recommendedReading?: string[]
externalResources?: IExternalResource[]
// Article body (the Markdown), and what follows it (prev/next). The site
// footer always comes last.
children: ReactNode
after?: ReactNode
}

// Folder chain from the outermost folder down to the file.
function flattenTrail([
currNode,
...previousNodes
]: IFileOrFolder[]): IFileOrFolder[] {
if (currNode.type === "file") {
return [...previousNodes, currNode]
}

return flattenTrail([...currNode.children, ...previousNodes, currNode])
}

function trailItems(relativePath: string, basePath: string) {
const trail = flattenTrail([traversePaths(relativePath.split("/"), basePath)])
const folders = trail.filter((item) => item.type === "folder")
const file = trail[trail.length - 1]
// A top-level folder's intro is that folder's home page (/resources/<lang>),
// so its crumb would be a link to the current page.
const crumbs =
file.type === "file" && file.title === "intro" && folders.length === 1
? []
: folders
const items = [
{ path: "/", title: "home", link: true },
{ path: basePath, title: basePath.replace(/\//, ""), link: true },
...crumbs.map((item, index) => ({
path: item.path,
title: item.title,
link: index === 0,
})),
]
return items
}

// Home > Resources > language (link) > deeper folders (text). The page itself
// is the <h1> below, so it is not repeated here.
const ArticleBreadcrumb: FC<{
relativePath?: string
basePath?: string
crumbs?: { path: string; title: string }[]
}> = ({ relativePath, basePath, crumbs }) => {
const home = { path: "/", title: "home", link: true }
const items = crumbs
? [home, ...crumbs.map((crumb) => ({ ...crumb, link: true }))]
: relativePath && basePath
? trailItems(relativePath, basePath)
: [home]

return (
<nav aria-label="Breadcrumb" className="pl-[23px] max-md:pl-0">
<ol className="flex flex-wrap items-center gap-x-[6px] text-base leading-[21px] font-medium tracking-[-0.75px] text-main-fg/90">
{items.map((item, index) => (
<li key={item.path} className="flex items-center gap-x-[7px]">
{index > 0 && (
<ChevronRightSmall aria-hidden="true" className="shrink-0" />
)}
{item.link ? (
<AppLink
to={item.path}
className="text-inherit underline decoration-from-font hover:text-main-fg"
>
{sentenceCase(humanize(item.title))}
</AppLink>
) : (
<span>{sentenceCase(humanize(item.title))}</span>
)}
</li>
))}
</ol>
</nav>
)
}

const listFormat = new Intl.ListFormat("en", {
style: "long",
type: "conjunction",
})
const dateFormat = new Intl.DateTimeFormat("en-US", { dateStyle: "long" })

const ArticleMeta: FC<{
authors?: Author[]
createdAt?: string
timeToRead?: number
}> = ({ authors = [], createdAt, timeToRead }) => {
const date = createdAt ? new Date(createdAt) : null
const hasDate = date !== null && !Number.isNaN(date.getTime())
const names = authors.map((author) => author.name)

const parts: ReactNode[] = []
if (names.length > 0) {
parts.push(
<span key="by" className="text-[16px]">
by{" "}
{listFormat.formatToParts(names).map((part, index) =>
part.type === "element" ? (
<span key={index} className="font-medium">
{part.value}
</span>
) : (
<React.Fragment key={index}>{part.value}</React.Fragment>
)
)}
</span>
)
}
if (hasDate) {
parts.push(
<time key="date" dateTime={date.toISOString()} className="text-[14px]">
{dateFormat.format(date)}
</time>
)
}
if (timeToRead !== undefined) {
parts.push(
<span key="time" className="text-[14px]">
{timeToRead} minute read time
</span>
)
}
if (parts.length === 0) return null

return (
<div className="mt-[6.5px] flex items-center gap-[13px] pl-[21px] max-md:pl-0">
{authors.length > 0 && (
<div className="flex shrink-0">
{authors.map((author, index) => (
<img
key={`${author.name}#${author.hash}`}
src={author.avatar}
alt=""
width={32}
height={32}
className="relative size-8 rounded-full border-2 border-avatar-ring not-first:-ml-5"
style={{ zIndex: index }}
/>
))}
</div>
)}
{/* Sizes are arbitrary values (font-size only) so the row's 21px
line-height reaches them; text-sm/text-base would reset it. */}
<p className="m-0 flex flex-wrap items-center gap-x-[11px] leading-[21px] font-light tracking-[-0.75px] text-main-fg/90">
{/* Each bullet is kept on the line of the item after it, so a wrapped
row never ends on a dangling "•". */}
{parts.map((part, index) =>
index === 0 ? (
part
) : (
<span
key={index}
className="inline-flex items-center gap-x-[11px] whitespace-nowrap"
>
<span aria-hidden="true" className="text-[14px]">
•
</span>
{part}
</span>
)
)}
</p>
</div>
)
}

// Recommended reading points at other resources by path; an "intro" page is
// named after its folder ("javascript/callbacks/intro" reads "Callbacks").
function recommendedLabel(path: string): string {
const segments = path.split("/")
const last = segments[segments.length - 1]
const name =
last === "intro" && segments.length > 1
? segments[segments.length - 2]
: last
return sentenceCase(humanize(name))
}

const asideHeader =
"m-0 mb-2.5 text-lg leading-[23px] font-bold text-main-fg/90"

const ArticleAside: FC<{
toc: ITocItem[]
recommendedReading?: string[]
externalResources?: IExternalResource[]
}> = ({ toc, recommendedReading, externalResources }) => {
const ref = useRef<HTMLElement>(null)
// A long table of contents can outgrow the viewport; keep all of it reachable.
useScrollAwareSticky(ref, 36)

const hasLinks =
Boolean(recommendedReading?.length) || Boolean(externalResources?.length)
if (!hasLinks && toc.length === 0) return null

return (
<aside
ref={ref}
className={cn(
"article-aside flex flex-col gap-[56.5px] pr-2.5 pl-[18px] max-md:px-0 min-[1200px]:sticky min-[1200px]:pr-0 min-[1200px]:pl-2 min-[1200px]:top-9 min-[1200px]:-mt-px min-[1200px]:col-start-2 min-[1200px]:row-span-2 min-[1200px]:row-start-2 min-[1200px]:self-start max-[1199px]:mt-16",
// Below 1200px the table of contents is hidden; with no links left
// the aside would be an empty landmark adding 64px of space.
!hasLinks && "max-[1199px]:hidden"
)}
>
{toc.length > 0 && (
<nav aria-label="On this page" className="max-[1199px]:hidden">
<Toc header={null} items={toc} />
</nav>
)}

{recommendedReading && recommendedReading.length > 0 && (
<section>
<h2 className={asideHeader}>Recommended reading</h2>
<ul className="m-0 flex list-none flex-col items-start gap-[5px] p-0">
{recommendedReading.map((item) => (
<li key={item} className="article-link">
<PageSidebarLink
href={item}
text={recommendedLabel(item)}
type="internal"
/>
<ChevronRight aria-hidden="true" className="shrink-0" />
</li>
))}
</ul>
</section>
)}

{externalResources && externalResources.length > 0 && (
<section>
<h2 className={asideHeader}>External resources</h2>
<ul className="m-0 flex list-none flex-col items-start gap-[5px] p-0">
{externalResources.map((item) => (
<li key={item.href} className="article-link">
<PageSidebarLink
href={item.href}
text={item.text}
type="external"
/>
<ChevronRight aria-hidden="true" className="shrink-0" />
</li>
))}
</ul>
</section>
)}
</aside>
)
}

/*
Article page from the 2026 redesign: header (breadcrumb, title, meta), the
article column, and a sticky aside (table of contents, recommended reading).
At 1440 the article column is 677px wide and the group is centred in the
space right of the sidebar card; below 1200 the aside drops under the
article and the table of contents is hidden.
*/
export const Article: FC<IArticleProps> = ({
relativePath,
basePath,
crumbs,
title,
authors,
createdAt,
timeToRead,
toc = [],
recommendedReading,
externalResources,
children,
after,
}) => {
return (
<div className="grid grid-cols-[minmax(0,677px)] justify-center px-5 pt-[100px] pb-16 md:px-8 lg:pt-[63px] min-[1200px]:grid-cols-[minmax(0,677px)_204px] min-[1200px]:gap-x-[clamp(40px,6vw,86px)]">
<header className="pb-10 md:pb-[60px] min-[1200px]:col-start-1">
<ArticleBreadcrumb
relativePath={relativePath}
basePath={basePath}
crumbs={crumbs}
/>
<h1 className="m-0 mt-[-1px] pl-[21px] font-header text-[48px] leading-[58.5px] font-bold tracking-[-0.75px] break-words text-main-fg max-md:pl-0 max-md:text-[36px] max-md:leading-[44px]">
{title}
</h1>
<ArticleMeta
authors={authors}
createdAt={createdAt}
timeToRead={timeToRead}
/>
</header>

<div className="pr-2.5 pl-[18px] max-md:px-0 min-[1200px]:col-start-1">
{children}
</div>

<ArticleAside
toc={toc}
recommendedReading={recommendedReading}
externalResources={externalResources}
/>

<div className="pr-2.5 pl-[18px] max-md:px-0 min-[1200px]:col-start-1">
{after}
<Footer />
</div>
</div>
)
}
Loading
Loading