From bf3e82c0937c15ccf93366db235d5fb5dc864fea Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Tue, 4 Jul 2023 12:33:47 +0200 Subject: [PATCH] www: add versioning to docs (#1400) --- docs/canary/the-canary-version/index.md | 15 ++ docs/toc.ts | 207 +++++++++++++++++------- www/components/DocsSidebar.tsx | 22 ++- www/data/docs.ts | 109 +++++++++---- www/fresh.gen.ts | 24 +-- www/islands/VersionSelect.tsx | 62 +++++++ www/main_test.ts | 64 +++++++- www/routes/docs/[...slug].tsx | 177 +++++++++++++++----- www/routes/docs/index.tsx | 19 +++ www/twind.config.ts | 16 +- 10 files changed, 566 insertions(+), 149 deletions(-) create mode 100644 docs/canary/the-canary-version/index.md create mode 100644 www/islands/VersionSelect.tsx create mode 100644 www/routes/docs/index.tsx diff --git a/docs/canary/the-canary-version/index.md b/docs/canary/the-canary-version/index.md new file mode 100644 index 00000000..9ec8f401 --- /dev/null +++ b/docs/canary/the-canary-version/index.md @@ -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. diff --git a/docs/toc.ts b/docs/toc.ts index 1e32d42d..2019f770 100644 --- a/docs/toc.ts +++ b/docs/toc.ts @@ -1,66 +1,161 @@ -type RawTableOfContents = Record; +import FRESH_VERSIONS from "../versions.json" assert { type: "json" }; + +type RawTableOfContents = Record< + string, + { + label: string; + content: Record; + } +>; interface RawTableOfContentsEntry { title: string; - pages?: [string, string][]; + link?: string; + pages?: [string, string, string?][]; } const toc: RawTableOfContents = { - "introduction": { - "title": "Introduction", + canary: { + 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 ", "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": { - "title": "Getting Started", - "pages": [ - ["create-a-project", "Create a project"], - ["running-locally", "Running locally"], - ["create-a-route", "Create a route"], - ["dynamic-routes", "Dynamic routes"], - ["custom-handlers", "Custom handlers"], - ["fetching-data", "Fetching data"], - ["form-submissions", "Form submissions"], - ["adding-interactivity", "Adding interactivity"], - ["deploy-to-production", "Deploy to production"], - ], - }, - "concepts": { - "title": "Concepts", - "pages": [ - ["architecture", "Architecture"], - ["routes", "Routes"], - ["forms", "Forms"], - ["islands", "Interactive islands"], - ["static-files", "Static files"], - ["middleware", "Route middleware"], - ["error-pages", "Error pages"], - ["routing", "Routing"], - ["data-fetching", "Data fetching"], - ["deployment", "Deployment"], - ["plugins", "Plugins"], - ["updating", "Updating Fresh"], - ["app-wrapper", "Application wrapper"], - ["server-configuration", "Server configuration"], - ], - }, - "integrations": { - "title": "Integrations", - }, - "examples": { - "title": "Examples", - "pages": [ - ["modifying-the-head", "Modifying the "], - ["setting-the-language", "Setting the language"], - ["writing-tests", "Writing tests"], - ["changing-the-src-dir", "Changing the source directory"], - ["using-twind-v1", "Using Twind v1"], - ["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"], - ], + latest: { + label: FRESH_VERSIONS[0], + content: { + introduction: { + title: "Introduction", + }, + "getting-started": { + title: "Getting Started", + pages: [ + ["create-a-project", "Create a project"], + ["running-locally", "Running locally"], + ["create-a-route", "Create a route"], + ["dynamic-routes", "Dynamic routes"], + ["custom-handlers", "Custom handlers"], + ["fetching-data", "Fetching data"], + ["form-submissions", "Form submissions"], + ["adding-interactivity", "Adding interactivity"], + ["deploy-to-production", "Deploy to production"], + ], + }, + concepts: { + title: "Concepts", + pages: [ + ["architecture", "Architecture"], + ["routes", "Routes"], + ["forms", "Forms"], + ["islands", "Interactive islands"], + ["static-files", "Static files"], + ["middleware", "Route middleware"], + ["error-pages", "Error pages"], + ["routing", "Routing"], + ["data-fetching", "Data fetching"], + ["deployment", "Deployment"], + ["plugins", "Plugins"], + ["updating", "Updating Fresh"], + ["app-wrapper", "Application wrapper"], + ["server-configuration", "Server configuration"], + ], + }, + integrations: { + title: "Integrations", + }, + examples: { + title: "Examples", + pages: [ + ["modifying-the-head", "Modifying the "], + ["setting-the-language", "Setting the language"], + ["writing-tests", "Writing tests"], + ["changing-the-src-dir", "Changing the source directory"], + ["using-twind-v1", "Using Twind v1"], + ["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"], + ], + }, + }, }, }; diff --git a/www/components/DocsSidebar.tsx b/www/components/DocsSidebar.tsx index bd86dd17..2bfe528d 100644 --- a/www/components/DocsSidebar.tsx +++ b/www/components/DocsSidebar.tsx @@ -1,13 +1,20 @@ -import { Head } from "$fresh/runtime.ts"; import { CATEGORIES, TableOfContentsCategory, TableOfContentsCategoryEntry, } from "../data/docs.ts"; 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 }) { - const id = String(Math.random()).replaceAll(".", ""); +export default function DocsSidebar( + props: { + path: string; + mobile?: boolean; + versionLinks: VersionLink[]; + selectedVersion: string; + }, +) { return ( <> {props.mobile @@ -47,8 +54,15 @@ export default function DocsSidebar(props: { path: string; mobile?: boolean }) { ) : } +
+ +
+
    - {CATEGORIES.map((category) => ( + {CATEGORIES[props.selectedVersion].map((category) => ( ))}
diff --git a/www/data/docs.ts b/www/data/docs.ts index e2a149c2..3a2a4a96 100644 --- a/www/data/docs.ts +++ b/www/data/docs.ts @@ -19,42 +19,83 @@ export interface TableOfContentsCategoryEntry { href: string; } -export const TABLE_OF_CONTENTS: Record = {}; -export const CATEGORIES: TableOfContentsCategory[] = []; +export const TABLE_OF_CONTENTS: Record< + string, + Record +> = {}; +export const CATEGORIES: Record = {}; -for (const parent in toc) { - const rawEntry = toc[parent]; - const href = `/docs/${parent}`; - const file = `docs/${parent}/index.md`; - const entry = { - slug: parent, - title: rawEntry.title, - href, - file, - }; - TABLE_OF_CONTENTS[parent] = entry; - const category: TableOfContentsCategory = { - title: rawEntry.title, - href, - entries: [], - }; - CATEGORIES.push(category); - const filteredPages = rawEntry.pages?.filter(([title, page]) => - title != null && page != null - ); - if (filteredPages) { - for (const [id, title] of filteredPages) { - const slug = `${parent}/${id}`; - const href = `/docs/${slug}`; - const file = `docs/${slug}.md`; - const entry = { slug, title, category: parent, href, file }; - TABLE_OF_CONTENTS[slug] = entry; - category.entries.push({ - title, - href, - }); +export const VERSIONS = Object.keys(toc); +export const CANARY_VERSION = toc.canary ? "canary" : ""; +export const LATEST_VERSION = + VERSIONS.find((version) => version !== "canary") ?? ""; + +for (const version in toc) { + const RAW_VERSION = toc[version]; + const versionSlug = version === LATEST_VERSION ? "" : `/${version}`; + TABLE_OF_CONTENTS[version] = {}; + CATEGORIES[version] = []; + + for (const parent in RAW_VERSION.content) { + const rawEntry = RAW_VERSION.content[parent]; + + // Allow versioned documentation to stack on each other. This should + // only be used for canary versions. This avoids having us to copy + // all documentation content and backport changes. + const fileVersion = rawEntry.link ?? version; + const versionFilePath = fileVersion === LATEST_VERSION + ? "" + : `/${fileVersion}`; + + const href = `/docs${versionSlug}/${parent}`; + const file = `docs${versionFilePath}/${parent}/index.md`; + + const entry = { + slug: parent, + title: rawEntry.title, + 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}"`); +} diff --git a/www/fresh.gen.ts b/www/fresh.gen.ts index 95c92ee2..94d38d9b 100644 --- a/www/fresh.gen.ts +++ b/www/fresh.gen.ts @@ -7,16 +7,18 @@ import * as $1 from "./routes/_500.tsx"; import * as $2 from "./routes/_middleware.ts"; import * as $3 from "./routes/components.tsx"; import * as $4 from "./routes/docs/[...slug].tsx"; -import * as $5 from "./routes/gfm.css.ts"; -import * as $6 from "./routes/index.tsx"; -import * as $7 from "./routes/raw.ts"; -import * as $8 from "./routes/showcase.tsx"; -import * as $9 from "./routes/update.tsx"; +import * as $5 from "./routes/docs/index.tsx"; +import * as $6 from "./routes/gfm.css.ts"; +import * as $7 from "./routes/index.tsx"; +import * as $8 from "./routes/raw.ts"; +import * as $9 from "./routes/showcase.tsx"; +import * as $10 from "./routes/update.tsx"; import * as $$0 from "./islands/ComponentGallery.tsx"; import * as $$1 from "./islands/CopyArea.tsx"; import * as $$2 from "./islands/Counter.tsx"; import * as $$3 from "./islands/LemonDrop.tsx"; import * as $$4 from "./islands/SearchButton.tsx"; +import * as $$5 from "./islands/VersionSelect.tsx"; const manifest = { routes: { @@ -25,11 +27,12 @@ const manifest = { "./routes/_middleware.ts": $2, "./routes/components.tsx": $3, "./routes/docs/[...slug].tsx": $4, - "./routes/gfm.css.ts": $5, - "./routes/index.tsx": $6, - "./routes/raw.ts": $7, - "./routes/showcase.tsx": $8, - "./routes/update.tsx": $9, + "./routes/docs/index.tsx": $5, + "./routes/gfm.css.ts": $6, + "./routes/index.tsx": $7, + "./routes/raw.ts": $8, + "./routes/showcase.tsx": $9, + "./routes/update.tsx": $10, }, islands: { "./islands/ComponentGallery.tsx": $$0, @@ -37,6 +40,7 @@ const manifest = { "./islands/Counter.tsx": $$2, "./islands/LemonDrop.tsx": $$3, "./islands/SearchButton.tsx": $$4, + "./islands/VersionSelect.tsx": $$5, }, baseUrl: import.meta.url, }; diff --git a/www/islands/VersionSelect.tsx b/www/islands/VersionSelect.tsx new file mode 100644 index 00000000..cae991c5 --- /dev/null +++ b/www/islands/VersionSelect.tsx @@ -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 ( + <> +
+ + {selectedIsLatest && ( +
+
+ Latest +
+
+ )} + {selectedIsCanary && ( +
+
+ 🚧 Preview +
+
+ )} + +
+ + ); +} diff --git a/www/main_test.ts b/www/main_test.ts index 383d7c97..a0d8952b 100644 --- a/www/main_test.ts +++ b/www/main_test.ts @@ -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 { 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", { sanitizeResources: false, }, async () => { 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`); @@ -19,3 +22,58 @@ Deno.test("CORS should not set on GET /fresh-badge.svg", { // await for the server to close 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`); + }); +}); diff --git a/www/routes/docs/[...slug].tsx b/www/routes/docs/[...slug].tsx index 68d83e64..020163e5 100644 --- a/www/routes/docs/[...slug].tsx +++ b/www/routes/docs/[...slug].tsx @@ -1,52 +1,135 @@ -import { asset, Head } from "$fresh/runtime.ts"; import { Handlers, PageProps } from "$fresh/server.ts"; -import { frontMatter, gfm } from "../../utils/markdown.ts"; - -import Header from "../../components/Header.tsx"; -import DocsTitle from "../../components/DocsTitle.tsx"; +import { asset, Head } from "$fresh/runtime.ts"; import DocsSidebar from "../../components/DocsSidebar.tsx"; +import DocsTitle from "../../components/DocsTitle.tsx"; import Footer from "../../components/Footer.tsx"; +import Header from "../../components/Header.tsx"; import { - SLUGS, + getFirstPageUrl, + LATEST_VERSION, TABLE_OF_CONTENTS, TableOfContentsEntry, } from "../../data/docs.ts"; +import { frontMatter, gfm } from "../../utils/markdown.ts"; +import toc from "../../../docs/toc.ts"; interface Data { page: Page; } +interface NavEntry { + title: string; + category?: string; + href: string; +} + +export interface VersionLink { + label: string; + href: string; + value: string; +} + interface Page extends TableOfContentsEntry { markdown: string; data: Record; + versionLinks: VersionLink[]; + version: string; + prevNav?: NavEntry; + nextNav?: NavEntry; } +const pattern = new URLPattern({ pathname: "/:version/:page*" }); + export const handler: Handlers = { async GET(_req, ctx) { 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("", { status: 307, - headers: { location: "/docs/introduction" }, - }); - } - if (slug === "concepts/architechture") { - return new Response("", { - status: 307, - headers: { location: "/docs/concepts/architecture" }, + headers: { location: href }, }); } - 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) { 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 fileContent = await Deno.readTextFile(url); const { body, attrs } = frontMatter>(fileContent); - const page = { ...entry, markdown: body, data: attrs ?? {} }; - const resp = ctx.render({ page }); - return resp; + + return ctx.render({ + page: { + ...entry, + markdown: body, + data: attrs ?? {}, + versionLinks, + version, + prevNav, + nextNav, + }, + }); }, }; @@ -84,7 +167,7 @@ export default function DocsPage(props: PageProps) { function Main(props: { path: string; page: Page }) { return (
- +
- +
); } -function MobileSidebar(props: { path: string }) { +function MobileSidebar(props: { path: string; page: Page }) { return ( <> @@ -145,10 +233,14 @@ function MobileSidebar(props: { path: string }) { ); } -function DesktopSidebar(props: { path: string }) { +function DesktopSidebar(props: { path: string; page: Page }) { return ( ); } @@ -164,36 +256,41 @@ function Content(props: { page: Page }) { class="mt-6 markdown-body" dangerouslySetInnerHTML={{ __html: html }} /> - + ); } const button = "p-2 bg-gray-100 w-full border(1 gray-200) grid"; -function ForwardBackButtons(props: { slug: string }) { - const currentIndex = SLUGS.findIndex((slug) => slug === props.slug); - const previousSlug = SLUGS[currentIndex - 1]; - const nextSlug = SLUGS[currentIndex + 1]; - const previous = TABLE_OF_CONTENTS[previousSlug]; - const next = TABLE_OF_CONTENTS[nextSlug]; - +function ForwardBackButtons( + props: { + slug: string; + version: string; + prev?: NavEntry; + next?: NavEntry; + }, +) { + const { prev, next } = props; const upper = "text(sm gray-600)"; const category = "font-normal"; const lower = "text-gray-900 font-medium"; return (
- {previous && ( - + {prev && ( + {"←"} Previous - {previous.category - ? `${TABLE_OF_CONTENTS[previous.category].title}: ` - : ""} + {prev.category ? `${prev.category}: ` : ""} - {previous.title} + {prev.title} )} @@ -202,9 +299,7 @@ function ForwardBackButtons(props: { slug: string }) { Next {"→"} - {next.category - ? `${TABLE_OF_CONTENTS[next.category].title}: ` - : ""} + {next.category ? `${next.category}: ` : ""} {next.title} diff --git a/www/routes/docs/index.tsx b/www/routes/docs/index.tsx new file mode 100644 index 00000000..f957e652 --- /dev/null +++ b/www/routes/docs/index.tsx @@ -0,0 +1,19 @@ +import { MultiHandler } from "$fresh/server.ts"; + +export const handler: MultiHandler = { + 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" }, + }); + }, +}; diff --git a/www/twind.config.ts b/www/twind.config.ts index 3446bb6e..1c8ff27d 100644 --- a/www/twind.config.ts +++ b/www/twind.config.ts @@ -17,7 +17,7 @@ export default { plugins: { // Basic workaround for old twind version not supporting // the `basis-*` keyword - "basis": (parts) => { + basis: (parts) => { let value; const arr = parts[0].split("/"); if (arr.length === 2) { @@ -29,5 +29,19 @@ export default { "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;