From 43f00eddc85c9d99a468b295607f7725f11d215a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Kl=C3=ADma?= Date: Tue, 14 Nov 2023 00:05:34 +0200 Subject: [PATCH] Updated Fresh to newest version (#57) Resolves #56. --- .vscode/import_map.json | 18 ++++++------ www/components/App.tsx | 8 +++--- www/components/Header.tsx | 52 ++++++++++++++++++----------------- www/components/Icons.tsx | 18 ++++++------ www/deno.json | 30 ++++++++++++++++++-- www/dev.ts | 5 +++- www/fresh.config.ts | 7 +++++ www/fresh.gen.ts | 4 +-- www/import_map.json | 12 -------- www/main.ts | 8 +++--- www/routes/docs/[...slug].tsx | 6 +--- www/routes/index.tsx | 7 +---- 12 files changed, 95 insertions(+), 80 deletions(-) create mode 100644 www/fresh.config.ts delete mode 100644 www/import_map.json diff --git a/.vscode/import_map.json b/.vscode/import_map.json index eeb6b26..7486ca3 100644 --- a/.vscode/import_map.json +++ b/.vscode/import_map.json @@ -1,13 +1,15 @@ { "imports": { - "$fresh/": "https://deno.land/x/fresh@1.1.4/", - "preact": "https://esm.sh/preact@10.11.0", - "preact/": "https://esm.sh/preact@10.11.0/", - "preact-render-to-string": "https://esm.sh/*preact-render-to-string@5.2.4", - "@preact/signals": "https://esm.sh/*@preact/signals@1.0.3", - "@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.0.1", - "twind": "https://esm.sh/twind@0.16.17", - "twind/": "https://esm.sh/twind@0.16.17/", + "$fresh/": "https://deno.land/x/fresh@1.5.4/", + "preact": "https://esm.sh/preact@10.18.1", + "preact/": "https://esm.sh/preact@10.18.1/", + "preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.2", + "@preact/signals": "https://esm.sh/*@preact/signals@1.2.1", + "@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.5.0", + "twind": "https://esm.sh/twind@0.16.19", + "twind/": "https://esm.sh/twind@0.16.19/", + + "$std/": "https://deno.land/std@0.193.0/", "react": "https://esm.sh/preact@10.10.6/compat", "react-dom": "https://esm.sh/preact@10.10.6/compat", diff --git a/www/components/App.tsx b/www/components/App.tsx index eb88f3b..2f144af 100644 --- a/www/components/App.tsx +++ b/www/components/App.tsx @@ -1,5 +1,5 @@ import type { ComponentChildren } from "preact"; -import { Head } from "$fresh/runtime.ts"; +import { asset, Head } from "$fresh/runtime.ts"; import { Footer } from "./Footer.tsx"; import { type ActiveLink, Header } from "./Header.tsx"; @@ -7,18 +7,18 @@ import { Title } from "./Title.tsx"; type AppProps = { children: ComponentChildren; - activeLink: ActiveLink; title?: string; }; -export function App({ children, activeLink, title }: AppProps) { +export function App({ children, title }: AppProps) { return ( <> {title} +
-
+
{children}
diff --git a/www/components/Header.tsx b/www/components/Header.tsx index dc852d7..7ca4dc6 100644 --- a/www/components/Header.tsx +++ b/www/components/Header.tsx @@ -1,11 +1,13 @@ -import { IconExternalLink, IconLDkit } from "./Icons.tsx"; +import type { ComponentChildren } from "preact"; -export function Header(props: { activeLink: ActiveLink }) { +import { IconGitHub, IconLDkit } from "./Icons.tsx"; + +export function Header() { return (
-
+
- +
); @@ -48,38 +50,38 @@ type Writeable = { -readonly [P in keyof T]: T[P] }; type Unpacked = T extends (infer U)[] ? U : T; export type ActiveLink = Unpacked>["url"]; -function Menu(props: { activeLink: ActiveLink }) { +function Menu() { return (
    - {menuItems.map((item) => MenuItem({ ...item, ...props }))} + Home + Documentation + + +
); } -type MenuItemProps = { - title: string; - url: string; - activeLink: ActiveLink; -}; - const baseLinkClass = - "flex flex-row p-4 border-b-2 hover:border-black dark:hover:border-red-700 dark:hover:text-white"; + "table-cell align-middle h-14 px-4 border-b-2 hover:border-black dark:hover:border-red-700 dark:hover:text-white border-transparent"; -function MenuItem({ title, url, activeLink }: MenuItemProps) { - const linkClass = url === activeLink - ? `${baseLinkClass} border-black dark:border-red-700 bg-gray-50 dark:bg-gray-800` - : `${baseLinkClass} border-transparent`; +const activeCurrentLinkClass = + `${baseLinkClass} [data-current]:border-black [data-current]:dark:border-red-700 [data-current]:bg-gray-50 [data-current]:dark:bg-gray-800`; + +const activeAncestorLinkClass = + `${baseLinkClass} [data-ancestor]:border-black [data-ancestor]:dark:border-red-700 [data-ancestor]:bg-gray-50 [data-ancestor]:dark:bg-gray-800`; + +function Link({ url, children }: { + url: string; + children: ComponentChildren; +}) { + const linkClass = url === "/" + ? activeCurrentLinkClass + : activeAncestorLinkClass; return (
  • - {title} - {url.startsWith("http") - ? ( - - - - ) - : null} + {children}
  • ); diff --git a/www/components/Icons.tsx b/www/components/Icons.tsx index 7b49691..6166371 100644 --- a/www/components/Icons.tsx +++ b/www/components/Icons.tsx @@ -44,18 +44,16 @@ export function IconArrowRight() { export function IconGitHub() { return ( ); diff --git a/www/deno.json b/www/deno.json index c3fb3d7..284cae6 100644 --- a/www/deno.json +++ b/www/deno.json @@ -1,8 +1,34 @@ { + "lock": false, "tasks": { - "start": "deno run -A --watch=static/,routes/,data/,../docs/ dev.ts" + "check": "deno fmt --check && deno lint && deno check **/*.ts && deno check **/*.tsx", + "start": "deno run -A --watch=static/,routes/ dev.ts", + "build": "deno run -A dev.ts build", + "preview": "deno run -A main.ts", + "update": "deno run -A -r https://fresh.deno.dev/update ." + }, + "lint": { + "rules": { + "tags": [ + "fresh", + "recommended" + ] + } + }, + "exclude": [ + "**/_fresh/*" + ], + "imports": { + "$fresh/": "https://deno.land/x/fresh@1.5.4/", + "preact": "https://esm.sh/preact@10.18.1", + "preact/": "https://esm.sh/preact@10.18.1/", + "preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.2", + "@preact/signals": "https://esm.sh/*@preact/signals@1.2.1", + "@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.5.0", + "twind": "https://esm.sh/twind@0.16.19", + "twind/": "https://esm.sh/twind@0.16.19/", + "$std/": "https://deno.land/std@0.193.0/" }, - "importMap": "./import_map.json", "compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "preact" diff --git a/www/dev.ts b/www/dev.ts index 2d85d6c..ae73946 100644 --- a/www/dev.ts +++ b/www/dev.ts @@ -1,5 +1,8 @@ #!/usr/bin/env -S deno run -A --watch=static/,routes/ import dev from "$fresh/dev.ts"; +import config from "./fresh.config.ts"; -await dev(import.meta.url, "./main.ts"); +import "$std/dotenv/load.ts"; + +await dev(import.meta.url, "./main.ts", config); diff --git a/www/fresh.config.ts b/www/fresh.config.ts new file mode 100644 index 0000000..548e16a --- /dev/null +++ b/www/fresh.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from "$fresh/server.ts"; +import twindPlugin from "$fresh/plugins/twind.ts"; +import twindConfig from "./twind.config.ts"; + +export default defineConfig({ + plugins: [twindPlugin(twindConfig)], +}); diff --git a/www/fresh.gen.ts b/www/fresh.gen.ts index 39931ed..9dbb7f5 100644 --- a/www/fresh.gen.ts +++ b/www/fresh.gen.ts @@ -1,8 +1,7 @@ -// DO NOT EDIT. This file is generated by fresh. +// DO NOT EDIT. This file is generated by Fresh. // This file SHOULD be checked into source version control. // This file is automatically updated during development when running `dev.ts`. -import config from "./deno.json" assert { type: "json" }; import * as $0 from "./routes/[name].tsx"; import * as $1 from "./routes/_404.tsx"; import * as $2 from "./routes/docs/[...slug].tsx"; @@ -19,7 +18,6 @@ const manifest = { }, islands: {}, baseUrl: import.meta.url, - config, }; export default manifest; diff --git a/www/import_map.json b/www/import_map.json deleted file mode 100644 index 3a7cf57..0000000 --- a/www/import_map.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "imports": { - "$fresh/": "https://deno.land/x/fresh@1.1.4/", - "preact": "https://esm.sh/preact@10.11.0", - "preact/": "https://esm.sh/preact@10.11.0/", - "preact-render-to-string": "https://esm.sh/*preact-render-to-string@5.2.4", - "@preact/signals": "https://esm.sh/*@preact/signals@1.0.3", - "@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.0.1", - "twind": "https://esm.sh/twind@0.16.17", - "twind/": "https://esm.sh/twind@0.16.17/" - } -} diff --git a/www/main.ts b/www/main.ts index bb00964..675f529 100644 --- a/www/main.ts +++ b/www/main.ts @@ -4,10 +4,10 @@ /// /// +import "$std/dotenv/load.ts"; + import { start } from "$fresh/server.ts"; import manifest from "./fresh.gen.ts"; +import config from "./fresh.config.ts"; -import twindPlugin from "$fresh/plugins/twind.ts"; -import twindConfig from "./twind.config.ts"; - -await start(manifest, { plugins: [twindPlugin(twindConfig)] }); +await start(manifest, config); diff --git a/www/routes/docs/[...slug].tsx b/www/routes/docs/[...slug].tsx index 2941441..514c654 100644 --- a/www/routes/docs/[...slug].tsx +++ b/www/routes/docs/[...slug].tsx @@ -1,4 +1,3 @@ -import { Head } from "$fresh/runtime.ts"; import { Handlers, PageProps } from "$fresh/server.ts"; import { gfm } from "../../utils/markdown.ts"; @@ -44,10 +43,7 @@ export const handler: Handlers = { export default function DocsPage(props: PageProps) { return ( - - - - +
    diff --git a/www/routes/index.tsx b/www/routes/index.tsx index 677bd0f..13c4b41 100644 --- a/www/routes/index.tsx +++ b/www/routes/index.tsx @@ -1,5 +1,3 @@ -import { Head } from "$fresh/runtime.ts"; - import { App } from "../components/App.tsx"; import { Jumbo } from "../components/Jumbo.tsx"; import { IconArrowRight } from "../components/Icons.tsx"; @@ -7,10 +5,7 @@ import { gfm } from "../utils/markdown.ts"; export default function Home() { return ( - - - - +
    LDkit