docs: Enhanced CSR Layout (#1908)
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
This commit is contained in:
co-authored by
Marvin Hagemeister
parent
7d954584a6
commit
eb41b65d4c
@@ -6,6 +6,8 @@ import {
|
|||||||
import SearchButton from "../islands/SearchButton.tsx";
|
import SearchButton from "../islands/SearchButton.tsx";
|
||||||
import VersionSelect from "../islands/VersionSelect.tsx";
|
import VersionSelect from "../islands/VersionSelect.tsx";
|
||||||
import { type VersionLink } from "../routes/docs/[...slug].tsx";
|
import { type VersionLink } from "../routes/docs/[...slug].tsx";
|
||||||
|
import { Logo } from "$fresh/www/components/Header.tsx";
|
||||||
|
import DocsTitle from "$fresh/www/components/DocsTitle.tsx";
|
||||||
|
|
||||||
export default function DocsSidebar(
|
export default function DocsSidebar(
|
||||||
props: {
|
props: {
|
||||||
@@ -16,55 +18,29 @@ export default function DocsSidebar(
|
|||||||
) {
|
) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{props.mobile
|
<div class="fixed w-[17rem] md:flex h-screen overflow-hidden ">
|
||||||
? (
|
<div class="flex-1 h-screen overflow-y-auto">
|
||||||
<button
|
<div class="sticky mb-4 top-0 bg-white z-10">
|
||||||
type="button"
|
<div class=" py-4 flex items-center">
|
||||||
class="bg-gray-200 font-bold text-gray-400 rounded-full py-1 px-2 w-full mb-2"
|
<Logo />
|
||||||
>
|
<DocsTitle />
|
||||||
<script
|
</div>
|
||||||
dangerouslySetInnerHTML={{
|
<hr />
|
||||||
__html:
|
</div>
|
||||||
`document.currentScript.parentNode.onclick = function () {
|
<SearchButton class="mr-4 sm:mr-0" />
|
||||||
document.querySelector(".DocSearch.DocSearch-Button").click()
|
<div class="mb-4">
|
||||||
}`,
|
<VersionSelect
|
||||||
}}
|
selectedVersion={props.selectedVersion}
|
||||||
|
versions={props.versionLinks}
|
||||||
/>
|
/>
|
||||||
<span class="DocSearch-Button-Container">
|
</div>
|
||||||
<svg
|
<ul class="list-inside font-semibold nested ml-2.5">
|
||||||
width="20"
|
{CATEGORIES[props.selectedVersion].map((category) => (
|
||||||
height="20"
|
<SidebarCategory key={category.href} category={category} />
|
||||||
class="DocSearch-Search-Icon"
|
))}
|
||||||
viewBox="0 0 20 20"
|
</ul>
|
||||||
>
|
</div>
|
||||||
<path
|
|
||||||
d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z"
|
|
||||||
stroke="currentColor"
|
|
||||||
fill="none"
|
|
||||||
fill-rule="evenodd"
|
|
||||||
stroke-linecap="round"
|
|
||||||
stroke-linejoin="round"
|
|
||||||
>
|
|
||||||
</path>
|
|
||||||
</svg>
|
|
||||||
<span class="DocSearch-Button-Placeholder">Search</span>
|
|
||||||
</span>
|
|
||||||
</button>
|
|
||||||
)
|
|
||||||
: <SearchButton />}
|
|
||||||
|
|
||||||
<div class="mb-4">
|
|
||||||
<VersionSelect
|
|
||||||
selectedVersion={props.selectedVersion}
|
|
||||||
versions={props.versionLinks}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ul class="list-inside font-semibold nested ml-2.5">
|
|
||||||
{CATEGORIES[props.selectedVersion].map((category) => (
|
|
||||||
<SidebarCategory key={category.href} category={category} />
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
export default function DocsTitle(props: { title: string }) {
|
export default function DocsTitle() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<a
|
<a
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ const LINKS = [
|
|||||||
|
|
||||||
export default function Footer() {
|
export default function Footer() {
|
||||||
return (
|
return (
|
||||||
<footer class="border-t-2 border-gray-200 bg-gray-100 md:h-16 flex gap-4 justify-center">
|
<footer class="border-t-2 border-gray-200 md:h-16 flex my-8 justify-center">
|
||||||
<div class="flex flex-col sm:flex-row gap-4 justify-between items-center max-w-screen-xl mx-auto w-full px(4 sm:6 md:8) p-4">
|
<div class="flex flex-col sm:flex-row gap-4 justify-between items-center max-w-screen-xl mx-auto w-full px(4 sm:6 md:8) p-4">
|
||||||
<div class="text(gray-600 center)">
|
<div class="text(gray-600 center)">
|
||||||
<span>© {new Date().getFullYear()} the Fresh authors</span>
|
<span>© {new Date().getFullYear()} the Fresh authors</span>
|
||||||
@@ -30,27 +30,6 @@ export default function Footer() {
|
|||||||
</a>
|
</a>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ul class="flex justify-center items-center gap-4 md:ml-4 mt-2 mb-4 sm:mt-0 sm:mb-0 flex-wrap">
|
|
||||||
<li class="flex items-center">
|
|
||||||
<a
|
|
||||||
href="https://github.com/denoland/fresh"
|
|
||||||
class="hover:text-green-600 inline-block transition"
|
|
||||||
aria-label="GitHub"
|
|
||||||
>
|
|
||||||
<Icons.GitHub />
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<li class="flex items-center">
|
|
||||||
<a
|
|
||||||
href="https://discord.com/invite/deno"
|
|
||||||
class="hover:text-green-600 inline-block transition"
|
|
||||||
aria-label="Discord"
|
|
||||||
>
|
|
||||||
<Icons.Discord />
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
);
|
);
|
||||||
|
|||||||
+33
-14
@@ -3,26 +3,45 @@ import NavigationBar from "./NavigationBar.tsx";
|
|||||||
|
|
||||||
export default function Header(props: { title: string; active: string }) {
|
export default function Header(props: { title: string; active: string }) {
|
||||||
const isHome = props.active == "/";
|
const isHome = props.active == "/";
|
||||||
|
const isDocs = props.active == "/docs";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<>
|
||||||
<header
|
{isDocs
|
||||||
class={"mx-auto max-w-screen-xl flex gap-3 items-center " +
|
? (
|
||||||
(isHome ? "justify-end" : "justify-between")}
|
<header
|
||||||
>
|
class={" top-0 w-full bg-white mx-auto max-w-screen-xl flex gap-3 items-center " +
|
||||||
{!isHome && (
|
"justify-between md:justify-end"}
|
||||||
<div class="p-4 flex items-center">
|
>
|
||||||
<Logo />
|
<div class="p-4 flex items-center md:hidden">
|
||||||
<DocsTitle title={props.title} />
|
<Logo />
|
||||||
</div>
|
<DocsTitle />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<NavigationBar class="hidden md:flex" active={props.active} />
|
||||||
|
</header>
|
||||||
|
)
|
||||||
|
: (
|
||||||
|
<header
|
||||||
|
class={"mx-auto max-w-screen-xl flex gap-3 items-center " +
|
||||||
|
(isHome ? "justify-end" : "justify-between")}
|
||||||
|
>
|
||||||
|
{!isHome && (
|
||||||
|
<div class="p-4 flex items-center">
|
||||||
|
<Logo />
|
||||||
|
<DocsTitle />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<NavigationBar class="hidden md:flex" active={props.active} />
|
||||||
|
</header>
|
||||||
)}
|
)}
|
||||||
<NavigationBar class="hidden md:flex" active={props.active} />
|
|
||||||
</header>
|
|
||||||
<NavigationBar class="md:hidden pb-3" active={props.active} />
|
<NavigationBar class="md:hidden pb-3" active={props.active} />
|
||||||
</div>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function Logo() {
|
export function Logo() {
|
||||||
return (
|
return (
|
||||||
<a href="/" class="flex mr-3 items-center" aria-label="Top Page">
|
<a href="/" class="flex mr-3 items-center" aria-label="Top Page">
|
||||||
<img src="/logo.svg" alt="Fresh logo" width={40} height={40} />
|
<img src="/logo.svg" alt="Fresh logo" width={40} height={40} />
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export default function VersionSelect(
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div class="relative">
|
<div class="relative mr-4 sm:mr-0">
|
||||||
<label htmlFor="version" class="sr-only">
|
<label htmlFor="version" class="sr-only">
|
||||||
Version
|
Version
|
||||||
</label>
|
</label>
|
||||||
|
|||||||
@@ -155,10 +155,8 @@ export default function DocsPage(props: PageProps<Data>) {
|
|||||||
<meta property="og:image" content={ogImageUrl} />
|
<meta property="og:image" content={ogImageUrl} />
|
||||||
<meta name="view-transition" content="same-origin" />
|
<meta name="view-transition" content="same-origin" />
|
||||||
</Head>
|
</Head>
|
||||||
<div class="flex flex-col min-h-screen">
|
<div class="flex flex-col min-h-screen mx-auto max-w-screen-xl">
|
||||||
<Header title="docs" active="/docs" />
|
|
||||||
<Main page={props.data.page} />
|
<Main page={props.data.page} />
|
||||||
<Footer />
|
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
@@ -166,31 +164,8 @@ export default function DocsPage(props: PageProps<Data>) {
|
|||||||
|
|
||||||
function Main(props: { page: Page }) {
|
function Main(props: { page: Page }) {
|
||||||
return (
|
return (
|
||||||
<div class="flex-1" f-client-nav>
|
<div class="flex-1 " f-client-nav>
|
||||||
<MobileSidebar page={props.page} />
|
<div class=" md:flex">
|
||||||
<div class="flex mx-auto max-w-screen-xl px-4 md:px-0 md:py-0 justify-end bg-gray-100">
|
|
||||||
<label
|
|
||||||
for="docs_sidebar"
|
|
||||||
class="px-4 py-3 md:hidden flex items-center hover:bg-gray-100 rounded gap-2 cursor-pointer"
|
|
||||||
>
|
|
||||||
<svg
|
|
||||||
class="h-6 w-6"
|
|
||||||
stroke="currentColor"
|
|
||||||
fill="none"
|
|
||||||
viewBox="0 0 24 24"
|
|
||||||
>
|
|
||||||
<path
|
|
||||||
strokeLinecap="round"
|
|
||||||
strokeLinejoin="round"
|
|
||||||
strokeWidth="2"
|
|
||||||
d="M4 6h16M4 12h16M4 18h7"
|
|
||||||
>
|
|
||||||
</path>
|
|
||||||
</svg>
|
|
||||||
<div>Table of Contents</div>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<div class="mx-auto max-w-screen-xl flex gap-6 md:gap-8">
|
|
||||||
<DesktopSidebar page={props.page} />
|
<DesktopSidebar page={props.page} />
|
||||||
<Partial name="docs-main">
|
<Partial name="docs-main">
|
||||||
<Content page={props.page} />
|
<Content page={props.page} />
|
||||||
@@ -202,7 +177,7 @@ function Main(props: { page: Page }) {
|
|||||||
|
|
||||||
function MobileSidebar(props: { page: Page }) {
|
function MobileSidebar(props: { page: Page }) {
|
||||||
return (
|
return (
|
||||||
<>
|
<div class="md:hidden">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
class="hidden toggle"
|
class="hidden toggle"
|
||||||
@@ -215,11 +190,8 @@ function MobileSidebar(props: { page: Page }) {
|
|||||||
class="absolute inset-0 bg-gray-600 opacity-75"
|
class="absolute inset-0 bg-gray-600 opacity-75"
|
||||||
for="docs_sidebar"
|
for="docs_sidebar"
|
||||||
/>
|
/>
|
||||||
<div class="relative flex-1 flex flex-col w-[16rem] h-full bg-white border(r-2 gray-100)">
|
<div class="relative flex-1 flex flex-col w-[18rem] h-full bg-white border(r-2 gray-100)">
|
||||||
<div class="p-4 border(b-2 gray-100) bg-green-300">
|
<nav class="pt-0 pb-16 px-4 overflow-x-auto">
|
||||||
<DocsTitle title="docs" />
|
|
||||||
</div>
|
|
||||||
<nav class="pt-6 pb-16 px-4 overflow-x-auto">
|
|
||||||
<DocsSidebar
|
<DocsSidebar
|
||||||
mobile
|
mobile
|
||||||
versionLinks={props.page.versionLinks}
|
versionLinks={props.page.versionLinks}
|
||||||
@@ -228,13 +200,13 @@ function MobileSidebar(props: { page: Page }) {
|
|||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function DesktopSidebar(props: { page: Page }) {
|
function DesktopSidebar(props: { page: Page }) {
|
||||||
return (
|
return (
|
||||||
<nav class="w-[18rem] flex-shrink-0 hidden md:block py-7 px-4">
|
<nav class="w-[18rem] flex-shrink-0 hidden md:block px-4">
|
||||||
<DocsSidebar
|
<DocsSidebar
|
||||||
versionLinks={props.page.versionLinks}
|
versionLinks={props.page.versionLinks}
|
||||||
selectedVersion={props.page.version}
|
selectedVersion={props.page.version}
|
||||||
@@ -246,21 +218,48 @@ function DesktopSidebar(props: { page: Page }) {
|
|||||||
function Content(props: { page: Page }) {
|
function Content(props: { page: Page }) {
|
||||||
const html = renderMarkdown(props.page.markdown);
|
const html = renderMarkdown(props.page.markdown);
|
||||||
return (
|
return (
|
||||||
<main class="py-6 md:mr-4 lg:mr-32 min-w-0">
|
<div class="w-full min-w-0">
|
||||||
<h1 class="text(4xl gray-900) tracking-tight font-extrabold md:mt-0 px-4">
|
<Header title="docs" active="/docs" />
|
||||||
{props.page.title}
|
<main class="max-w-3xl mt-4 min-w-0 mx-auto">
|
||||||
</h1>
|
<MobileSidebar page={props.page} />
|
||||||
<div
|
<div class="flex mx-auto max-w-screen-xl px-4 md:px-0 md:py-0 justify-end bg-gray-100">
|
||||||
class="mt-6 markdown-body"
|
<label
|
||||||
dangerouslySetInnerHTML={{ __html: html }}
|
for="docs_sidebar"
|
||||||
/>
|
class="px-4 py-3 md:hidden flex items-center hover:bg-gray-100 rounded gap-2 cursor-pointer"
|
||||||
<ForwardBackButtons
|
>
|
||||||
slug={props.page.slug}
|
<svg
|
||||||
version={props.page.version}
|
class="h-6 w-6"
|
||||||
prev={props.page.prevNav}
|
stroke="currentColor"
|
||||||
next={props.page.nextNav}
|
fill="none"
|
||||||
/>
|
viewBox="0 0 24 24"
|
||||||
</main>
|
>
|
||||||
|
<path
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
strokeWidth="2"
|
||||||
|
d="M4 6h16M4 12h16M4 18h7"
|
||||||
|
>
|
||||||
|
</path>
|
||||||
|
</svg>
|
||||||
|
<div>Table of Contents</div>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<h1 class="text(4xl gray-900) tracking-tight font-extrabold md:mt-0 px-4">
|
||||||
|
{props.page.title}
|
||||||
|
</h1>
|
||||||
|
<div
|
||||||
|
class="mt-6 markdown-body"
|
||||||
|
dangerouslySetInnerHTML={{ __html: html }}
|
||||||
|
/>
|
||||||
|
<ForwardBackButtons
|
||||||
|
slug={props.page.slug}
|
||||||
|
version={props.page.version}
|
||||||
|
prev={props.page.prevNav}
|
||||||
|
next={props.page.nextNav}
|
||||||
|
/>
|
||||||
|
<Footer />
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user