Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(web): add docs route group with sidebar layout

Richie McIlroy52094115bebb
diff --git a/apps/web/app/(docs)/docs/[[...slug]]/page.tsx b/apps/web/app/(docs)/docs/[[...slug]]/page.tsx
new file mode 100644
index 000000000..2377500a6
--- /dev/null
+++ b/apps/web/app/(docs)/docs/[[...slug]]/page.tsx
@@ -0,0 +1,71 @@
+import { buildEnv } from "@cap/env";
+import type { Metadata } from "next";
+import { notFound } from "next/navigation";
+import { CustomMDX } from "@/components/mdx";
+import { extractHeadings, getDocBySlug } from "@/utils/docs";
+import { DocsBreadcrumbs } from "../_components/DocsBreadcrumbs";
+import { DocsPrevNext } from "../_components/DocsPrevNext";
+import { DocsTableOfContents } from "../_components/DocsTableOfContents";
+
+interface DocPageProps {
+ params: Promise<{ slug?: string[] }>;
+}
+
+export async function generateMetadata(
+ props: DocPageProps,
+): Promise<Metadata | undefined> {
+ const params = await props.params;
+ const slug = params.slug?.join("/") ?? "introduction";
+ const doc = getDocBySlug(slug);
+ if (!doc) return;
+
+ const { title, summary: description, image } = doc.metadata;
+ const ogImage = image ? `${buildEnv.NEXT_PUBLIC_WEB_URL}${image}` : undefined;
+
+ return {
+ title: `${title} - Cap Docs`,
+ description: description || title,
+ openGraph: {
+ title: `${title} - Cap Docs`,
+ description: description || title,
+ type: "article",
+ url: `${buildEnv.NEXT_PUBLIC_WEB_URL}/docs/${slug}`,
+ ...(ogImage && { images: [{ url: ogImage }] }),
+ },
+ };
+}
+
+export default async function DocPage(props: DocPageProps) {
+ const params = await props.params;
+ const slug = params.slug?.join("/") ?? "introduction";
+ const doc = getDocBySlug(slug);
+
+ if (!doc) {
+ notFound();
+ }
+
+ const headings = extractHeadings(doc.content);
+
+ return (
+ <div className="flex">
+ <div className="flex-1 min-w-0 max-w-3xl mx-auto px-6 sm:px-8 py-10">
+ <DocsBreadcrumbs currentSlug={slug} />
+ <article className="mt-4">
+ <h1 className="text-3xl font-bold tracking-tight text-gray-900 mb-2">
+ {doc.metadata.title}
+ </h1>
+ {doc.metadata.summary && (
+ <p className="text-lg text-gray-500 mb-8">{doc.metadata.summary}</p>
+ )}
+ <div className="prose prose-gray max-w-none prose-headings:scroll-mt-20 prose-headings:font-semibold prose-a:text-blue-600 prose-code:before:content-none prose-code:after:content-none prose-code:bg-gray-100 prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded prose-code:text-sm [&_pre]:rounded-lg [&_pre]:p-4 [&_pre]:overflow-x-auto [&_pre]:text-[13px] [&_pre]:leading-relaxed [&_pre_code]:bg-transparent [&_pre_code]:p-0 [&_pre_code]:text-[inherit] [&_iframe]:max-w-full [&_iframe]:w-full">
+ <CustomMDX source={doc.content} />
+ </div>
+ </article>
+ <DocsPrevNext currentSlug={slug} />
+ </div>
+ <div className="hidden xl:block w-[200px] shrink-0">
+ <DocsTableOfContents headings={headings} />
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/app/(docs)/docs/_components/DocsBreadcrumbs.tsx b/apps/web/app/(docs)/docs/_components/DocsBreadcrumbs.tsx
new file mode 100644
index 000000000..21f10affd
--- /dev/null
+++ b/apps/web/app/(docs)/docs/_components/DocsBreadcrumbs.tsx
@@ -0,0 +1,43 @@
+import { ChevronRight } from "lucide-react";
+import Link from "next/link";
+import { getBreadcrumbs } from "../docs-config";
+
+interface DocsBreadcrumbsProps {
+ currentSlug: string;
+}
+
+export function DocsBreadcrumbs({ currentSlug }: DocsBreadcrumbsProps) {
+ const breadcrumbs = getBreadcrumbs(currentSlug);
+
+ return (
+ <nav
+ className="flex items-center gap-1 text-sm mb-6"
+ aria-label="Breadcrumb"
+ >
+ {breadcrumbs.map((crumb, index) => {
+ const isLast = index === breadcrumbs.length - 1;
+
+ return (
+ <span
+ key={crumb.slug + crumb.title}
+ className="flex items-center gap-1"
+ >
+ {index > 0 && (
+ <ChevronRight className="w-3.5 h-3.5 text-gray-300 shrink-0" />
+ )}
+ {isLast ? (
+ <span className="text-gray-700 font-medium">{crumb.title}</span>
+ ) : (
+ <Link
+ href={crumb.slug ? `/docs/${crumb.slug}` : "/docs"}
+ className="text-gray-400 hover:text-gray-600 transition-colors"
+ >
+ {crumb.title}
+ </Link>
+ )}
+ </span>
+ );
+ })}
+ </nav>
+ );
+}
diff --git a/apps/web/app/(docs)/docs/_components/DocsHeader.tsx b/apps/web/app/(docs)/docs/_components/DocsHeader.tsx
new file mode 100644
index 000000000..0d33b3bc3
--- /dev/null
+++ b/apps/web/app/(docs)/docs/_components/DocsHeader.tsx
@@ -0,0 +1,113 @@
+"use client";
+
+import { Logo } from "@cap/ui";
+import { ExternalLink, Menu, Search } from "lucide-react";
+import Link from "next/link";
+import { useEffect, useState } from "react";
+
+function useOS() {
+ const [isMac, setIsMac] = useState(true);
+
+ useEffect(() => {
+ setIsMac(navigator.platform.toUpperCase().indexOf("MAC") >= 0);
+ }, []);
+
+ return { isMac };
+}
+
+export function DocsHeader() {
+ const { isMac } = useOS();
+
+ const handleSearchClick = () => {
+ window.dispatchEvent(new CustomEvent("open-docs-search"));
+ };
+
+ const handleMobileMenuClick = () => {
+ window.dispatchEvent(new CustomEvent("open-docs-mobile-menu"));
+ };
+
+ useEffect(() => {
+ const handleKeyDown = (e: KeyboardEvent) => {
+ if ((e.metaKey || e.ctrlKey) && e.key === "k") {
+ e.preventDefault();
+ window.dispatchEvent(new CustomEvent("open-docs-search"));
+ }
+ };
+ window.addEventListener("keydown", handleKeyDown);
+ return () => window.removeEventListener("keydown", handleKeyDown);
+ }, []);
+
+ return (
+ <header className="fixed top-0 left-0 right-0 z-50 flex items-center justify-between h-14 px-4 bg-white border-b border-gray-200">
+ <div className="flex items-center gap-3">
+ <button
+ type="button"
+ onClick={handleMobileMenuClick}
+ className="lg:hidden flex items-center justify-center w-8 h-8 rounded-md text-gray-500 hover:text-gray-900 hover:bg-gray-100 transition-colors"
+ aria-label="Open menu"
+ >
+ <Menu className="w-5 h-5" />
+ </button>
+ <Link href="/" className="flex items-center">
+ <Logo className="h-5 w-auto" />
+ </Link>
+ <span className="text-sm font-semibold text-gray-400">/</span>
+ <Link
+ href="/docs"
+ className="text-sm font-semibold text-gray-900 hover:text-gray-700 transition-colors"
+ >
+ Docs
+ </Link>
+ </div>
+
+ <button
+ type="button"
+ onClick={handleSearchClick}
+ className="hidden sm:flex items-center gap-2 h-8 px-3 rounded-lg border border-gray-200 bg-gray-50 text-sm text-gray-500 hover:border-gray-300 hover:bg-gray-100 transition-colors cursor-pointer min-w-[240px]"
+ >
+ <Search className="w-3.5 h-3.5 text-gray-400" />
+ <span className="flex-1 text-left">Search docs...</span>
+ <kbd className="hidden md:inline-flex items-center gap-0.5 rounded bg-white border border-gray-200 px-1.5 py-0.5 text-[11px] font-medium text-gray-400">
+ {isMac ? "\u2318" : "Ctrl"}K
+ </kbd>
+ </button>
+
+ <div className="flex items-center gap-3">
+ <button
+ type="button"
+ onClick={handleSearchClick}
+ className="sm:hidden flex items-center justify-center w-8 h-8 rounded-md text-gray-500 hover:text-gray-900 hover:bg-gray-100 transition-colors"
+ aria-label="Search"
+ >
+ <Search className="w-4 h-4" />
+ </button>
+ <Link
+ href="https://cap.so"
+ target="_blank"
+ rel="noopener noreferrer"
+ className="hidden sm:flex items-center gap-1 text-sm text-gray-500 hover:text-gray-900 transition-colors"
+ >
+ cap.so
+ <ExternalLink className="w-3 h-3" />
+ </Link>
+ <Link
+ href="https://github.com/CapSoftware/Cap"
+ target="_blank"
+ rel="noopener noreferrer"
+ className="flex items-center text-gray-500 hover:text-gray-900 transition-colors"
+ >
+ <svg
+ viewBox="0 0 24 24"
+ fill="currentColor"
+ className="w-5 h-5"
+ role="img"
+ aria-label="GitHub"
+ >
+ <title>GitHub</title>
+ <path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z" />
+ </svg>
+ </Link>
+ </div>
+ </header>
+ );
+}
diff --git a/apps/web/app/(docs)/docs/_components/DocsMobileMenu.tsx b/apps/web/app/(docs)/docs/_components/DocsMobileMenu.tsx
new file mode 100644
index 000000000..f4429b4b4
--- /dev/null
+++ b/apps/web/app/(docs)/docs/_components/DocsMobileMenu.tsx
@@ -0,0 +1,100 @@
+"use client";
+
+import { X } from "lucide-react";
+import Link from "next/link";
+import { usePathname } from "next/navigation";
+import { useEffect, useRef, useState } from "react";
+import { docsConfig, type SidebarGroup } from "../docs-config";
+
+export function DocsMobileMenu() {
+ const [isOpen, setIsOpen] = useState(false);
+ const pathname = usePathname();
+ const prevPathname = useRef(pathname);
+
+ useEffect(() => {
+ const handleOpen = () => setIsOpen(true);
+ window.addEventListener("open-docs-mobile-menu", handleOpen);
+ return () =>
+ window.removeEventListener("open-docs-mobile-menu", handleOpen);
+ }, []);
+
+ useEffect(() => {
+ if (prevPathname.current !== pathname) {
+ setIsOpen(false);
+ prevPathname.current = pathname;
+ }
+ }, [pathname]);
+
+ useEffect(() => {
+ if (isOpen) {
+ document.body.style.overflow = "hidden";
+ } else {
+ document.body.style.overflow = "";
+ }
+ return () => {
+ document.body.style.overflow = "";
+ };
+ }, [isOpen]);
+
+ const isActive = (slug: string) => {
+ return pathname === `/docs/${slug}` || pathname === `/docs/${slug}/`;
+ };
+
+ if (!isOpen) return null;
+
+ return (
+ <div className="fixed inset-0 z-50 lg:hidden">
+ <button
+ type="button"
+ className="absolute inset-0 bg-black/40 cursor-default"
+ onClick={() => setIsOpen(false)}
+ aria-label="Close menu"
+ />
+ <div className="absolute top-0 left-0 bottom-0 w-[280px] bg-white shadow-xl overflow-y-auto">
+ <div className="flex items-center justify-between h-14 px-4 border-b border-gray-200">
+ <span className="text-sm font-semibold text-gray-900">
+ Documentation
+ </span>
+ <button
+ type="button"
+ onClick={() => setIsOpen(false)}
+ className="flex items-center justify-center w-8 h-8 rounded-md text-gray-500 hover:text-gray-900 hover:bg-gray-100 transition-colors"
+ aria-label="Close menu"
+ >
+ <X className="w-5 h-5" />
+ </button>
+ </div>
+ <nav className="px-4 py-6">
+ <div className="flex flex-col gap-6">
+ {docsConfig.sidebar.map((group: SidebarGroup) => (
+ <div key={group.title}>
+ <h4 className="px-3 mb-2 text-[11px] font-semibold uppercase tracking-wider text-gray-400">
+ {group.title}
+ </h4>
+ <ul className="flex flex-col gap-0.5">
+ {group.items.map((item) => {
+ const active = isActive(item.slug);
+ return (
+ <li key={item.slug}>
+ <Link
+ href={`/docs/${item.slug}`}
+ className={`block text-[13px] font-medium py-1.5 px-3 rounded-md transition-colors ${
+ active
+ ? "text-blue-500 bg-blue-50 border-l-2 border-blue-500"
+ : "text-gray-600 hover:text-gray-900 hover:bg-gray-50"
+ }`}
+ >
+ {item.title}
+ </Link>
+ </li>
+ );
+ })}
+ </ul>
+ </div>
+ ))}
+ </div>
+ </nav>
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/app/(docs)/docs/_components/DocsPrevNext.tsx b/apps/web/app/(docs)/docs/_components/DocsPrevNext.tsx
new file mode 100644
index 000000000..e41482a4b
--- /dev/null
+++ b/apps/web/app/(docs)/docs/_components/DocsPrevNext.tsx
@@ -0,0 +1,54 @@
+import { ChevronLeft, ChevronRight } from "lucide-react";
+import Link from "next/link";
+import { getAdjacentDocs } from "../docs-config";
+
+interface DocsPrevNextProps {
+ currentSlug: string;
+}
+
+export function DocsPrevNext({ currentSlug }: DocsPrevNextProps) {
+ const { prev, next } = getAdjacentDocs(currentSlug);
+
+ if (!prev && !next) return null;
+
+ return (
+ <div className="flex items-stretch justify-between gap-4 mt-12 pt-6 border-t border-gray-200">
+ {prev ? (
+ <Link
+ href={`/docs/${prev.slug}`}
+ className="group flex items-center gap-3 flex-1 px-4 py-3 rounded-lg border border-gray-200 hover:border-gray-300 hover:bg-gray-50 transition-colors"
+ >
+ <ChevronLeft className="w-4 h-4 text-gray-400 group-hover:text-gray-600 transition-colors shrink-0" />
+ <div className="flex flex-col">
+ <span className="text-[11px] font-medium text-gray-400 uppercase tracking-wide">
+ Previous
+ </span>
+ <span className="text-sm font-medium text-gray-700 group-hover:text-gray-900 transition-colors">
+ {prev.title}
+ </span>
+ </div>
+ </Link>
+ ) : (
+ <div className="flex-1" />
+ )}
+ {next ? (
+ <Link
+ href={`/docs/${next.slug}`}
+ className="group flex items-center justify-end gap-3 flex-1 px-4 py-3 rounded-lg border border-gray-200 hover:border-gray-300 hover:bg-gray-50 transition-colors text-right"
+ >
+ <div className="flex flex-col items-end">
+ <span className="text-[11px] font-medium text-gray-400 uppercase tracking-wide">
+ Next
+ </span>
+ <span className="text-sm font-medium text-gray-700 group-hover:text-gray-900 transition-colors">
+ {next.title}
+ </span>
+ </div>
+ <ChevronRight className="w-4 h-4 text-gray-400 group-hover:text-gray-600 transition-colors shrink-0" />
+ </Link>
+ ) : (
+ <div className="flex-1" />
+ )}
+ </div>
+ );
+}
diff --git a/apps/web/app/(docs)/docs/_components/DocsSearch.tsx b/apps/web/app/(docs)/docs/_components/DocsSearch.tsx
new file mode 100644
index 000000000..56eed6368
--- /dev/null
+++ b/apps/web/app/(docs)/docs/_components/DocsSearch.tsx
@@ -0,0 +1,323 @@
+"use client";
+
+import { FileText, Search } from "lucide-react";
+import { useRouter } from "next/navigation";
+import {
+ useCallback,
+ useEffect,
+ useId,
+ useMemo,
+ useRef,
+ useState,
+} from "react";
+
+interface SearchItem {
+ slug: string;
+ title: string;
+ summary: string;
+ content: string;
+ group: string;
+}
+
+interface DocsSearchProps {
+ searchIndex: SearchItem[];
+}
+
+interface GroupedResults {
+ group: string;
+ items: SearchItem[];
+}
+
+function groupResults(items: SearchItem[]): GroupedResults[] {
+ const map = new Map<string, SearchItem[]>();
+ for (const item of items) {
+ const existing = map.get(item.group);
+ if (existing) {
+ existing.push(item);
+ } else {
+ map.set(item.group, [item]);
+ }
+ }
+ return Array.from(map.entries()).map(([group, items]) => ({
+ group,
+ items,
+ }));
+}
+
+function truncateSummary(text: string, maxLength = 120): string {
+ if (text.length <= maxLength) return text;
+ return `${text.slice(0, maxLength).trimEnd()}...`;
+}
+
+export function DocsSearch({ searchIndex }: DocsSearchProps) {
+ const [isOpen, setIsOpen] = useState(false);
+ const [query, setQuery] = useState("");
+ const [activeIndex, setActiveIndex] = useState(0);
+ const [isAnimating, setIsAnimating] = useState(false);
+ const router = useRouter();
+ const inputRef = useRef<HTMLInputElement>(null);
+ const resultsRef = useRef<HTMLDivElement>(null);
+ const activeItemRef = useRef<HTMLButtonElement>(null);
+ const instanceId = useId();
+ const resultsId = `${instanceId}-docs-search-results`;
+ const prevQueryRef = useRef(query);
+ const prevActiveIndexRef = useRef(activeIndex);
+
+ const filteredResults = useMemo(() => {
+ if (!query.trim()) return [];
+ const lowerQuery = query.toLowerCase();
+ return searchIndex.filter(
+ (item) =>
+ item.title.toLowerCase().includes(lowerQuery) ||
+ item.summary.toLowerCase().includes(lowerQuery) ||
+ item.content.toLowerCase().includes(lowerQuery),
+ );
+ }, [query, searchIndex]);
+
+ const grouped = useMemo(
+ () => groupResults(filteredResults),
+ [filteredResults],
+ );
+
+ const flatResults = useMemo(() => grouped.flatMap((g) => g.items), [grouped]);
+
+ const open = useCallback(() => {
+ setIsOpen(true);
+ setQuery("");
+ setActiveIndex(0);
+ requestAnimationFrame(() => {
+ setIsAnimating(true);
+ inputRef.current?.focus();
+ });
+ }, []);
+
+ const close = useCallback(() => {
+ setIsAnimating(false);
+ const timeout = setTimeout(() => {
+ setIsOpen(false);
+ setQuery("");
+ setActiveIndex(0);
+ }, 150);
+ return () => clearTimeout(timeout);
+ }, []);
+
+ const navigateTo = useCallback(
+ (slug: string) => {
+ close();
+ router.push(`/docs/${slug}`);
+ },
+ [close, router],
+ );
+
+ useEffect(() => {
+ const handleCustomEvent = () => open();
+ window.addEventListener("open-docs-search", handleCustomEvent);
+ return () =>
+ window.removeEventListener("open-docs-search", handleCustomEvent);
+ }, [open]);
+
+ useEffect(() => {
+ if (!isOpen) return;
+
+ const handleKeyDown = (e: KeyboardEvent) => {
+ if (e.key === "Escape") {
+ e.preventDefault();
+ close();
+ return;
+ }
+
+ if (e.key === "ArrowDown") {
+ e.preventDefault();
+ setActiveIndex((prev) =>
+ prev < flatResults.length - 1 ? prev + 1 : 0,
+ );
+ return;
+ }
+
+ if (e.key === "ArrowUp") {
+ e.preventDefault();
+ setActiveIndex((prev) =>
+ prev > 0 ? prev - 1 : flatResults.length - 1,
+ );
+ return;
+ }
+
+ if (e.key === "Enter") {
+ e.preventDefault();
+ const selected = flatResults[activeIndex];
+ if (selected) {
+ navigateTo(selected.slug);
+ }
+ }
+ };
+
+ window.addEventListener("keydown", handleKeyDown);
+ return () => window.removeEventListener("keydown", handleKeyDown);
+ }, [isOpen, flatResults, activeIndex, close, navigateTo]);
+
+ if (prevQueryRef.current !== query) {
+ prevQueryRef.current = query;
+ setActiveIndex(0);
+ }
+
+ if (prevActiveIndexRef.current !== activeIndex) {
+ prevActiveIndexRef.current = activeIndex;
+ activeItemRef.current?.scrollIntoView({ block: "nearest" });
+ }
+
+ useEffect(() => {
+ if (isOpen) {
+ document.body.style.overflow = "hidden";
+ } else {
+ document.body.style.overflow = "";
+ }
+ return () => {
+ document.body.style.overflow = "";
+ };
+ }, [isOpen]);
+
+ if (!isOpen) return null;
+
+ let flatIndex = -1;
+
+ return (
+ <div className="fixed inset-0 z-[60] flex items-start justify-center pt-[min(20vh,120px)]">
+ <button
+ type="button"
+ className={`absolute inset-0 bg-black/30 transition-opacity duration-150 cursor-default ${
+ isAnimating ? "opacity-100" : "opacity-0"
+ }`}
+ onClick={close}
+ aria-label="Close search"
+ tabIndex={-1}
+ />
+
+ <div
+ className={`relative w-full max-w-xl mx-4 bg-white rounded-xl shadow-2xl overflow-hidden transition-all duration-150 ${
+ isAnimating
+ ? "opacity-100 scale-100 translate-y-0"
+ : "opacity-0 scale-[0.98] -translate-y-2"
+ }`}
+ role="dialog"
+ aria-modal="true"
+ aria-label="Search documentation"
+ >
+ <div className="flex items-center gap-3 px-4 border-b border-gray-200">
+ <Search className="w-4.5 h-4.5 text-gray-400 shrink-0" />
+ <input
+ ref={inputRef}
+ type="text"
+ value={query}
+ onChange={(e) => setQuery(e.target.value)}
+ placeholder="Search documentation..."
+ className="flex-1 h-14 text-base text-gray-900 placeholder-gray-400 outline-none bg-transparent"
+ aria-label="Search documentation"
+ aria-autocomplete="list"
+ aria-controls={resultsId}
+ aria-activedescendant={
+ flatResults[activeIndex]
+ ? `${instanceId}-item-${flatResults[activeIndex].slug}`
+ : undefined
+ }
+ />
+ <kbd className="shrink-0 inline-flex items-center rounded bg-gray-100 border border-gray-200 px-1.5 py-0.5 text-[11px] font-medium text-gray-400 select-none">
+ ESC
+ </kbd>
+ </div>
+
+ <div
+ ref={resultsRef}
+ id={resultsId}
+ role="listbox"
+ className="max-h-[400px] overflow-y-auto overscroll-contain"
+ >
+ {!query.trim() && (
+ <div className="flex flex-col items-center justify-center py-12 px-4">
+ <Search className="w-8 h-8 text-gray-300 mb-3" />
+ <p className="text-sm text-gray-400">Start typing to search...</p>
+ </div>
+ )}
+
+ {query.trim() && flatResults.length === 0 && (
+ <div className="flex flex-col items-center justify-center py-12 px-4">
+ <Search className="w-8 h-8 text-gray-300 mb-3" />
+ <p className="text-sm text-gray-500">
+ No results found for &ldquo;{query}&rdquo;
+ </p>
+ </div>
+ )}
+
+ {grouped.map((group) => (
+ <div key={group.group} className="py-2">
+ <div className="px-4 py-1.5">
+ <span className="text-[11px] font-semibold uppercase tracking-wider text-gray-400">
+ {group.group}
+ </span>
+ </div>
+ {group.items.map((item) => {
+ flatIndex++;
+ const isActive = flatIndex === activeIndex;
+ const currentIndex = flatIndex;
+ return (
+ <button
+ key={item.slug}
+ ref={isActive ? activeItemRef : undefined}
+ id={`${instanceId}-item-${item.slug}`}
+ role="option"
+ aria-selected={isActive}
+ type="button"
+ className={`w-full flex items-start gap-3 px-4 py-2.5 text-left transition-colors duration-75 cursor-pointer ${
+ isActive ? "bg-blue-50" : "hover:bg-gray-50"
+ }`}
+ onClick={() => navigateTo(item.slug)}
+ onMouseEnter={() => setActiveIndex(currentIndex)}
+ >
+ <FileText
+ className={`w-4 h-4 mt-0.5 shrink-0 ${
+ isActive ? "text-blue-500" : "text-gray-400"
+ }`}
+ />
+ <div className="min-w-0 flex-1">
+ <div
+ className={`text-sm font-medium truncate ${
+ isActive ? "text-blue-900" : "text-gray-900"
+ }`}
+ >
+ {item.title}
+ </div>
+ {item.summary && (
+ <div className="text-xs text-gray-500 mt-0.5 truncate">
+ {truncateSummary(item.summary)}
+ </div>
+ )}
+ </div>
+ </button>
+ );
+ })}
+ </div>
+ ))}
+ </div>
+
+ {flatResults.length > 0 && (
+ <div className="flex items-center gap-4 px-4 py-2.5 border-t border-gray-200 bg-gray-50">
+ <span className="flex items-center gap-1.5 text-[11px] text-gray-400">
+ <kbd className="inline-flex items-center justify-center w-5 h-5 rounded bg-white border border-gray-200 text-[10px] font-medium">
+ ↑
+ </kbd>
+ <kbd className="inline-flex items-center justify-center w-5 h-5 rounded bg-white border border-gray-200 text-[10px] font-medium">
+ ↓
+ </kbd>
+ <span>to navigate</span>
+ </span>
+ <span className="flex items-center gap-1.5 text-[11px] text-gray-400">
+ <kbd className="inline-flex items-center justify-center h-5 px-1.5 rounded bg-white border border-gray-200 text-[10px] font-medium">
+ ↵
+ </kbd>
+ <span>to select</span>
+ </span>
+ </div>
+ )}
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/app/(docs)/docs/_components/DocsSidebar.tsx b/apps/web/app/(docs)/docs/_components/DocsSidebar.tsx
new file mode 100644
index 000000000..1e028a3e2
--- /dev/null
+++ b/apps/web/app/(docs)/docs/_components/DocsSidebar.tsx
@@ -0,0 +1,46 @@
+"use client";
+
+import Link from "next/link";
+import { usePathname } from "next/navigation";
+import { docsConfig, type SidebarGroup } from "../docs-config";
+
+export function DocsSidebar() {
+ const pathname = usePathname();
+
+ const isActive = (slug: string) => {
+ return pathname === `/docs/${slug}` || pathname === `/docs/${slug}/`;
+ };
+
+ return (
+ <nav className="sticky top-14 h-[calc(100vh-56px)] w-[260px] shrink-0 overflow-y-auto border-r border-gray-200 px-4 py-6">
+ <div className="flex flex-col gap-6">
+ {docsConfig.sidebar.map((group: SidebarGroup) => (
+ <div key={group.title}>
+ <h4 className="px-3 mb-2 text-[11px] font-semibold uppercase tracking-wider text-gray-400">
+ {group.title}
+ </h4>
+ <ul className="flex flex-col gap-0.5">
+ {group.items.map((item) => {
+ const active = isActive(item.slug);
+ return (
+ <li key={item.slug}>
+ <Link
+ href={`/docs/${item.slug}`}
+ className={`block text-[13px] font-medium py-1.5 px-3 rounded-md transition-colors ${
+ active
+ ? "text-blue-500 bg-blue-50 border-l-2 border-blue-500"
+ : "text-gray-600 hover:text-gray-900 hover:bg-gray-50"
+ }`}
+ >
+ {item.title}
+ </Link>
+ </li>
+ );
+ })}
+ </ul>
+ </div>
+ ))}
+ </div>
+ </nav>
+ );
+}
diff --git a/apps/web/app/(docs)/docs/_components/DocsTableOfContents.tsx b/apps/web/app/(docs)/docs/_components/DocsTableOfContents.tsx
new file mode 100644
index 000000000..7a677ed83
--- /dev/null
+++ b/apps/web/app/(docs)/docs/_components/DocsTableOfContents.tsx
@@ -0,0 +1,84 @@
+"use client";
+
+import { useEffect, useState } from "react";
+
+interface Heading {
+ level: number;
+ text: string;
+ slug: string;
+}
+
+interface DocsTableOfContentsProps {
+ headings: Heading[];
+}
+
+export function DocsTableOfContents({ headings }: DocsTableOfContentsProps) {
+ const [activeSlug, setActiveSlug] = useState<string>("");
+
+ useEffect(() => {
+ if (headings.length === 0) return;
+
+ const slugs = headings.map((h) => h.slug);
+ const elements = slugs
+ .map((slug) => document.getElementById(slug))
+ .filter(Boolean) as HTMLElement[];
+
+ if (elements.length === 0) return;
+
+ const observer = new IntersectionObserver(
+ (entries) => {
+ const visibleEntries = entries.filter((entry) => entry.isIntersecting);
+ if (visibleEntries.length > 0) {
+ const topEntry = visibleEntries.reduce((prev, curr) =>
+ prev.boundingClientRect.top < curr.boundingClientRect.top
+ ? prev
+ : curr,
+ );
+ setActiveSlug(topEntry.target.id);
+ }
+ },
+ {
+ rootMargin: "-80px 0px -60% 0px",
+ threshold: 0,
+ },
+ );
+
+ for (const el of elements) {
+ observer.observe(el);
+ }
+
+ return () => observer.disconnect();
+ }, [headings]);
+
+ const filteredHeadings = headings.filter(
+ (h) => h.level === 2 || h.level === 3,
+ );
+
+ if (filteredHeadings.length === 0) return null;
+
+ return (
+ <div className="hidden xl:block sticky top-[80px] w-[200px] shrink-0 max-h-[calc(100vh-100px)] overflow-y-auto">
+ <h4 className="text-[11px] font-semibold uppercase tracking-wider text-gray-400 mb-3">
+ On this page
+ </h4>
+ <ul className="flex flex-col gap-1">
+ {filteredHeadings.map((heading, index) => (
+ <li key={`${heading.slug}-${index}`}>
+ <a
+ href={`#${heading.slug}`}
+ className={`block text-[13px] py-1 transition-colors ${
+ heading.level === 3 ? "pl-3" : ""
+ } ${
+ activeSlug === heading.slug
+ ? "text-blue-500 font-medium"
+ : "text-gray-500 hover:text-gray-700"
+ }`}
+ >
+ {heading.text}
+ </a>
+ </li>
+ ))}
+ </ul>
+ </div>
+ );
+}
diff --git a/apps/web/app/(docs)/docs/docs-config.ts b/apps/web/app/(docs)/docs/docs-config.ts
new file mode 100644
index 000000000..48fa2b2d8
--- /dev/null
+++ b/apps/web/app/(docs)/docs/docs-config.ts
@@ -0,0 +1,89 @@
+export interface SidebarLink {
+ title: string;
+ slug: string;
+}
+
+export interface SidebarGroup {
+ title: string;
+ items: SidebarLink[];
+}
+
+export const docsConfig = {
+ sidebar: [
+ {
+ title: "Getting Started",
+ items: [
+ { title: "Introduction", slug: "introduction" },
+ { title: "Installation", slug: "installation" },
+ { title: "Quickstart", slug: "quickstart" },
+ ],
+ },
+ {
+ title: "Recording",
+ items: [
+ { title: "Instant Mode", slug: "recording/instant-mode" },
+ { title: "Studio Mode", slug: "recording/studio-mode" },
+ { title: "Camera & Microphone", slug: "recording/camera-and-mic" },
+ {
+ title: "Keyboard Shortcuts",
+ slug: "recording/keyboard-shortcuts",
+ },
+ ],
+ },
+ {
+ title: "Sharing & Playback",
+ items: [
+ { title: "Share a Cap", slug: "sharing/share-a-cap" },
+ { title: "Embeds", slug: "sharing/embeds" },
+ { title: "Comments", slug: "sharing/comments" },
+ { title: "Analytics", slug: "sharing/analytics" },
+ ],
+ },
+ {
+ title: "Self-hosting",
+ items: [
+ { title: "Overview", slug: "self-hosting" },
+ { title: "S3: AWS", slug: "s3-config/aws-s3" },
+ { title: "S3: Cloudflare R2", slug: "s3-config/cloudflare-r2" },
+ ],
+ },
+ {
+ title: "API & Developers",
+ items: [
+ { title: "REST API", slug: "api/rest-api" },
+ { title: "Webhooks", slug: "api/webhooks" },
+ ],
+ },
+ {
+ title: "Legal",
+ items: [{ title: "Commercial License", slug: "commercial-license" }],
+ },
+ ] satisfies SidebarGroup[],
+};
+
+export function flattenSidebar(): SidebarLink[] {
+ return docsConfig.sidebar.flatMap((group) => group.items);
+}
+
+export function getAdjacentDocs(currentSlug: string) {
+ const flat = flattenSidebar();
+ const idx = flat.findIndex((item) => item.slug === currentSlug);
+ return {
+ prev: idx > 0 ? flat[idx - 1] : null,
+ next: idx < flat.length - 1 ? flat[idx + 1] : null,
+ };
+}
+
+export function getBreadcrumbs(currentSlug: string) {
+ for (const group of docsConfig.sidebar) {
+ const item = group.items.find((i) => i.slug === currentSlug);
+ if (item) {
+ return [
+ { title: "Docs", slug: "" },
+ { title: group.title, slug: group.items[0]?.slug ?? "" },
+ { title: item.title, slug: item.slug },
+ ];
+ }
+ }
+ return [{ title: "Docs", slug: "" }];
+}
diff --git a/apps/web/app/(docs)/docs/layout.tsx b/apps/web/app/(docs)/docs/layout.tsx
new file mode 100644
index 000000000..854ba586a
--- /dev/null
+++ b/apps/web/app/(docs)/docs/layout.tsx
@@ -0,0 +1,25 @@
+import type { PropsWithChildren } from "react";
+import { getDocSearchIndex } from "@/utils/docs";
+import { DocsHeader } from "./_components/DocsHeader";
+import { DocsMobileMenu } from "./_components/DocsMobileMenu";
+import { DocsSearch } from "./_components/DocsSearch";
+import { DocsSidebar } from "./_components/DocsSidebar";
+import { docsConfig } from "./docs-config";
+
+export default function DocsLayout(props: PropsWithChildren) {
+ const searchIndex = getDocSearchIndex(docsConfig.sidebar);
+
+ return (
+ <div className="min-h-screen bg-white">
+ <DocsHeader />
+ <DocsSearch searchIndex={searchIndex} />
+ <div className="flex pt-14">
+ <aside className="hidden lg:block w-[260px] shrink-0">
+ <DocsSidebar />
+ </aside>
+ <DocsMobileMenu />
+ <main className="flex-1 min-w-0">{props.children}</main>
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/app/(docs)/layout.tsx b/apps/web/app/(docs)/layout.tsx
new file mode 100644
index 000000000..3d1a59d32
--- /dev/null
+++ b/apps/web/app/(docs)/layout.tsx
@@ -0,0 +1,5 @@
+import type { PropsWithChildren } from "react";
+
+export default function DocsRootLayout(props: PropsWithChildren) {
+ return <>{props.children}</>;
+}