From 4a46327603e39a9cfb6f99261f911b9c2723d5cd Mon Sep 17 00:00:00 2001 From: 4513ECHO Date: Sat, 22 Feb 2025 11:35:40 +0900 Subject: [PATCH] feat: Replace fresh with honox --- .github/workflows/deploy.yml | 26 +++++++++ .gitignore | 3 +- app/client.ts | 12 ++++ {components => app/components}/Icons.tsx | 14 ++++- app/components/LinkBox.tsx | 23 ++++++++ app/global.d.ts | 8 +++ app/routes/_404.tsx | 8 +++ app/routes/_error.tsx | 12 ++++ app/routes/_renderer.tsx | 38 ++++++++++++ {routes => app/routes}/dot.ts | 8 +-- {routes => app/routes}/index.tsx | 67 +++++++++------------- app/server.ts | 8 +++ app/style.css | 1 + components/Link.tsx | 22 ------- deno.json | 62 ++++++++++---------- dev.ts | 5 -- fresh.config.ts | 7 --- fresh.gen.ts | 25 -------- islands/Toggle.tsx | 28 --------- main.ts | 5 -- {static => public}/.well-known/nostr.json | 0 {static => public}/icon.png | Bin {static => public}/icon.webp | Bin {static => public}/robots.txt | 0 routes/_app.tsx | 41 ------------- routes/_middleware.ts | 65 --------------------- scripts/gravatar.ts | 15 ----- twind.config.ts | 10 ---- vite.config.ts | 21 +++++++ 29 files changed, 236 insertions(+), 298 deletions(-) create mode 100644 .github/workflows/deploy.yml create mode 100644 app/client.ts rename {components => app/components}/Icons.tsx (52%) create mode 100644 app/components/LinkBox.tsx create mode 100644 app/global.d.ts create mode 100644 app/routes/_404.tsx create mode 100644 app/routes/_error.tsx create mode 100644 app/routes/_renderer.tsx rename {routes => app/routes}/dot.ts (51%) rename {routes => app/routes}/index.tsx (55%) create mode 100644 app/server.ts create mode 100644 app/style.css delete mode 100644 components/Link.tsx delete mode 100755 dev.ts delete mode 100644 fresh.config.ts delete mode 100644 fresh.gen.ts delete mode 100644 islands/Toggle.tsx delete mode 100644 main.ts rename {static => public}/.well-known/nostr.json (100%) rename {static => public}/icon.png (100%) rename {static => public}/icon.webp (100%) rename {static => public}/robots.txt (100%) delete mode 100644 routes/_app.tsx delete mode 100644 routes/_middleware.ts delete mode 100644 scripts/gravatar.ts delete mode 100644 twind.config.ts create mode 100644 vite.config.ts diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..eac0b9e --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,26 @@ +name: Deploy + +on: + push: + branches: [main] + +jobs: + deploy: + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@v4 + - uses: denoland/setup-deno@v2 + with: + deno-version: v2.x + - name: Build + run: deno task build + - uses: denoland/deployctl@v1 + with: + entrypoint: dist/index.js + project: 4513echo + include: | + deno.json + dist diff --git a/.gitignore b/.gitignore index c649a99..c925c21 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -/_fresh +/dist +/node_modules diff --git a/app/client.ts b/app/client.ts new file mode 100644 index 0000000..efdfe37 --- /dev/null +++ b/app/client.ts @@ -0,0 +1,12 @@ +import { createClient } from "honox/client"; + +createClient({ + hydrate: async (elem, root) => { + const { hydrateRoot } = await import("react-dom/client"); + hydrateRoot(root, elem); + }, + createElement: async (type, props) => { + const { createElement } = await import("react"); + return createElement(type, props); + }, +}); diff --git a/components/Icons.tsx b/app/components/Icons.tsx similarity index 52% rename from components/Icons.tsx rename to app/components/Icons.tsx index f8c30a5..85e9bcf 100644 --- a/components/Icons.tsx +++ b/app/components/Icons.tsx @@ -5,9 +5,21 @@ export function Sizume() { d="m23,63.5c2.9-1.9,6-3.8,9.5-4.2s7.5,1.2,8.6,4.5c1.5,4.2-2.2,8.4-5.8,11-3.4,2.5-7.1,4.6-11.2,5.6-4.1,1-8.6.7-12.3-1.3-4.3-2.4-6.9-7-7.9-11.8s-.4-9.7.4-14.5C7.4,36,14.5,19.7,26.2,7.3c2.5-2.7,6.1-5.4,9.6-4,3.4,1.4,4.2,5.8,4.1,9.5-.3,11.3-3.3,22.4-8.7,32.3-.7,1.2-1.4,2.5-2.6,3.3s-2.8,1.1-4,.4c-2.2-1.4-1.3-4.9.3-7,3.4-4.8,8.2-8.4,13.8-10.4,3.9-1.4,8.6-1.7,11.7.9,2.4,2.1,3.2,5.5,2.7,8.6s-2.2,5.9-4.1,8.4c-1.4,1.8-3.7,3.6-5.6,2.4-2.2-1.3-1.1-4.7.4-6.8,2.7-4,6.3-8.2,11.1-8.8,5.2-.6,10.1,3.3,11.8,8.2s.7,10.3-1.5,15c-4,8.9-12,15.9-21.4,18.7" fill="none" stroke="currentColor" - stroke-width="3" + strokeWidth="3" > ); } + +export function Twitter() { + return ( + + Twitter + + + ); +} diff --git a/app/components/LinkBox.tsx b/app/components/LinkBox.tsx new file mode 100644 index 0000000..aad0b0a --- /dev/null +++ b/app/components/LinkBox.tsx @@ -0,0 +1,23 @@ +// @ts-types="@types/react" +import type { ReactNode } from "react"; + +export interface LinkProps { + href: string; + name: string; + icon: ReactNode | string; +} + +export function LinkBox(props: LinkProps) { + return ( +
  • + + {typeof props.icon === "string" + ? {props.name} + :
    {props.icon}
    } +

    + {props.name} +

    +
    +
  • + ); +} diff --git a/app/global.d.ts b/app/global.d.ts new file mode 100644 index 0000000..838e8cd --- /dev/null +++ b/app/global.d.ts @@ -0,0 +1,8 @@ +import "hono"; +import "@hono/react-renderer"; + +declare module "@hono/react-renderer" { + interface Props { + title?: string; + } +} diff --git a/app/routes/_404.tsx b/app/routes/_404.tsx new file mode 100644 index 0000000..ab91e4f --- /dev/null +++ b/app/routes/_404.tsx @@ -0,0 +1,8 @@ +import type { NotFoundHandler } from "hono"; + +const handler: NotFoundHandler = (c) => { + c.status(404); + return c.render(

    404 Not Found

    ); +}; + +export default handler; diff --git a/app/routes/_error.tsx b/app/routes/_error.tsx new file mode 100644 index 0000000..5d90824 --- /dev/null +++ b/app/routes/_error.tsx @@ -0,0 +1,12 @@ +import type { ErrorHandler } from "hono"; + +const handler: ErrorHandler = (e, c) => { + if ("getResponse" in e) { + return e.getResponse(); + } + console.error(e.message); + c.status(500); + return c.render(

    Internal Server Error

    ); +}; + +export default handler; diff --git a/app/routes/_renderer.tsx b/app/routes/_renderer.tsx new file mode 100644 index 0000000..9004881 --- /dev/null +++ b/app/routes/_renderer.tsx @@ -0,0 +1,38 @@ +import { reactRenderer } from "@hono/react-renderer"; +import { Link, Script } from "honox/server"; + +export default reactRenderer(({ children, title }) => { + return ( + + + + + {title} + + -