Prechádzať zdrojové kódy

Upgrade basics by Claude Code

jerryliao 3 dní pred
rodič
commit
3c534c75b9

+ 3 - 1
.gitignore

@@ -1 +1,3 @@
-data
+data
+# Fresh build directory
+_fresh/

+ 15 - 23
deno.json

@@ -2,35 +2,27 @@
   "lock": false,
   "tasks": {
     "check": "deno fmt --check && deno lint && deno check **/*.ts && deno check **/*.tsx",
-    "cli": "echo \"import '\\$fresh/src/dev/cli.ts'\" | deno run --unstable -A -",
-    "manifest": "deno task cli manifest $(pwd)",
-    "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"]
-    }
+    "start": "deno run -A --watch=static/,routes/ main.ts",
+    "build": "vite build",
+    "preview": "deno run -A main.ts"
   },
+  "lint": { "rules": { "tags": ["fresh", "recommended"] } },
   "exclude": ["**/_fresh/*"],
   "imports": {
-    "$fresh/": "https://deno.land/x/fresh@1.6.5/",
-    "preact": "https://esm.sh/preact@10.19.2",
-    "preact/": "https://esm.sh/preact@10.19.2/",
-    "$std/": "https://deno.land/std@0.211.0/",
+    "fresh": "jsr:@fresh/core@^2.2.1",
+    "fresh/": "jsr:@fresh/core@^2.2.1/",
+    "preact": "npm:preact@^10.28.3",
+    "preact/": "npm:preact@^10.28.3/",
+    "@preact/signals": "npm:@preact/signals@^2.5.1",
+    "$std/": "https://deno.land/std@0.224.0/",
     "$sqlite/": "https://deno.land/x/sqlite@v3.8/",
     "$usid/": "https://deno.land/x/usid@2.0.0/",
-    "$encoding/": "https://deno.land/std@0.211.0/encoding/",
-    "$crypto/": "https://deno.land/std@0.211.0/crypto/",
-    "$async/": "https://deno.land/std@0.211.0/async/",
-    "$http/": "https://deno.land/std@0.211.0/http/",
+    "$encoding/": "https://deno.land/std@0.224.0/encoding/",
+    "$crypto/": "https://deno.land/std@0.224.0/crypto/",
+    "$async/": "https://deno.land/std@0.224.0/async/",
+    "$http/": "https://deno.land/std@0.224.0/http/",
     "showdown": "https://esm.sh/showdown@2.1.0",
     "utils/": "./utils/"
   },
-  "compilerOptions": {
-    "jsx": "react-jsx",
-    "jsxImportSource": "preact"
-  }
+  "compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "preact" }
 }

+ 0 - 8
dev.ts

@@ -1,8 +0,0 @@
-#!/usr/bin/env -S deno run -A --watch=static/,routes/
-
-import dev from "$fresh/dev.ts";
-import config from "./fresh.config.ts";
-
-import "$std/dotenv/load.ts";
-
-await dev(import.meta.url, "./main.ts", config);

+ 0 - 3
fresh.config.ts

@@ -1,3 +0,0 @@
-import { defineConfig } from "$fresh/server.ts";
-
-export default defineConfig({});

+ 0 - 53
fresh.gen.ts

