From 9643b671c9a2aea6c31daf3ff1b4022c9278cac4 Mon Sep 17 00:00:00 2001
From: ynwd <10122431+ynwd@users.noreply.github.com>
Date: Sun, 28 Jul 2024 15:24:36 +0700
Subject: [PATCH] chore: update modules
---
deno.json | 2 +-
modules/admin/admin.layout.tsx | 2 +-
modules/app/main.ts | 50 ++++++++
{web => modules/blog}/blog.layout.tsx | 0
modules/blog/mod.ts | 57 +++++++++
{web => modules/docs}/docs.layout.tsx | 0
modules/docs/mod.ts | 22 ++++
{web => modules/index}/index.layout.tsx | 0
{web => modules/index}/index.page.tsx | 0
modules/index/mod.ts | 53 ++++++++
{web => modules/toc}/toc.layout.tsx | 0
{web => modules/toc}/toc.page.tsx | 0
tailwind.config.ts | 38 +-----
web/mod.ts | 162 ------------------------
14 files changed, 185 insertions(+), 201 deletions(-)
create mode 100644 modules/app/main.ts
rename {web => modules/blog}/blog.layout.tsx (100%)
create mode 100644 modules/blog/mod.ts
rename {web => modules/docs}/docs.layout.tsx (100%)
create mode 100644 modules/docs/mod.ts
rename {web => modules/index}/index.layout.tsx (100%)
rename {web => modules/index}/index.page.tsx (100%)
create mode 100644 modules/index/mod.ts
rename {web => modules/toc}/toc.layout.tsx (100%)
rename {web => modules/toc}/toc.page.tsx (100%)
delete mode 100644 web/mod.ts
diff --git a/deno.json b/deno.json
index 206356014..6b13c224f 100644
--- a/deno.json
+++ b/deno.json
@@ -1,7 +1,7 @@
{
"lock": false,
"tasks": {
- "start": "ENV=DEVELOPMENT deno run --env --unstable-kv -A --watch web/mod.ts",
+ "start": "ENV=DEVELOPMENT deno run --env --unstable-kv -A --watch modules/app/main.ts",
"build": "deno run -A --unstable-kv web/mod.ts --build ",
"prod": "deno run --unstable-kv -A web/mod.ts",
"test": "rm -rf .hydrate && rm -rf cov && deno test -A --coverage=cov && deno coverage cov",
diff --git a/modules/admin/admin.layout.tsx b/modules/admin/admin.layout.tsx
index 14ce24760..ca5af1b63 100644
--- a/modules/admin/admin.layout.tsx
+++ b/modules/admin/admin.layout.tsx
@@ -13,7 +13,7 @@ export default function adminLayout(
name="viewport"
content="width=device-width, initial-scale=1.0"
/>
-
{data.title + " | Fastro"}
+ {data.title}
diff --git a/modules/app/main.ts b/modules/app/main.ts
new file mode 100644
index 000000000..eba7777d0
--- /dev/null
+++ b/modules/app/main.ts
@@ -0,0 +1,50 @@
+import Server from "@app/mod.ts";
+import markdown from "@app/middleware/markdown/mod.tsx";
+import blogLayout from "@app/modules/blog/blog.layout.tsx";
+import docsLayout from "@app/modules/docs/docs.layout.tsx";
+import blog from "@app/modules/blog/mod.ts";
+import docs from "@app/modules/docs/mod.ts";
+import index from "@app/modules/index/mod.ts";
+import { tailwind } from "@app/middleware/tailwind/mod.ts";
+import { authModule } from "@app/auth/mod.tsx";
+import { adminModule } from "@app/modules/admin/mod.ts";
+
+const s = new Server();
+
+/** markdown with default folder and prefix */
+s.use(markdown(blogLayout));
+
+/** markdown with 'docs' folder and prefix */
+s.use(markdown(docsLayout, "docs", "docs"));
+
+/** setup tailwind */
+s.use(tailwind());
+
+/** proxy for github repo */
+s.use(async (_req, ctx) => {
+ if (
+ ctx.url.pathname.endsWith(".ts") ||
+ ctx.url.pathname.endsWith(".tsx")
+ ) {
+ const version = ctx.url.pathname.startsWith("/v")
+ ? ""
+ : ctx.url.pathname.startsWith("/canary")
+ ? "/canary"
+ : "/main";
+
+ const path =
+ `https://raw.githubusercontent.com/fastrodev/fastro${version}${ctx.url.pathname}`;
+ const res = await fetch(path);
+ const content = await res.text();
+ return new Response(content);
+ }
+ return ctx.next();
+});
+
+s.group(index);
+s.group(blog);
+s.group(docs);
+s.group(authModule);
+s.group(adminModule);
+
+s.serve();
diff --git a/web/blog.layout.tsx b/modules/blog/blog.layout.tsx
similarity index 100%
rename from web/blog.layout.tsx
rename to modules/blog/blog.layout.tsx
diff --git a/modules/blog/mod.ts b/modules/blog/mod.ts
new file mode 100644
index 000000000..22b2b1f5c
--- /dev/null
+++ b/modules/blog/mod.ts
@@ -0,0 +1,57 @@
+import { Fastro } from "@app/mod.ts";
+import tocLayout from "@app/modules/toc/toc.layout.tsx";
+import tocApp from "../toc/toc.page.tsx";
+
+export default function (s: Fastro) {
+ s.page("/blog", {
+ component: tocApp,
+ layout: tocLayout,
+ folder: "modules/toc",
+ handler: (_req, ctx) => {
+ return ctx.render({
+ title: "Blog",
+ description: "Blog",
+ destination: "/blog",
+ posts: [
+ {
+ title: "Collaboration and Profit Sharing",
+ url: "/blog/collaboration",
+ date: "06/18/2024",
+ },
+ {
+ title: "Set up Tailwind on Deno",
+ url: "/blog/tailwind",
+ date: "01/26/2024",
+ },
+ {
+ title: "Deno KV OAuth Implementation",
+ url: "/blog/oauth",
+ date: "11/15/2023",
+ },
+ {
+ title: "renderToReadableStream",
+ url: "/blog/render_to_readable_stream",
+ date: "10/26/2023",
+ },
+ {
+ title: "React",
+ url: "/blog/react",
+ date: "10/22/2023",
+ },
+ {
+ title: "Preact",
+ url: "/blog/preact_and_encrypted_props",
+ date: "08/16/2023",
+ },
+ {
+ title: "Hello",
+ url: "/blog/hello",
+ date: "11/15/2023",
+ },
+ ],
+ });
+ },
+ });
+
+ return s;
+}
diff --git a/web/docs.layout.tsx b/modules/docs/docs.layout.tsx
similarity index 100%
rename from web/docs.layout.tsx
rename to modules/docs/docs.layout.tsx
diff --git a/modules/docs/mod.ts b/modules/docs/mod.ts
new file mode 100644
index 000000000..17295ca58
--- /dev/null
+++ b/modules/docs/mod.ts
@@ -0,0 +1,22 @@
+import { Fastro } from "@app/mod.ts";
+import tocLayout from "@app/modules/toc/toc.layout.tsx";
+import tocApp from "../toc/toc.page.tsx";
+import { docToc } from "../docs/docs.layout.tsx";
+
+export default function (s: Fastro) {
+ s.page("/docs", {
+ component: tocApp,
+ layout: tocLayout,
+ folder: "modules/toc",
+ handler: (_req, ctx) => {
+ return ctx.render({
+ title: "Docs",
+ description: "Docs",
+ destination: "/docs",
+ posts: docToc,
+ });
+ },
+ });
+
+ return s;
+}
diff --git a/web/index.layout.tsx b/modules/index/index.layout.tsx
similarity index 100%
rename from web/index.layout.tsx
rename to modules/index/index.layout.tsx
diff --git a/web/index.page.tsx b/modules/index/index.page.tsx
similarity index 100%
rename from web/index.page.tsx
rename to modules/index/index.page.tsx
diff --git a/modules/index/mod.ts b/modules/index/mod.ts
new file mode 100644
index 000000000..950b24f9c
--- /dev/null
+++ b/modules/index/mod.ts
@@ -0,0 +1,53 @@
+import { Fastro, HttpRequest } from "@app/mod.ts";
+import indexApp from "../index/index.page.tsx";
+import { index } from "../index/index.layout.tsx";
+
+function init() {
+ const basePath = Deno.env.get("DENO_DEPLOYMENT_ID")
+ ? `https://raw.githubusercontent.com/fastrodev/fastro/main/static`
+ : "http://localhost:8000/static";
+ const code =
+ `import init from "${basePath}/init.ts"; const name = Deno.args[0] ?? 'project'; await init(name);`;
+ return new Response(code, {
+ headers: {
+ "content-type": "application/typescript; charset=utf-8",
+ },
+ });
+}
+
+function denoRunCheck(req: HttpRequest) {
+ const regex = /^Deno\/(\d+\.\d+\.\d+)$/;
+ const string = req.headers.get("user-agent");
+ if (!string) return false;
+ const match = regex.exec(string);
+ if (!match) return false;
+ return true;
+}
+
+export default function (s: Fastro) {
+ /** setup SSR */
+ s.page("/", {
+ component: indexApp,
+ layout: index,
+ folder: "modules/index",
+ handler: (req, ctx) => {
+ const res = denoRunCheck(req);
+ if (res) return init();
+ return ctx.render({
+ title: "Fast & Modular Web Framework",
+ description:
+ "Build SSR web applications with a flat modular architecture",
+ image: "https://fastro.dev/fastro.png",
+ start: Deno.env.get("ENV") === "DEVELOPMENT"
+ ? "http://localhost:8000/docs/start"
+ : "https://fastro.dev/docs/start",
+ baseUrl: Deno.env.get("ENV") === "DEVELOPMENT"
+ ? "http://localhost:8000"
+ : "https://fastro.dev",
+ new: "Collaboration and Profit Sharing",
+ destination: "blog/collaboration",
+ });
+ },
+ });
+ return s;
+}
diff --git a/web/toc.layout.tsx b/modules/toc/toc.layout.tsx
similarity index 100%
rename from web/toc.layout.tsx
rename to modules/toc/toc.layout.tsx
diff --git a/web/toc.page.tsx b/modules/toc/toc.page.tsx
similarity index 100%
rename from web/toc.page.tsx
rename to modules/toc/toc.page.tsx
diff --git a/tailwind.config.ts b/tailwind.config.ts
index b52dfbecf..01a3bed37 100644
--- a/tailwind.config.ts
+++ b/tailwind.config.ts
@@ -6,7 +6,7 @@ import { type Config } from "npm:tailwindcss@3.3.5";
export default {
content: [
"./components/**/*.tsx",
- "./web/**/**/*.tsx",
+ "./modules/**/**/*.tsx",
"./middleware/**/**/*.tsx",
],
theme: {
@@ -27,41 +27,5 @@ export default {
},
},
},
- fontFamily: {
- "body": [
- "Inter",
- "ui-sans-serif",
- "system-ui",
- "-apple-system",
- "system-ui",
- "Segoe UI",
- "Roboto",
- "Helvetica Neue",
- "Arial",
- "Noto Sans",
- "sans-serif",
- "Apple Color Emoji",
- "Segoe UI Emoji",
- "Segoe UI Symbol",
- "Noto Color Emoji",
- ],
- "sans": [
- "Inter",
- "ui-sans-serif",
- "system-ui",
- "-apple-system",
- "system-ui",
- "Segoe UI",
- "Roboto",
- "Helvetica Neue",
- "Arial",
- "Noto Sans",
- "sans-serif",
- "Apple Color Emoji",
- "Segoe UI Emoji",
- "Segoe UI Symbol",
- "Noto Color Emoji",
- ],
- },
},
} satisfies Config;
diff --git a/web/mod.ts b/web/mod.ts
deleted file mode 100644
index 6f3193622..000000000
--- a/web/mod.ts
+++ /dev/null
@@ -1,162 +0,0 @@
-import Server from "@app/mod.ts";
-import indexApp from "@app/web/index.page.tsx";
-import markdown from "@app/middleware/markdown/mod.tsx";
-import blogLayout from "@app/web/blog.layout.tsx";
-import docsLayout, { docToc } from "@app/web/docs.layout.tsx";
-import tocLayout from "@app/web/toc.layout.tsx";
-import tocApp from "@app/web/toc.page.tsx";
-import { index } from "@app/web/index.layout.tsx";
-import { tailwind } from "@app/middleware/tailwind/mod.ts";
-import { HttpRequest } from "@app/http/server/types.ts";
-import { authModule } from "@app/auth/mod.tsx";
-import { adminModule } from "@app/modules/admin/mod.ts";
-
-const s = new Server();
-
-/** markdown with default folder and prefix */
-s.use(markdown(blogLayout));
-
-/** markdown with 'docs' folder and prefix */
-s.use(markdown(docsLayout, "docs", "docs"));
-
-/** setup tailwind */
-s.use(tailwind());
-
-/** setup docs endpoint */
-
-s.page("/docs", {
- component: tocApp,
- layout: tocLayout,
- folder: "web",
- handler: (_req, ctx) => {
- return ctx.render({
- title: "Docs",
- description: "Docs",
- destination: "/docs",
- posts: docToc,
- });
- },
-});
-
-/** proxy for github repo */
-s.use(async (_req, ctx) => {
- if (
- ctx.url.pathname.endsWith(".ts") ||
- ctx.url.pathname.endsWith(".tsx")
- ) {
- const version = ctx.url.pathname.startsWith("/v")
- ? ""
- : ctx.url.pathname.startsWith("/canary")
- ? "/canary"
- : "/main";
-
- const path =
- `https://raw.githubusercontent.com/fastrodev/fastro${version}${ctx.url.pathname}`;
- const res = await fetch(path);
- const content = await res.text();
- return new Response(content);
- }
- return ctx.next();
-});
-
-/** setup SSR */
-s.page("/", {
- component: indexApp,
- layout: index,
- folder: "web",
- handler: (req, ctx) => {
- const res = denoRunCheck(req);
- if (res) return init();
- return ctx.render({
- title: "Fast & Modular Web Framework",
- description:
- "Build SSR web applications with a flat modular architecture",
- image: "https://fastro.dev/fastro.png",
- start: Deno.env.get("ENV") === "DEVELOPMENT"
- ? "http://localhost:8000/docs/start"
- : "https://fastro.dev/docs/start",
- baseUrl: Deno.env.get("ENV") === "DEVELOPMENT"
- ? "http://localhost:8000"
- : "https://fastro.dev",
- new: "Collaboration and Profit Sharing",
- destination: "blog/collaboration",
- });
- },
-});
-
-s.page("/blog", {
- component: tocApp,
- layout: tocLayout,
- folder: "web",
- handler: (_req, ctx) => {
- return ctx.render({
- title: "Blog",
- description: "Blog",
- destination: "/blog",
- posts: [
- {
- title: "Collaboration and Profit Sharing",
- url: "/blog/collaboration",
- date: "06/18/2024",
- },
- {
- title: "Set up Tailwind on Deno",
- url: "/blog/tailwind",
- date: "01/26/2024",
- },
- {
- title: "Deno KV OAuth Implementation",
- url: "/blog/oauth",
- date: "11/15/2023",
- },
- {
- title: "renderToReadableStream",
- url: "/blog/render_to_readable_stream",
- date: "10/26/2023",
- },
- {
- title: "React",
- url: "/blog/react",
- date: "10/22/2023",
- },
- {
- title: "Preact",
- url: "/blog/preact_and_encrypted_props",
- date: "08/16/2023",
- },
- {
- title: "Hello",
- url: "/blog/hello",
- date: "11/15/2023",
- },
- ],
- });
- },
-});
-
-s.group(authModule);
-s.group(adminModule);
-
-s.serve();
-
-function denoRunCheck(req: HttpRequest) {
- const regex = /^Deno\/(\d+\.\d+\.\d+)$/;
- const string = req.headers.get("user-agent");
- if (!string) return false;
- const match = regex.exec(string);
- if (!match) return false;
- return true;
-}
-
-function init() {
- const basePath = Deno.env.get("DENO_DEPLOYMENT_ID")
- ? `https://raw.githubusercontent.com/fastrodev/fastro/main/static`
- : "http://localhost:8000/static";
- const code =
- `import init from "${basePath}/init.ts"; const name = Deno.args[0] ?? 'project'; await init(name);`;
- return new Response(code, {
- headers: {
- "content-type": "application/typescript; charset=utf-8",
- },
- });
-}