Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
240 changes: 126 additions & 114 deletions packages/docs/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { PageMeta } from "./pageMeta.js";
import { route } from "@funstack/router/server";
import { defer } from "@funstack/static/server";
import { Layout } from "./components/Layout.js";
import { DocsLayout } from "./components/DocsLayout.js";
import { ApiReferencePage } from "./pages/ApiReferencePage.js";
import { LearnPage } from "./pages/LearnPage.js";
import { ClientApp } from "./ClientApp.js";
Expand Down Expand Up @@ -142,160 +143,171 @@ export const routes = [
component: defer(withMeta("/", <HomePage />), { name: "HomePage" }),
}),
route({
path: "/getting-started",
component: defer(withMeta("/getting-started", <GettingStartedPage />), {
name: "GettingStartedPage",
}),
}),
route({
path: "/learn",
component: LearnPage,
component: <DocsLayout />,
children: [
route({
path: "/",
component: defer(withMeta("/learn", <LearnIndexPage />), {
name: "LearnIndexPage",
}),
}),
route({
path: "/navigation-api",
component: defer(withMeta("/learn/navigation-api", <LearnNavigationApiPage />), {
name: "LearnNavigationApiPage",
path: "/getting-started",
component: defer(withMeta("/getting-started", <GettingStartedPage />), {
name: "GettingStartedPage",
}),
}),
route({
path: "/nested-routes",
component: defer(withMeta("/learn/nested-routes", <LearnNestedRoutesPage />), {
name: "LearnNestedRoutesPage",
}),
}),
route({
path: "/type-safety",
component: defer(withMeta("/learn/type-safety", <LearnTypeSafetyPage />), {
name: "LearnTypeSafetyPage",
}),
}),
route({
path: "/ssr",
component: <Outlet />,
path: "/learn",
component: LearnPage,
children: [
route({
path: "/",
component: defer(withMeta("/learn/ssr", <LearnSsrBasicPage />), {
name: "LearnSsrBasicPage",
component: defer(withMeta("/learn", <LearnIndexPage />), {
name: "LearnIndexPage",
}),
}),
route({
path: "/static-site-generation",
path: "/navigation-api",
component: defer(
withMeta("/learn/ssr/static-site-generation", <LearnSsgPage />),
withMeta("/learn/navigation-api", <LearnNavigationApiPage />),
{
name: "LearnSsgPage",
name: "LearnNavigationApiPage",
},
),
}),
route({
path: "/with-loaders",
path: "/nested-routes",
component: defer(withMeta("/learn/nested-routes", <LearnNestedRoutesPage />), {
name: "LearnNestedRoutesPage",
}),
}),
route({
path: "/type-safety",
component: defer(withMeta("/learn/type-safety", <LearnTypeSafetyPage />), {
name: "LearnTypeSafetyPage",
}),
}),
route({
path: "/ssr",
component: <Outlet />,
children: [
route({
path: "/",
component: defer(withMeta("/learn/ssr", <LearnSsrBasicPage />), {
name: "LearnSsrBasicPage",
}),
}),
route({
path: "/static-site-generation",
component: defer(
withMeta("/learn/ssr/static-site-generation", <LearnSsgPage />),
{
name: "LearnSsgPage",
},
),
}),
route({
path: "/with-loaders",
component: defer(
withMeta("/learn/ssr/with-loaders", <LearnSsrWithLoadersPage />),
{
name: "LearnSsrWithLoadersPage",
},
),
}),
],
}),
route({
path: "/rsc",
component: <Outlet />,
children: [
route({
path: "/",
component: defer(withMeta("/learn/rsc", <LearnRscPage />), {
name: "LearnRscPage",
}),
}),
route({
path: "/route-features",
component: defer(
withMeta("/learn/rsc/route-features", <LearnRouteDefinitionsPage />),
{
name: "LearnRouteDefinitionsPage",
},
),
}),
],
}),
route({
path: "/actions",
component: defer(withMeta("/learn/actions", <LearnActionsPage />), {
name: "LearnActionsPage",
}),
}),
route({
path: "/error-handling",
component: defer(
withMeta("/learn/ssr/with-loaders", <LearnSsrWithLoadersPage />),
withMeta("/learn/error-handling", <LearnErrorHandlingPage />),
{
name: "LearnSsrWithLoadersPage",
name: "LearnErrorHandlingPage",
},
),
}),
route({
path: "/transitions",
component: defer(withMeta("/learn/transitions", <LearnTransitionsPage />), {
name: "LearnTransitionsPage",
}),
}),
route({
path: "/loaders",
component: defer(withMeta("/learn/loaders", <LearnLoadersPage />), {
name: "LearnLoadersPage",
}),
}),
],
}),
route({
path: "/rsc",
component: <Outlet />,
path: "/api",
component: ApiReferencePage,
children: [
route({
path: "/",
component: defer(withMeta("/learn/rsc", <LearnRscPage />), {
name: "LearnRscPage",
component: defer(withMeta("/api", <ApiReferenceIndexPage />), {
name: "ApiReferenceIndexPage",
}),
}),
route({
path: "/route-features",
component: defer(
withMeta("/learn/rsc/route-features", <LearnRouteDefinitionsPage />),
{
name: "LearnRouteDefinitionsPage",
},
),
path: "/components",
component: defer(withMeta("/api/components", <ApiComponentsPage />), {
name: "ApiComponentsPage",
}),
}),
route({
path: "/hooks",
component: defer(withMeta("/api/hooks", <ApiHooksPage />), {
name: "ApiHooksPage",
}),
}),
route({
path: "/utilities",
component: defer(withMeta("/api/utilities", <ApiUtilitiesPage />), {
name: "ApiUtilitiesPage",
}),
}),
route({
path: "/types",
component: defer(withMeta("/api/types", <ApiTypesPage />), {
name: "ApiTypesPage",
}),
}),
],
}),
route({
path: "/actions",
component: defer(withMeta("/learn/actions", <LearnActionsPage />), {
name: "LearnActionsPage",
}),
path: "/examples",
component: defer(withMeta("/examples", <ExamplesPage />), { name: "ExamplesPage" }),
}),
route({
path: "/error-handling",
component: defer(withMeta("/learn/error-handling", <LearnErrorHandlingPage />), {
name: "LearnErrorHandlingPage",
}),
}),
route({
path: "/transitions",
component: defer(withMeta("/learn/transitions", <LearnTransitionsPage />), {
name: "LearnTransitionsPage",
}),
}),
route({
path: "/loaders",
component: defer(withMeta("/learn/loaders", <LearnLoadersPage />), {
name: "LearnLoadersPage",
}),
path: "/faq",
component: defer(withMeta("/faq", <FaqPage />), { name: "FaqPage" }),
}),
],
}),
route({
path: "/api",
component: ApiReferencePage,
children: [
route({
path: "/",
component: defer(withMeta("/api", <ApiReferenceIndexPage />), {
name: "ApiReferenceIndexPage",
}),
}),
route({
path: "/components",
component: defer(withMeta("/api/components", <ApiComponentsPage />), {
name: "ApiComponentsPage",
}),
}),
route({
path: "/hooks",
component: defer(withMeta("/api/hooks", <ApiHooksPage />), {
name: "ApiHooksPage",
}),
}),
route({
path: "/utilities",
component: defer(withMeta("/api/utilities", <ApiUtilitiesPage />), {
name: "ApiUtilitiesPage",
}),
}),
route({
path: "/types",
component: defer(withMeta("/api/types", <ApiTypesPage />), {
name: "ApiTypesPage",
}),
}),
],
}),
route({
path: "/examples",
component: defer(withMeta("/examples", <ExamplesPage />), { name: "ExamplesPage" }),
}),
route({
path: "/faq",
component: defer(withMeta("/faq", <FaqPage />), { name: "FaqPage" }),
}),
route({
path: "/*",
component: defer(withMeta("/*", <NotFoundPage />), { name: "NotFoundPage" }),
Expand Down
14 changes: 14 additions & 0 deletions packages/docs/src/components/DocsLayout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Outlet } from "@funstack/router";
import { DocsSidebar } from "./DocsSidebar.js";

// Layout for documentation pages: a site-wide sidebar next to the page content.
export function DocsLayout() {
return (
<div className="docs-layout">
<DocsSidebar />
<div className="docs-content">
<Outlet />
</div>
</div>
);
}
84 changes: 84 additions & 0 deletions packages/docs/src/components/DocsNav.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
"use client";

import { useLocation } from "@funstack/router";
import { docsNavSections, isNavGroup, type NavItem } from "../navigation.js";

function DocsNavLink({
item,
currentPath,
onNavigate,
}: {
item: NavItem;
currentPath: string;
onNavigate?: () => void;
}) {
if (item.external) {
return (
<li>
<a
href={item.path}
className="docs-nav-link"
target="_blank"
rel="noopener noreferrer"
onClick={onNavigate}
>
{item.label} <span aria-hidden="true">↗</span>
</a>
</li>
);
}
const isActive = currentPath === item.path;
return (
<li>
<a
href={item.path}
className={`docs-nav-link ${isActive ? "active" : ""}`}
aria-current={isActive ? "page" : undefined}
onClick={onNavigate}
>
{item.label}
</a>
</li>
);
}

// Lists all documentation pages grouped by section, highlighting the current page.
export function DocsNav({ onNavigate }: { onNavigate?: () => void }) {
const { pathname: currentPath } = useLocation();

return (
<>
{docsNavSections.map((section) => (
<div key={section.label} className="docs-nav-section">
<p className="docs-nav-section-label">{section.label}</p>
<ul className="docs-nav-list">
{section.items.map((entry) =>
isNavGroup(entry) ? (
<li key={entry.label} className="docs-nav-group">
<span className="docs-nav-group-label">{entry.label}</span>
<ul className="docs-nav-list">
{entry.items.map((item) => (
<DocsNavLink
key={item.path}
item={item}
currentPath={currentPath}
onNavigate={onNavigate}
/>
))}
</ul>
</li>
) : (
<DocsNavLink
key={entry.path}
item={entry}
currentPath={currentPath}
onNavigate={onNavigate}
/>
),
)}
</ul>
</div>
))}
</>
);
}
Loading
Loading