@@ -1,53 +0,0 @@
-// 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 * as $_id_ from "./routes/[id].tsx";
-import * as $_404 from "./routes/_404.tsx";
-import * as $_app from "./routes/_app.tsx";
-import * as $api_post from "./routes/api/post.tsx";
-import * as $api_share from "./routes/api/share.tsx";
-import * as $api_user_login from "./routes/api/user/login.tsx";
-import * as $api_user_logout from "./routes/api/user/logout.tsx";
-import * as $api_user_register from "./routes/api/user/register.tsx";
-import * as $api_user_reset from "./routes/api/user/reset.tsx";
-import * as $index from "./routes/index.tsx";
-import * as $login from "./routes/login.tsx";
-import * as $register from "./routes/register.tsx";
-import * as $Editor from "./islands/Editor.tsx";
-import * as $HomeBar from "./islands/HomeBar.tsx";
-import * as $LoginFrame from "./islands/LoginFrame.tsx";
-import * as $Modal from "./islands/Modal.tsx";
-import * as $PostList from "./islands/PostList.tsx";
-import * as $TopBar from "./islands/TopBar.tsx";
-import * as $WelcomeFrame from "./islands/WelcomeFrame.tsx";
-import { type Manifest } from "$fresh/server.ts";
-
-const manifest = {
-  routes: {
-    "./routes/[id].tsx": $_id_,
-    "./routes/_404.tsx": $_404,
-    "./routes/_app.tsx": $_app,
-    "./routes/api/post.tsx": $api_post,
-    "./routes/api/share.tsx": $api_share,
-    "./routes/api/user/login.tsx": $api_user_login,
-    "./routes/api/user/logout.tsx": $api_user_logout,
-    "./routes/api/user/register.tsx": $api_user_register,
-    "./routes/api/user/reset.tsx": $api_user_reset,
-    "./routes/index.tsx": $index,
-    "./routes/login.tsx": $login,
-    "./routes/register.tsx": $register,
-  },
-  islands: {
-    "./islands/Editor.tsx": $Editor,
-    "./islands/HomeBar.tsx": $HomeBar,
-    "./islands/LoginFrame.tsx": $LoginFrame,
-    "./islands/Modal.tsx": $Modal,
-    "./islands/PostList.tsx": $PostList,
-    "./islands/TopBar.tsx": $TopBar,
-    "./islands/WelcomeFrame.tsx": $WelcomeFrame,
-  },
-  baseUrl: import.meta.url,
-} satisfies Manifest;
-
-export default manifest;

+ 1 - 1
islands/Editor.tsx

@@ -1,7 +1,7 @@
 import { render } from "preact";
 import { useEffect, useRef, useState } from "preact/hooks";
 import showdown, { Converter } from "showdown";
-import { asset } from "$fresh/runtime.ts";
+import { asset } from "fresh/runtime";
 import { debounce, DebouncedFunction } from "$async/debounce.ts";
 import { hideLoading } from "utils/ui.ts";
 

+ 1 - 1
islands/WelcomeFrame.tsx

