Skip to content

Commit

Permalink
chore: update modules
Browse files Browse the repository at this point in the history
  • Loading branch information
ynwd committed Jul 28, 2024
1 parent 6ade83e commit 9643b67
Show file tree
Hide file tree
Showing 14 changed files with 185 additions and 201 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion modules/admin/admin.layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function adminLayout(
name="viewport"
content="width=device-width, initial-scale=1.0"
/>
<title>{data.title + " | Fastro"}</title>
<title>{data.title}</title>
<meta name="description" content={data.description} />
<meta property="og:image" content={data.image} />
<link href="styles.css" rel="stylesheet" />
Expand Down
50 changes: 50 additions & 0 deletions modules/app/main.ts
Original file line number Diff line number Diff line change
@@ -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();
File renamed without changes.
57 changes: 57 additions & 0 deletions modules/blog/mod.ts
Original file line number Diff line number Diff line change
@@ -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;
}
File renamed without changes.
22 changes: 22 additions & 0 deletions modules/docs/mod.ts
Original file line number Diff line number Diff line change
@@ -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;
}
File renamed without changes.
File renamed without changes.
53 changes: 53 additions & 0 deletions modules/index/mod.ts
Original file line number Diff line number Diff line change
@@ -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;
}
File renamed without changes.
File renamed without changes.
38 changes: 1 addition & 37 deletions tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { type Config } from "npm:[email protected]";
export default {
content: [
"./components/**/*.tsx",
"./web/**/**/*.tsx",
"./modules/**/**/*.tsx",
"./middleware/**/**/*.tsx",
],
theme: {
Expand All @@ -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;
Loading

0 comments on commit 9643b67

Please sign in to comment.