www: add versioning to docs (#1400)

This commit is contained in:
Marvin Hagemeister
2023-07-04 12:33:47 +02:00
committed by GitHub
parent efcaec3658
commit bf3e82c093
10 changed files with 566 additions and 149 deletions
+15
View File
@@ -0,0 +1,15 @@
---
description: |
Learn more about Fresh canary releases
---
The canary version represents the current development state of Fresh. It's
intended for testing work in progress features before it lands in a stable
release. Whenever new code is merged into the `main` branch on
[GitHub](https://github.com/denoland/fresh) a new canary version is created that
matches the hash of the git commit.
With the addition of new features that are not yet in a stable release, we need
a place to update our documentation. That's what this section of the
documentation is about. It contains all information about unreleased features
and changes that will land in a stable release.
+151 -56
View File
@@ -1,66 +1,161 @@
type RawTableOfContents = Record<string, RawTableOfContentsEntry>; import FRESH_VERSIONS from "../versions.json" assert { type: "json" };
type RawTableOfContents = Record<
string,
{
label: string;
content: Record<string, RawTableOfContentsEntry>;
}
>;
interface RawTableOfContentsEntry { interface RawTableOfContentsEntry {
title: string; title: string;
pages?: [string, string][]; link?: string;
pages?: [string, string, string?][];
} }
const toc: RawTableOfContents = { const toc: RawTableOfContents = {
"introduction": { canary: {
"title": "Introduction", label: "canary",
content: {
"the-canary-version": {
title: "The canary version",
},
introduction: {
title: "Introduction",
link: "latest",
},
"getting-started": {
title: "Getting Started",
link: "latest",
pages: [
["create-a-project", "Create a project", "link:latest"],
["running-locally", "Running locally", "link:latest"],
["create-a-route", "Create a route", "link:latest"],
["dynamic-routes", "Dynamic routes", "link:latest"],
["custom-handlers", "Custom handlers", "link:latest"],
["fetching-data", "Fetching data", "link:latest"],
["form-submissions", "Form submissions", "link:latest"],
["adding-interactivity", "Adding interactivity", "link:latest"],
["deploy-to-production", "Deploy to production", "link:latest"],
],
},
concepts: {
title: "Concepts",
link: "latest",
pages: [
["architecture", "Architecture", "link:latest"],
["routes", "Routes", "link:latest"],
["forms", "Forms", "link:latest"],
["islands", "Interactive islands", "link:latest"],
["static-files", "Static files", "link:latest"],
["middleware", "Route middleware", "link:latest"],
["error-pages", "Error pages", "link:latest"],
["routing", "Routing", "link:latest"],
["data-fetching", "Data fetching", "link:latest"],
["deployment", "Deployment", "link:latest"],
["plugins", "Plugins", "link:latest"],
["updating", "Updating Fresh", "link:latest"],
["app-wrapper", "Application wrapper", "link:latest"],
["server-configuration", "Server configuration", "link:latest"],
],
},
integrations: {
title: "Integrations",
link: "latest",
},
examples: {
title: "Examples",
link: "latest",
pages: [
["modifying-the-head", "Modifying the <head>", "link:latest"],
["setting-the-language", "Setting the language", "link:latest"],
["writing-tests", "Writing tests", "link:latest"],
[
"changing-the-src-dir",
"Changing the source directory",
"link:latest",
],
["using-twind-v1", "Using Twind v1", "link:latest"],
["init-the-server", "Initializing the server", "link:latest"],
[
"using-fresh-canary-version",
"Using Fresh canary version",
"link:latest",
],
["dealing-with-cors", "Dealing with CORS", "link:latest"],
["creating-a-crud-api", "Creating a CRUD API", "link:latest"],
["handling-complex-routes", "Handling complex routes", "link:latest"],
["rendering-markdown", "Rendering markdown", "link:latest"],
[
"sharing-state-between-islands",
"Sharing state between islands",
"link:latest",
],
],
},
},
}, },
"getting-started": { latest: {
"title": "Getting Started", label: FRESH_VERSIONS[0],
"pages": [ content: {
["create-a-project", "Create a project"], introduction: {
["running-locally", "Running locally"], title: "Introduction",
["create-a-route", "Create a route"], },
["dynamic-routes", "Dynamic routes"], "getting-started": {
["custom-handlers", "Custom handlers"], title: "Getting Started",
["fetching-data", "Fetching data"], pages: [
["form-submissions", "Form submissions"], ["create-a-project", "Create a project"],
["adding-interactivity", "Adding interactivity"], ["running-locally", "Running locally"],
["deploy-to-production", "Deploy to production"], ["create-a-route", "Create a route"],
], ["dynamic-routes", "Dynamic routes"],
}, ["custom-handlers", "Custom handlers"],
"concepts": { ["fetching-data", "Fetching data"],
"title": "Concepts", ["form-submissions", "Form submissions"],
"pages": [ ["adding-interactivity", "Adding interactivity"],
["architecture", "Architecture"], ["deploy-to-production", "Deploy to production"],
["routes", "Routes"], ],
["forms", "Forms"], },
["islands", "Interactive islands"], concepts: {
["static-files", "Static files"], title: "Concepts",
["middleware", "Route middleware"], pages: [
["error-pages", "Error pages"], ["architecture", "Architecture"],
["routing", "Routing"], ["routes", "Routes"],
["data-fetching", "Data fetching"], ["forms", "Forms"],
["deployment", "Deployment"], ["islands", "Interactive islands"],
["plugins", "Plugins"], ["static-files", "Static files"],
["updating", "Updating Fresh"], ["middleware", "Route middleware"],
["app-wrapper", "Application wrapper"], ["error-pages", "Error pages"],
["server-configuration", "Server configuration"], ["routing", "Routing"],
], ["data-fetching", "Data fetching"],
}, ["deployment", "Deployment"],
"integrations": { ["plugins", "Plugins"],
"title": "Integrations", ["updating", "Updating Fresh"],
}, ["app-wrapper", "Application wrapper"],
"examples": { ["server-configuration", "Server configuration"],
"title": "Examples", ],
"pages": [ },
["modifying-the-head", "Modifying the <head>"], integrations: {
["setting-the-language", "Setting the language"], title: "Integrations",
["writing-tests", "Writing tests"], },
["changing-the-src-dir", "Changing the source directory"], examples: {
["using-twind-v1", "Using Twind v1"], title: "Examples",
["init-the-server", "Initializing the server"], pages: [
["using-fresh-canary-version", "Using Fresh canary version"], ["modifying-the-head", "Modifying the <head>"],
["dealing-with-cors", "Dealing with CORS"], ["setting-the-language", "Setting the language"],
["creating-a-crud-api", "Creating a CRUD API"], ["writing-tests", "Writing tests"],
["handling-complex-routes", "Handling complex routes"], ["changing-the-src-dir", "Changing the source directory"],
["rendering-markdown", "Rendering markdown"], ["using-twind-v1", "Using Twind v1"],
["sharing-state-between-islands", "Sharing state between islands"], ["init-the-server", "Initializing the server"],
], ["using-fresh-canary-version", "Using Fresh canary version"],
["dealing-with-cors", "Dealing with CORS"],
["creating-a-crud-api", "Creating a CRUD API"],
["handling-complex-routes", "Handling complex routes"],
["rendering-markdown", "Rendering markdown"],
["sharing-state-between-islands", "Sharing state between islands"],
],
},
},
}, },
}; };
+18 -4
View File
@@ -1,13 +1,20 @@
import { Head } from "$fresh/runtime.ts";
import { import {
CATEGORIES, CATEGORIES,
TableOfContentsCategory, TableOfContentsCategory,
TableOfContentsCategoryEntry, TableOfContentsCategoryEntry,
} from "../data/docs.ts"; } from "../data/docs.ts";
import SearchButton from "../islands/SearchButton.tsx"; import SearchButton from "../islands/SearchButton.tsx";
import VersionSelect from "../islands/VersionSelect.tsx";
import { type VersionLink } from "../routes/docs/[...slug].tsx";
export default function DocsSidebar(props: { path: string; mobile?: boolean }) { export default function DocsSidebar(
const id = String(Math.random()).replaceAll(".", ""); props: {
path: string;
mobile?: boolean;
versionLinks: VersionLink[];
selectedVersion: string;
},
) {
return ( return (
<> <>
{props.mobile {props.mobile
@@ -47,8 +54,15 @@ export default function DocsSidebar(props: { path: string; mobile?: boolean }) {
) )
: <SearchButton />} : <SearchButton />}
<div class="mb-4">
<VersionSelect
selectedVersion={props.selectedVersion}
versions={props.versionLinks}
/>
</div>
<ol class="list-decimal list-inside font-semibold nested"> <ol class="list-decimal list-inside font-semibold nested">
{CATEGORIES.map((category) => ( {CATEGORIES[props.selectedVersion].map((category) => (
<SidebarCategory path={props.path} category={category} /> <SidebarCategory path={props.path} category={category} />
))} ))}
</ol> </ol>
+75 -34
View File
@@ -19,42 +19,83 @@ export interface TableOfContentsCategoryEntry {
href: string; href: string;
} }
export const TABLE_OF_CONTENTS: Record<string, TableOfContentsEntry> = {}; export const TABLE_OF_CONTENTS: Record<
export const CATEGORIES: TableOfContentsCategory[] = []; string,
Record<string, TableOfContentsEntry>
> = {};
export const CATEGORIES: Record<string, TableOfContentsCategory[]> = {};
for (const parent in toc) { export const VERSIONS = Object.keys(toc);
const rawEntry = toc[parent]; export const CANARY_VERSION = toc.canary ? "canary" : "";
const href = `/docs/${parent}`; export const LATEST_VERSION =
const file = `docs/${parent}/index.md`; VERSIONS.find((version) => version !== "canary") ?? "";
const entry = {
slug: parent, for (const version in toc) {
title: rawEntry.title, const RAW_VERSION = toc[version];
href, const versionSlug = version === LATEST_VERSION ? "" : `/${version}`;
file, TABLE_OF_CONTENTS[version] = {};
}; CATEGORIES[version] = [];
TABLE_OF_CONTENTS[parent] = entry;
const category: TableOfContentsCategory = { for (const parent in RAW_VERSION.content) {
title: rawEntry.title, const rawEntry = RAW_VERSION.content[parent];
href,
entries: [], // Allow versioned documentation to stack on each other. This should
}; // only be used for canary versions. This avoids having us to copy
CATEGORIES.push(category); // all documentation content and backport changes.
const filteredPages = rawEntry.pages?.filter(([title, page]) => const fileVersion = rawEntry.link ?? version;
title != null && page != null const versionFilePath = fileVersion === LATEST_VERSION
); ? ""
if (filteredPages) { : `/${fileVersion}`;
for (const [id, title] of filteredPages) {
const slug = `${parent}/${id}`; const href = `/docs${versionSlug}/${parent}`;
const href = `/docs/${slug}`; const file = `docs${versionFilePath}/${parent}/index.md`;
const file = `docs/${slug}.md`;
const entry = { slug, title, category: parent, href, file }; const entry = {
TABLE_OF_CONTENTS[slug] = entry; slug: parent,
category.entries.push({ title: rawEntry.title,
title, href,
href, file,
}); };
TABLE_OF_CONTENTS[version][parent] = entry;
const category: TableOfContentsCategory = {
title: rawEntry.title,
href,
entries: [],
};
CATEGORIES[version].push(category);
if (rawEntry.pages) {
for (const [id, title, linkedVersion] of rawEntry.pages) {
const slug = `${parent}/${id}`;
// Allow stacked documentation
const pageVersion = linkedVersion
? linkedVersion.slice("link:".length)
: version;
const versionFilePath = !pageVersion || pageVersion === LATEST_VERSION
? ""
: `/${pageVersion}`;
const href = `/docs${versionSlug}/${slug}`;
const file = `docs${versionFilePath}/${slug}.md`;
const entry = { slug, title, category: parent, href, file };
TABLE_OF_CONTENTS[version][slug] = entry;
category.entries.push({
title,
href,
});
}
} }
} }
} }
export const SLUGS = Object.keys(TABLE_OF_CONTENTS); export function getFirstPageUrl(version: string) {
const group = TABLE_OF_CONTENTS[version];
if (group) {
for (const slug in group) {
return group[slug].href;
}
}
throw new Error(`Could not find version "${version}"`);
}
+14 -10
View File
@@ -7,16 +7,18 @@ import * as $1 from "./routes/_500.tsx";
import * as $2 from "./routes/_middleware.ts"; import * as $2 from "./routes/_middleware.ts";
import * as $3 from "./routes/components.tsx"; import * as $3 from "./routes/components.tsx";
import * as $4 from "./routes/docs/[...slug].tsx"; import * as $4 from "./routes/docs/[...slug].tsx";
import * as $5 from "./routes/gfm.css.ts"; import * as $5 from "./routes/docs/index.tsx";
import * as $6 from "./routes/index.tsx"; import * as $6 from "./routes/gfm.css.ts";
import * as $7 from "./routes/raw.ts"; import * as $7 from "./routes/index.tsx";
import * as $8 from "./routes/showcase.tsx"; import * as $8 from "./routes/raw.ts";
import * as $9 from "./routes/update.tsx"; import * as $9 from "./routes/showcase.tsx";
import * as $10 from "./routes/update.tsx";
import * as $$0 from "./islands/ComponentGallery.tsx"; import * as $$0 from "./islands/ComponentGallery.tsx";
import * as $$1 from "./islands/CopyArea.tsx"; import * as $$1 from "./islands/CopyArea.tsx";
import * as $$2 from "./islands/Counter.tsx"; import * as $$2 from "./islands/Counter.tsx";
import * as $$3 from "./islands/LemonDrop.tsx"; import * as $$3 from "./islands/LemonDrop.tsx";
import * as $$4 from "./islands/SearchButton.tsx"; import * as $$4 from "./islands/SearchButton.tsx";
import * as $$5 from "./islands/VersionSelect.tsx";
const manifest = { const manifest = {
routes: { routes: {
@@ -25,11 +27,12 @@ const manifest = {
"./routes/_middleware.ts": $2, "./routes/_middleware.ts": $2,
"./routes/components.tsx": $3, "./routes/components.tsx": $3,
"./routes/docs/[...slug].tsx": $4, "./routes/docs/[...slug].tsx": $4,
"./routes/gfm.css.ts": $5, "./routes/docs/index.tsx": $5,
"./routes/index.tsx": $6, "./routes/gfm.css.ts": $6,
"./routes/raw.ts": $7, "./routes/index.tsx": $7,
"./routes/showcase.tsx": $8, "./routes/raw.ts": $8,
"./routes/update.tsx": $9, "./routes/showcase.tsx": $9,
"./routes/update.tsx": $10,
}, },
islands: { islands: {
"./islands/ComponentGallery.tsx": $$0, "./islands/ComponentGallery.tsx": $$0,
@@ -37,6 +40,7 @@ const manifest = {
"./islands/Counter.tsx": $$2, "./islands/Counter.tsx": $$2,
"./islands/LemonDrop.tsx": $$3, "./islands/LemonDrop.tsx": $$3,
"./islands/SearchButton.tsx": $$4, "./islands/SearchButton.tsx": $$4,
"./islands/VersionSelect.tsx": $$5,
}, },
baseUrl: import.meta.url, baseUrl: import.meta.url,
}; };
+62
View File
@@ -0,0 +1,62 @@
// Copyright 2022-2023 the Deno authors. All rights reserved. MIT license.
import { IS_BROWSER } from "$fresh/runtime.ts";
import { type VersionLink } from "../routes/docs/[...slug].tsx";
export default function VersionSelect(
{ versions, selectedVersion }: {
versions: VersionLink[];
selectedVersion: string;
},
) {
const selectedIsLatest = selectedVersion === "latest";
const selectedIsCanary = selectedVersion === "canary";
return (
<>
<div class="relative">
<label htmlFor="version" class="sr-only">
Version
</label>
{selectedIsLatest && (
<div class="flex absolute pointer-events-none select-none w-full h-full items-center justify-end pr-8">
<div class="rounded-full px-2 py-1 text-xs tag-label bg-[#056CF025] text-blue-600">
Latest
</div>
</div>
)}
{selectedIsCanary && (
<div class="flex absolute pointer-events-none select-none w-full h-full items-center justify-end pr-8">
<div class="rounded-full px-2 py-1 text-xs tag-label bg-[#F0900525] text-yellow-600">
🚧 Preview
</div>
</div>
)}
<select
id="version"
class={`rounded-md block border border-gray-300 appearance-none bg-white form-select-bg font-semibold ${
selectedIsLatest ? "pr-22" : "pr-10"
} py-2 pl-3 w-full h-full leading-none sm:(text-sm leading-5) focus:(outline-none border-blue-300) hover:bg-gray-100`}
value={selectedVersion}
onChange={(e) => {
if (e.currentTarget.value !== selectedVersion) {
const entry = versions.find((entry) =>
entry.value === e.currentTarget.value
);
if (entry) {
location.href = entry.href;
}
}
}}
disabled={!IS_BROWSER}
>
{versions.map((entry) => (
<option key={entry.value} value={entry.value}>
{entry.label}
</option>
))}
</select>
</div>
</>
);
}
+61 -3
View File
@@ -1,12 +1,15 @@
import { assertEquals } from "$std/testing/asserts.ts"; import { assertArrayIncludes, assertEquals } from "$std/testing/asserts.ts";
import { delay } from "$std/async/delay.ts"; import { delay } from "$std/async/delay.ts";
import { startFreshServer } from "../tests/test_utils.ts"; import { startFreshServer, withPageName } from "../tests/test_utils.ts";
import { dirname, join } from "$std/path/mod.ts";
const dir = dirname(import.meta.url);
Deno.test("CORS should not set on GET /fresh-badge.svg", { Deno.test("CORS should not set on GET /fresh-badge.svg", {
sanitizeResources: false, sanitizeResources: false,
}, async () => { }, async () => {
const { serverProcess, lines, address } = await startFreshServer({ const { serverProcess, lines, address } = await startFreshServer({
args: ["run", "-A", "./main.ts"], args: ["run", "-A", join(dir, "./main.ts")],
}); });
const res = await fetch(`${address}/fresh-badge.svg`); const res = await fetch(`${address}/fresh-badge.svg`);
@@ -19,3 +22,58 @@ Deno.test("CORS should not set on GET /fresh-badge.svg", {
// await for the server to close // await for the server to close
await delay(100); await delay(100);
}); });
Deno.test("shows version selector", {
sanitizeResources: false,
}, async () => {
await withPageName(join(dir, "./main.ts"), async (page, address) => {
await page.goto(`${address}/docs`);
await page.waitForSelector("#version");
// Check that we redirected to the first page
assertEquals(page.url(), `${address}/docs/introduction`);
// Wait for version selector to be enabled
await page.waitForSelector("#version:not([disabled])");
const options = await page.$eval("#version", (el: HTMLSelectElement) => {
return Array.from(el.options).map((option) => ({
value: option.value,
label: option.textContent,
}));
});
assertEquals(options.length, 2);
assertArrayIncludes(options, [
{
value: "canary",
label: "canary",
},
{
value: "1.2",
label: "1.2.x",
},
]);
const selectValue = await page.$eval(
"#version",
(el: HTMLSelectElement) => el.value,
);
assertEquals(selectValue, "1.2");
// Go to canary page
await Promise.all([
page.waitForNavigation(),
page.select("#version", "canary"),
]);
await page.waitForSelector("#version:not([disabled])");
const selectValue2 = await page.$eval(
"#version",
(el: HTMLSelectElement) => el.value,
);
assertEquals(selectValue2, "canary");
assertEquals(page.url(), `${address}/docs/canary/introduction`);
});
});
+136 -41
View File
@@ -1,52 +1,135 @@
import { asset, Head } from "$fresh/runtime.ts";
import { Handlers, PageProps } from "$fresh/server.ts"; import { Handlers, PageProps } from "$fresh/server.ts";
import { frontMatter, gfm } from "../../utils/markdown.ts"; import { asset, Head } from "$fresh/runtime.ts";
import Header from "../../components/Header.tsx";
import DocsTitle from "../../components/DocsTitle.tsx";
import DocsSidebar from "../../components/DocsSidebar.tsx"; import DocsSidebar from "../../components/DocsSidebar.tsx";
import DocsTitle from "../../components/DocsTitle.tsx";
import Footer from "../../components/Footer.tsx"; import Footer from "../../components/Footer.tsx";
import Header from "../../components/Header.tsx";
import { import {
SLUGS, getFirstPageUrl,
LATEST_VERSION,
TABLE_OF_CONTENTS, TABLE_OF_CONTENTS,
TableOfContentsEntry, TableOfContentsEntry,
} from "../../data/docs.ts"; } from "../../data/docs.ts";
import { frontMatter, gfm } from "../../utils/markdown.ts";
import toc from "../../../docs/toc.ts";
interface Data { interface Data {
page: Page; page: Page;
} }
interface NavEntry {
title: string;
category?: string;
href: string;
}
export interface VersionLink {
label: string;
href: string;
value: string;
}
interface Page extends TableOfContentsEntry { interface Page extends TableOfContentsEntry {
markdown: string; markdown: string;
data: Record<string, unknown>; data: Record<string, unknown>;
versionLinks: VersionLink[];
version: string;
prevNav?: NavEntry;
nextNav?: NavEntry;
} }
const pattern = new URLPattern({ pathname: "/:version/:page*" });
export const handler: Handlers<Data> = { export const handler: Handlers<Data> = {
async GET(_req, ctx) { async GET(_req, ctx) {
const slug = ctx.params.slug; const slug = ctx.params.slug;
if (slug === "") {
// Check if the slug is the index page of a version tag
if (TABLE_OF_CONTENTS[slug]) {
const href = getFirstPageUrl(slug);
return new Response("", { return new Response("", {
status: 307, status: 307,
headers: { location: "/docs/introduction" }, headers: { location: href },
});
}
if (slug === "concepts/architechture") {
return new Response("", {
status: 307,
headers: { location: "/docs/concepts/architecture" },
}); });
} }
const entry = TABLE_OF_CONTENTS[slug]; const match = pattern.exec("https://localhost/" + slug);
if (!match) {
return ctx.renderNotFound();
}
let { version, page = "" } = match.pathname.groups;
if (!version) {
return ctx.renderNotFound();
}
// Latest version doesn't show up in the url
if (!TABLE_OF_CONTENTS[version]) {
page = version + (page ? "/" + page : "");
version = LATEST_VERSION;
}
// Check if the page exists
const currentToc = TABLE_OF_CONTENTS[version];
const entry = currentToc[page];
if (!entry) { if (!entry) {
return ctx.renderNotFound(); return ctx.renderNotFound();
} }
// Build up the link map for the version selector.
const versionLinks: VersionLink[] = [];
for (const version in TABLE_OF_CONTENTS) {
const label = toc[version].label;
const maybeEntry = TABLE_OF_CONTENTS[version][page];
// Check if the same page is available for this version and
// link to that. Pick the index page for that version if an
// exact match doesn't exist.
versionLinks.push({
label,
value: version,
href: maybeEntry ? maybeEntry.href : getFirstPageUrl(version),
});
}
// Add previous and next page entry if available
const entryKeys = Object.keys(currentToc);
const idx = entryKeys.findIndex((name) => name === entry.slug);
let nextNav: NavEntry | undefined;
let prevNav: NavEntry | undefined;
const prevEntry = currentToc[entryKeys[idx - 1]];
const nextEntry = currentToc[entryKeys[idx + 1]];
if (prevEntry) {
let category = prevEntry.category;
category = category ? currentToc[category].title : "";
prevNav = { title: prevEntry.title, category, href: prevEntry.href };
}
if (nextEntry) {
let category = nextEntry.category;
category = category ? currentToc[category].title : "";
nextNav = { title: nextEntry.title, category, href: nextEntry.href };
}
// Parse markdown front matter
const url = new URL(`../../../${entry.file}`, import.meta.url); const url = new URL(`../../../${entry.file}`, import.meta.url);
const fileContent = await Deno.readTextFile(url); const fileContent = await Deno.readTextFile(url);
const { body, attrs } = frontMatter<Record<string, unknown>>(fileContent); const { body, attrs } = frontMatter<Record<string, unknown>>(fileContent);
const page = { ...entry, markdown: body, data: attrs ?? {} };
const resp = ctx.render({ page }); return ctx.render({
return resp; page: {
...entry,
markdown: body,
data: attrs ?? {},
versionLinks,
version,
prevNav,
nextNav,
},
});
}, },
}; };
@@ -84,7 +167,7 @@ export default function DocsPage(props: PageProps<Data>) {
function Main(props: { path: string; page: Page }) { function Main(props: { path: string; page: Page }) {
return ( return (
<div class="flex-1"> <div class="flex-1">
<MobileSidebar path={props.path} /> <MobileSidebar path={props.path} page={props.page} />
<div class="flex mx-auto max-w-screen-lg px-4 py-5 justify-end"> <div class="flex mx-auto max-w-screen-lg px-4 py-5 justify-end">
<label <label
for="docs_sidebar" for="docs_sidebar"
@@ -110,14 +193,14 @@ function Main(props: { path: string; page: Page }) {
</label> </label>
</div> </div>
<div class="mx-auto max-w-screen-lg px-4 flex gap-6"> <div class="mx-auto max-w-screen-lg px-4 flex gap-6">
<DesktopSidebar path={props.path} /> <DesktopSidebar path={props.path} page={props.page} />
<Content page={props.page} /> <Content page={props.page} />
</div> </div>
</div> </div>
); );
} }
function MobileSidebar(props: { path: string }) { function MobileSidebar(props: { path: string; page: Page }) {
return ( return (
<> <>
<input <input
@@ -137,7 +220,12 @@ function MobileSidebar(props: { path: string }) {
<DocsTitle title="docs" /> <DocsTitle title="docs" />
</div> </div>
<nav class="pt-6 pb-16 px-4 overflow-x-auto"> <nav class="pt-6 pb-16 px-4 overflow-x-auto">
<DocsSidebar mobile path={props.path} /> <DocsSidebar
mobile
path={props.path}
versionLinks={props.page.versionLinks}
selectedVersion={props.page.version}
/>
</nav> </nav>
</div> </div>
</div> </div>
@@ -145,10 +233,14 @@ function MobileSidebar(props: { path: string }) {
); );
} }
function DesktopSidebar(props: { path: string }) { function DesktopSidebar(props: { path: string; page: Page }) {
return ( return (
<nav class="w-[16rem] flex-shrink-0 hidden md:block py-8 pr-4 border(r-2 gray-100)"> <nav class="w-[16rem] flex-shrink-0 hidden md:block py-8 pr-4 border(r-2 gray-100)">
<DocsSidebar path={props.path} /> <DocsSidebar
path={props.path}
versionLinks={props.page.versionLinks}
selectedVersion={props.page.version}
/>
</nav> </nav>
); );
} }
@@ -164,36 +256,41 @@ function Content(props: { page: Page }) {
class="mt-6 markdown-body" class="mt-6 markdown-body"
dangerouslySetInnerHTML={{ __html: html }} dangerouslySetInnerHTML={{ __html: html }}
/> />
<ForwardBackButtons slug={props.page.slug} /> <ForwardBackButtons
slug={props.page.slug}
version={props.page.version}
prev={props.page.prevNav}
next={props.page.nextNav}
/>
</main> </main>
); );
} }
const button = "p-2 bg-gray-100 w-full border(1 gray-200) grid"; const button = "p-2 bg-gray-100 w-full border(1 gray-200) grid";
function ForwardBackButtons(props: { slug: string }) { function ForwardBackButtons(
const currentIndex = SLUGS.findIndex((slug) => slug === props.slug); props: {
const previousSlug = SLUGS[currentIndex - 1]; slug: string;
const nextSlug = SLUGS[currentIndex + 1]; version: string;
const previous = TABLE_OF_CONTENTS[previousSlug]; prev?: NavEntry;
const next = TABLE_OF_CONTENTS[nextSlug]; next?: NavEntry;
},
) {
const { prev, next } = props;
const upper = "text(sm gray-600)"; const upper = "text(sm gray-600)";
const category = "font-normal"; const category = "font-normal";
const lower = "text-gray-900 font-medium"; const lower = "text-gray-900 font-medium";
return ( return (
<div class="mt-8 flex flex(col md:row) gap-4"> <div class="mt-8 flex flex(col md:row) gap-4">
{previous && ( {prev && (
<a href={previous.href} class={`${button} text-left`}> <a href={prev.href} class={`${button} text-left`}>
<span class={upper}>{"←"} Previous</span> <span class={upper}>{"←"} Previous</span>
<span class={lower}> <span class={lower}>
<span class={category}> <span class={category}>
{previous.category {prev.category ? `${prev.category}: ` : ""}
? `${TABLE_OF_CONTENTS[previous.category].title}: `
: ""}
</span> </span>
{previous.title} {prev.title}
</span> </span>
</a> </a>
)} )}
@@ -202,9 +299,7 @@ function ForwardBackButtons(props: { slug: string }) {
<span class={upper}>Next {"→"}</span> <span class={upper}>Next {"→"}</span>
<span class={lower}> <span class={lower}>
<span class={category}> <span class={category}>
{next.category {next.category ? `${next.category}: ` : ""}
? `${TABLE_OF_CONTENTS[next.category].title}: `
: ""}
</span> </span>
{next.title} {next.title}
</span> </span>
+19
View File
@@ -0,0 +1,19 @@
import { MultiHandler } from "$fresh/server.ts";
export const handler: MultiHandler<void> = {
GET(_req, ctx) {
const slug = ctx.params.slug;
if (slug === "concepts/architechture") {
return new Response("", {
status: 307,
headers: { location: "/docs/concepts/architecture" },
});
}
return new Response("", {
status: 307,
headers: { location: "/docs/introduction" },
});
},
};
+15 -1
View File
@@ -17,7 +17,7 @@ export default {
plugins: { plugins: {
// Basic workaround for old twind version not supporting // Basic workaround for old twind version not supporting
// the `basis-*` keyword // the `basis-*` keyword
"basis": (parts) => { basis: (parts) => {
let value; let value;
const arr = parts[0].split("/"); const arr = parts[0].split("/");
if (arr.length === 2) { if (arr.length === 2) {
@@ -29,5 +29,19 @@ export default {
"flex-basis": value, "flex-basis": value,
}; };
}, },
"rounded-full": () => {
return {
"border-radius": "9999px",
};
},
"form-select-bg": () => {
return {
"background-image":
`url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none'%3e%3cpath d='M7 7l3-3 3 3m0 6l-3 3-3-3' stroke='%239fa6b2' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3e%3c/svg%3e")`,
"background-position": "right 0.5rem center",
"background-size": "1.5em 1.5em",
"background-repeat": "no-repeat",
};
},
}, },
} as Options; } as Options;