@@ -1,4 +1,4 @@
-import { asset } from "$fresh/runtime.ts";
+import { asset } from "fresh/runtime";
 
 export default function WelcomeFrame() {
   const goLogin = () => {

+ 8 - 10
main.ts

@@ -1,13 +1,11 @@
-/// <reference no-default-lib="true" />
-/// <reference lib="dom" />
-/// <reference lib="dom.iterable" />
-/// <reference lib="dom.asynciterable" />
-/// <reference lib="deno.ns" />
-
 import "$std/dotenv/load.ts";
 
-import { start } from "$fresh/server.ts";
-import manifest from "./fresh.gen.ts";
-import config from "./fresh.config.ts";
+import { App, staticFiles } from "fresh";
+
+const app = new App()
+  .use(staticFiles())
+  .fsRoutes();
 
-await start(manifest, config);
+if (import.meta.main) {
+  await app.listen();
+}

+ 22 - 21
routes/[id].tsx

@@ -1,10 +1,13 @@
-import { Head } from "$fresh/runtime.ts";
-import { Handlers, PageProps } from "$fresh/server.ts";
+import { Head } from "fresh/runtime";
+import { createDefine, HttpError } from "fresh";
+import type { PageProps } from "fresh";
 import { checkToken } from "utils/server.ts";
 import { find } from "utils/db.ts";
 import TopBar from "../islands/TopBar.tsx";
 import Editor, { EditorMode } from "../islands/Editor.tsx";
 
+const define = createDefine<Record<never, never>>();
+
 interface PostProps {
   id: string;
   title: string;
@@ -14,36 +17,34 @@ interface PostProps {
   allowMode: EditorMode;
 }
 
-export const handler: Handlers<PostProps> = {
-  GET(req, ctx) {
-    const tokenUserId = checkToken(req);
+export const handler = define.handlers<PostProps>({
+  GET(ctx) {
+    const tokenUserId = checkToken(ctx.req);
     const postId = ctx.params.id;
     const post = find(
       "Post",
       tokenUserId
-        ? {
-          id: postId,
-          user_id: tokenUserId,
-        }
+        ? { id: postId, user_id: tokenUserId }
         : { id: postId, shared: true },
       ["title", "content", "shared"],
     );
     if (post.length > 0) {
-      return ctx.render({
-        id: postId,
-        isLogined: Boolean(tokenUserId),
-        allowMode: tokenUserId ? EditorMode.Both : EditorMode.Read,
-        title: post[0][0] as string,
-        content: post[0][1] as string,
-        shared: post[0][2] as boolean,
-      });
+      return {
+        data: {
+          id: postId,
+          isLogined: Boolean(tokenUserId),
+          allowMode: tokenUserId ? EditorMode.Both : EditorMode.Read,
+          title: post[0][0] as string,
+          content: post[0][1] as string,
+          shared: post[0][2] as boolean,
+        },
+      };
     }
-    // Redirect to 404 page if not found
-    return ctx.renderNotFound();
+    throw new HttpError(404);
   },
-};
+});
 
-export default function Post(props: PageProps) {
+export default function Post(props: PageProps<PostProps>) {
   return (
     <>
       <Head>

+ 0 - 9
routes/_404.tsx

@@ -1,9 +0,0 @@
-import { PageProps } from "$fresh/server.ts";
-
-export default function NotFound(props: PageProps) {
-  return (
-    <div className="pd-page pd-page-centered">
-      Not Found: {props.url.pathname}
-    </div>
-  );
-}

+ 2 - 2
routes/_app.tsx

@@ -1,5 +1,5 @@
-import { asset, Head } from "$fresh/runtime.ts";
-import { PageProps } from "$fresh/server.ts";
+import { asset, Head } from "fresh/runtime";
+import type { PageProps } from "fresh";
 import Modal from "../islands/Modal.tsx";
 
 export default function App({ Component }: PageProps) {

+ 17 - 0
routes/_error.tsx

@@ -0,0 +1,17 @@
+import { HttpError } from "fresh";
+import type { PageProps } from "fresh";
+
+export default function ErrorPage(props: PageProps) {
+  if (props.error instanceof HttpError && props.error.status === 404) {
+    return (
+      <div className="pd-page pd-page-centered">
+        Not Found: {props.url.pathname}
+      </div>
+    );
+  }
+  return (
+    <div className="pd-page pd-page-centered">
+      Something went wrong
+    </div>
+  );
+}

+ 90 - 100
routes/api/post.tsx

@@ -1,100 +1,90 @@
-import { Handlers } from "$fresh/server.ts";
-import {
-  checkToken,
-  makeErrorResponse,
-  makeSuccessResponse,
-} from "utils/server.ts";
-import { uid } from "$usid/mod.ts";
-import { del, find, insert, update } from "utils/db.ts";
-
-export const handler: Handlers = {
-  async GET(req: Request) {
-    const reqJson = await req.json();
-    const id = reqJson.id;
-    const tokenUserId = checkToken(req);
-    if (id) {
-      const post = find(
-        "Post",
-        tokenUserId
-          ? {
-              id,
-              user_id: tokenUserId,
-            }
-          : {
-              id,
-              shared: true,
-            },
-        ["title", "content"]
-      );
-      if (post.length > 0) {
-        return makeSuccessResponse({
-          title: post[0][0] as string,
-          content: post[0][1] as string,
-        });
-      }
-    }
-    return makeErrorResponse();
-  },
-  async POST(req: Request) {
-    const reqJson = await req.json();
-    const title = reqJson.title || "";
-    const content = reqJson.content || "";
-    const tokenUserId = checkToken(req);
-    if (tokenUserId) {
-      const postId = uid(12);
-      const post = insert("Post", {
-        id: postId,
-        title,
-        content,
-        user_id: tokenUserId,
-        shared: false,
-      });
-      if (post.length > 0) {
-        return makeSuccessResponse(post[0][0] as string);
-      }
-    }
-    return makeErrorResponse();
-  },
-  async PUT(req: Request) {
-    const reqJson = await req.json();
-    const id = reqJson.id;
-    const title = reqJson.title;
-    const content = reqJson.content;
-    const tokenUserId = checkToken(req);
-    if (tokenUserId && id && (title || content)) {
-      const post = find("Post", {
-        id,
-        user_id: tokenUserId,
-      });
-      if (post.length > 0) {
-        const updateObject: { [key: string]: string } = {};
-        if (title) {
-          updateObject["title"] = title;
-        }
-        if (content) {
-          updateObject["content"] = content;
-        }
-        const newPost = update("Post", id, updateObject);
-        if (newPost.length > 0) {
-          return makeSuccessResponse(true);
-        }
-      }
-    }
-    return makeErrorResponse();
-  },
-  async DELETE(req: Request) {
-    const reqJson = await req.json();
-    const id = reqJson.id;
-    const tokenUserId = checkToken(req);
-    if (tokenUserId && id) {
-      const flag = del("Post", {
-        id,
-        user_id: tokenUserId,
-      });
-      if (flag) {
-        return makeSuccessResponse(true);
-      }
-    }
-    return makeErrorResponse();
-  },
-};
+import { createDefine } from "fresh";
+import {
+  checkToken,
+  makeErrorResponse,
+  makeSuccessResponse,
+} from "utils/server.ts";
+import { uid } from "$usid/mod.ts";
+import { del, find, insert, update } from "utils/db.ts";
+
+const define = createDefine<Record<never, never>>();
+
+export const handler = define.handlers({
+  async GET(ctx) {
+    const req = ctx.req;
+    const reqJson = await req.json();
+    const id = reqJson.id;
+    const tokenUserId = checkToken(req);
+    if (id) {
+      const post = find(
+        "Post",
+        tokenUserId
+          ? { id, user_id: tokenUserId }
+          : { id, shared: true },
+        ["title", "content"],
+      );
+      if (post.length > 0) {
+        return makeSuccessResponse({
+          title: post[0][0] as string,
+          content: post[0][1] as string,
+        });
+      }
+    }
+    return makeErrorResponse();
+  },
+  async POST(ctx) {
+    const req = ctx.req;
+    const reqJson = await req.json();
+    const title = reqJson.title || "";
+    const content = reqJson.content || "";
+    const tokenUserId = checkToken(req);
+    if (tokenUserId) {
+      const postId = uid(12);
+      const post = insert("Post", {
+        id: postId,
+        title,
+        content,
+        user_id: tokenUserId,
+        shared: false,
+      });
+      if (post.length > 0) {
+        return makeSuccessResponse(post[0][0] as string);
+      }
+    }
+    return makeErrorResponse();
+  },
+  async PUT(ctx) {
+    const req = ctx.req;
+    const reqJson = await req.json();
+    const id = reqJson.id;
+    const title = reqJson.title;
+    const content = reqJson.content;
+    const tokenUserId = checkToken(req);
+    if (tokenUserId && id && (title || content)) {
+      const post = find("Post", { id, user_id: tokenUserId });
+      if (post.length > 0) {
+        const updateObject: { [key: string]: string } = {};
+        if (title) updateObject["title"] = title;
+        if (content) updateObject["content"] = content;
+        const newPost = update("Post", id, updateObject);
+        if (newPost.length > 0) {
+          return makeSuccessResponse(true);
+        }
+      }
+    }
+    return makeErrorResponse();
+  },
+  async DELETE(ctx) {
+    const req = ctx.req;
+    const reqJson = await req.json();
+    const id = reqJson.id;
+    const tokenUserId = checkToken(req);
+    if (tokenUserId && id) {
+      const flag = del("Post", { id, user_id: tokenUserId });
+      if (flag) {
+        return makeSuccessResponse(true);
+      }
+    }
+    return makeErrorResponse();
+  },
+});

+ 9 - 11
routes/api/share.tsx

@@ -1,4 +1,4 @@
-import { Handlers } from "$fresh/server.ts";
+import { createDefine } from "fresh";
 import {
   checkToken,
   makeErrorResponse,
@@ -6,21 +6,19 @@ import {
 } from "utils/server.ts";
 import { find, update } from "utils/db.ts";
 
-export const handler: Handlers = {
-  async POST(req: Request) {
+const define = createDefine<Record<never, never>>();
+
+export const handler = define.handlers({
+  async POST(ctx) {
+    const req = ctx.req;
     const reqJson = await req.json();
     const id = reqJson.id;
     const shared = reqJson.shared;
     const tokenUserId = checkToken(req);
     if (tokenUserId && id) {
-      const post = find("Post", {
-        id,
-        user_id: tokenUserId,
-      });
+      const post = find("Post", { id, user_id: tokenUserId });
       if (post.length > 0) {
-        const newPost = update("Post", id, {
-          shared: Boolean(shared),
-        });
+        const newPost = update("Post", id, { shared: Boolean(shared) });
         if (newPost.length > 0) {
           return makeSuccessResponse(true);
         }
@@ -28,4 +26,4 @@ export const handler: Handlers = {
     }
     return makeErrorResponse();
   },
-};
+});

+ 52 - 62
routes/api/user/login.tsx

@@ -1,62 +1,52 @@
-import { Handlers } from "$fresh/server.ts";
-import {
-  setToken,
-  checkToken,
-  makeErrorResponse,
-  makeSuccessResponse,
-  getCryptoString,
-} from "utils/server.ts";
-import { find, insert } from "utils/db.ts";
-
-export const handler: Handlers = {
-  GET(req: Request) {
-    const tokenUserId = checkToken(req);
-    if (tokenUserId) {
-      const user = find(
-        "User",
-        {
-          id: tokenUserId,
-        },
-        ["name", "email"]
-      );
-      if (user.length > 0) {
-        return makeSuccessResponse({
-          name: user[0][0] as string,
-          email: user[0][1] as string,
-        });
-      }
-    }
-    return makeErrorResponse();
-  },
-  async POST(req: Request) {
-    const reqJson = await req.json();
-    if (reqJson.email && reqJson.password) {
-      const user = find(
-        "User",
-        {
-          email: reqJson.email,
-        },
-        ["id"]
-      );
-      if (user.length > 0) {
-        // Generate token
-        const token = await getCryptoString(
-          reqJson.email + new Date().toString(),
-          "MD5"
-        );
-
-        // Store token
-        const newToken = insert("Token", {
-          token,
-          user_id: user[0][0] as string,
-        });
-        if (newToken.length > 0) {
-          const successResponse = makeSuccessResponse(true);
-          setToken(successResponse, token);
-          return successResponse;
-        }
-      }
-    }
-    return makeErrorResponse();
-  },
-};
+import { createDefine } from "fresh";
+import {
+  setToken,
+  checkToken,
+  makeErrorResponse,
+  makeSuccessResponse,
+  getCryptoString,
+} from "utils/server.ts";
+import { find, insert } from "utils/db.ts";
+
+const define = createDefine<Record<never, never>>();
+
+export const handler = define.handlers({
+  GET(ctx) {
+    const tokenUserId = checkToken(ctx.req);
+    if (tokenUserId) {
+      const user = find("User", { id: tokenUserId }, ["name", "email"]);
+      if (user.length > 0) {
+        return makeSuccessResponse({
+          name: user[0][0] as string,
+          email: user[0][1] as string,
+        });
+      }
+    }
+    return makeErrorResponse();
+  },
+  async POST(ctx) {
+    const req = ctx.req;
+    const reqJson = await req.json();
+    if (reqJson.email && reqJson.password) {
+      const user = find("User", { email: reqJson.email }, ["id"]);
+      if (user.length > 0) {
+        // Generate token
+        const token = await getCryptoString(
+          reqJson.email + new Date().toString(),
+          "MD5",
+        );
+        // Store token
+        const newToken = insert("Token", {
+          token,
+          user_id: user[0][0] as string,
+        });
+        if (newToken.length > 0) {
+          const successResponse = makeSuccessResponse(true);
+          setToken(successResponse, token);
+          return successResponse;
+        }
+      }
+    }
+    return makeErrorResponse();
+  },
+});

+ 6 - 4
routes/api/user/logout.tsx

@@ -1,10 +1,12 @@
-import { Handlers } from "$fresh/server.ts";
+import { createDefine } from "fresh";
 import { clearToken, makeSuccessResponse } from "utils/server.ts";
 
-export const handler: Handlers = {
-  GET(_req: Request) {
+const define = createDefine<Record<never, never>>();
+
+export const handler = define.handlers({
+  GET(_ctx) {
     const successResponse = makeSuccessResponse(true);
     clearToken(successResponse);
     return successResponse;
   },
-};
+});

+ 8 - 8
routes/api/user/register.tsx

@@ -1,4 +1,4 @@
-import { Handlers } from "$fresh/server.ts";
+import { createDefine } from "fresh";
 import {
   makeErrorResponse,
   makeSuccessResponse,
@@ -6,13 +6,13 @@ import {
 } from "utils/server.ts";
 import { find, insert } from "utils/db.ts";
 
-export const handler: Handlers = {
-  async POST(req: Request) {
-    const reqJson = await req.json();
+const define = createDefine<Record<never, never>>();
+
+export const handler = define.handlers({
+  async POST(ctx) {
+    const reqJson = await ctx.req.json();
     if (reqJson.email && reqJson.password) {
-      const user = find("User", {
-        email: reqJson.email,
-      });
+      const user = find("User", { email: reqJson.email });
       if (user.length === 0) {
         const newUser = insert("User", {
           name: reqJson.email.split("@")[0],
@@ -26,4 +26,4 @@ export const handler: Handlers = {
     }
     return makeErrorResponse();
   },
-};
+});

+ 10 - 14
routes/api/user/reset.tsx

@@ -1,32 +1,28 @@
-import { Handlers } from "$fresh/server.ts";
+import { createDefine } from "fresh";
 import {
   checkToken,
   getCryptoString,
   makeErrorResponse,
   makeSuccessResponse,
-  setToken,
 } from "utils/server.ts";
-import { find, insert, update } from "utils/db.ts";
+import { find, update } from "utils/db.ts";
 
-export const handler: Handlers = {
-  async POST(req: Request) {
+const define = createDefine<Record<never, never>>();
+
+export const handler = define.handlers({
+  async POST(ctx) {
+    const req = ctx.req;
     const reqJson = await req.json();
     const tokenUserId = checkToken(req);
     if (tokenUserId && reqJson.old && reqJson.new) {
-      const user = find(
-        "User",
-        {
-          id: tokenUserId,
-        },
-        ["password"],
-      );
+      const user = find("User", { id: tokenUserId }, ["password"]);
       if (user.length > 0) {
         // Match old password
         if (
           await getCryptoString(reqJson.old, "MD5") === user[0][0] as string
         ) {
           // Store new password
-          const newUser = update("User", tokenUserId, {
+          update("User", tokenUserId, {
             password: await getCryptoString(reqJson.new, "MD5"),
           });
           return makeSuccessResponse(true);
@@ -35,4 +31,4 @@ export const handler: Handlers = {
     }
     return makeErrorResponse();
   },
-};
+});

+ 22 - 22
routes/index.tsx

@@ -1,25 +1,26 @@
-import { Head } from "$fresh/runtime.ts";
-import { Handlers, PageProps } from "$fresh/server.ts";
+import { Head } from "fresh/runtime";
+import { createDefine } from "fresh";
+import type { PageProps } from "fresh";
 import { checkToken } from "utils/server.ts";
 import { find } from "utils/db.ts";
 import HomeBar from "../islands/HomeBar.tsx";
 import PostList from "../islands/PostList.tsx";
 import WelcomeFrame from "../islands/WelcomeFrame.tsx";
 
+const define = createDefine<Record<never, never>>();
+
 interface HomeProps {
   name: string;
   list: { id: string; title: string; content: string; shared: boolean }[];
 }
 
-export const handler: Handlers<HomeProps> = {
-  GET(req, ctx) {
-    const tokenUserId = checkToken(req);
+export const handler = define.handlers<HomeProps>({
+  GET(ctx) {
+    const tokenUserId = checkToken(ctx.req);
     if (tokenUserId) {
       const user = find(
         "User",
-        {
-          id: tokenUserId,
-        },
+        { id: tokenUserId },
         ["name"],
       );
       if (user.length > 0) {
@@ -29,23 +30,22 @@ export const handler: Handlers<HomeProps> = {
           "content",
           "shared",
         ]);
-        return ctx.render({
-          name: user[0][0] as string,
-          list: posts.map((post) => ({
-            id: post[0] as string,
-            title: post[1] as string,
-            content: post[2] as string,
-            shared: post[3] as boolean,
-          })),
-        });
+        return {
+          data: {
+            name: user[0][0] as string,
+            list: posts.map((post) => ({
+              id: post[0] as string,
+              title: post[1] as string,
+              content: post[2] as string,
+              shared: post[3] as boolean,
+            })),
+          },
+        };
       }
     }
-    return ctx.render({
-      name: "",
-      list: [],
-    });
+    return { data: { name: "", list: [] } };
   },
-};
+});
 
 export default function Home(props: PageProps<HomeProps>) {
   return (

+ 1 - 1
routes/login.tsx

@@ -1,4 +1,4 @@
-import { Head } from "$fresh/runtime.ts";
+import { Head } from "fresh/runtime";
 import LoginFrame from "../islands/LoginFrame.tsx";
 
 export default function Login() {

+ 1 - 1
routes/register.tsx

@@ -1,4 +1,4 @@
-import { Head } from "$fresh/runtime.ts";
+import { Head } from "fresh/runtime";
 import LoginFrame from "../islands/LoginFrame.tsx";
 
 export default function Register() {

+ 6 - 0
vite.config.ts

@@ -0,0 +1,6 @@
+import { defineConfig } from "vite";
+import { fresh } from "@fresh/plugin-vite";
+
+export default defineConfig({
+  plugins: [fresh()],
+});