diff --git a/website/404.html b/website/404.html new file mode 100644 index 0000000..34bad15 --- /dev/null +++ b/website/404.html @@ -0,0 +1,9 @@ + + +
+
+

Page not found

+
+ +

We couldn't find the page you requested.

+
diff --git a/website/500.html b/website/500.html new file mode 100644 index 0000000..325b330 --- /dev/null +++ b/website/500.html @@ -0,0 +1,9 @@ + + +
+
+

Server Error

+
+ +

Something went wrong in our side, we apologise. Please try again later.

+
diff --git a/website/changelog/index.html b/website/changelog/index.html new file mode 100644 index 0000000..29c9cf3 --- /dev/null +++ b/website/changelog/index.html @@ -0,0 +1,9 @@ + + +
+
+

Changelog

+
+ +

// TODO

+
diff --git a/website/community.html b/website/community.html new file mode 100644 index 0000000..5082e6b --- /dev/null +++ b/website/community.html @@ -0,0 +1,9 @@ + + +
+
+

Community

+
+ +

// TODO

+
diff --git a/website/guide.html b/website/guide.html new file mode 100644 index 0000000..8f8763d --- /dev/null +++ b/website/guide.html @@ -0,0 +1,9 @@ + + +
+
+

Guide

+
+ +

// TODO

+
diff --git a/website/index.html b/website/index.html index 5e28076..b7b19f2 100644 --- a/website/index.html +++ b/website/index.html @@ -1,67 +1,20 @@ - - - - - Atlas — The Web Application Framework for Deno - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + +
+

Atlas

+ The Web Application Framework for Deno 🦕 + Get Started +
+ +
-

Atlas

-

The Web Application Framework for Deno

-

Get Started

+

About

-
-
-

Guide

-
- -

// TODO

-
- -
-
-

About

-
- -

The Atlas framework was born out of the desire to have a batteries-included application framework to run on a modern runtime like Deno.

-

A force multiplier that allows engineers to focus on delivering value, while letting the framework do the heavy lifting support work.

-

Atlas' goal is to be for Deno what Laravel is for PHP, or Rails is for Ruby.

- -

The name Atlas

-

Atlas gets its name from the Greek mythology Titan. It comes from the Ancient Greek work Ἄτλας, roughly means "to uphold, support", which is a fitting descripton for a framework.

-
+

The Atlas framework was born out of the desire to have a batteries-included application framework to run on a modern runtime like Deno.

+

A force multiplier that allows engineers to focus on delivering value, while letting the framework do the heavy lifting support work.

+

Atlas' goal is to be for Deno what Laravel is for PHP, or Rails is for Ruby.

- - - +

The name Atlas

+

Atlas gets its name from the Greek mythology Titan. It comes from the Ancient Greek work Ἄτλας, roughly means "to uphold, support", which is a fitting descripton for a framework.

+
diff --git a/website/main.ts b/website/main.ts index b995264..e6cbe28 100644 --- a/website/main.ts +++ b/website/main.ts @@ -1,44 +1,108 @@ import { contentType, extname, serve } from "./deps.ts"; +// TODO: replace with log module +const logger = console; + +// set cwd for deno deploy const cwd = Deno.cwd().includes("website") ? Deno.cwd() : `${Deno.cwd()}/website`; async function handler(request: Request): Promise { - const { pathname } = new URL(request.url); + const { pathname, search } = new URL(request.url); // infer the content-type from the file extension const extension = extname(pathname); const type = contentType(extension) ?? "text/html"; - try { - let file = await Deno.readTextFile(`${cwd}/index.html`); + // response status + let status = 200; + + // response headers + let headers: Record = { + "content-type": type, + }; + // response body + let body: string | null = null; + + try { // static assets if (pathname.startsWith("/public/")) { - file = await Deno.readTextFile(`${cwd}/public${pathname}`); - } - - console.info(200, `${request.method} ${pathname} (${type})`); + body = await Deno.readTextFile(`${cwd}/${pathname}`); + headers = { + ...headers, + // TODO: fingerprint assets for longer cache TTL + immutable + "cache-control": "public, max-age=900, stale-while-revalidate=900", + }; + } // home + else if (["/", "/index.html"].includes(pathname)) { + body = await Deno.readTextFile(`${cwd}/index.html`); + headers = { + ...headers, + "cache-control": "public, max-age=900, stale-while-revalidate=900", + }; + } // docs + else if (["/docs", "/documentation"].includes(pathname)) { + status = 307; + headers = { + ...headers, + "location": "https://doc.deno.land/https://deno.land/x/atlas", + }; + } // other routes + else { + try { + body = await Deno.readTextFile(`${cwd}/${pathname}.html`); + } // fallback to `/[route]/index.html` + catch (_) { + body = await Deno.readTextFile(`${cwd}/${pathname}/index.html`); + } - return new Response(file, { - headers: { - "content-type": type, - // 15 minutes cache TTL + headers = { + ...headers, "cache-control": "public, max-age=900, stale-while-revalidate=900", - }, - }); + }; + } } catch (error: unknown) { - console.info(404, `${request.method} ${pathname} (${type})`); - console.error((error as Error).message); - - return new Response(null, { - status: 404, - headers: { - "content-type": type, - }, + logger.error((error as Error).message); + + // 404 + if ((error as Error).name === "NotFound") { + status = 404; + body = await Deno.readTextFile(`${cwd}/404.html`); + } // 500 + else { + status = 500; + body = await Deno.readTextFile(`${cwd}/500.html`); + } + } finally { + logger.info(`${status} ${request.method} ${pathname}${search}`); + + const template = await Deno.readTextFile(`${cwd}/template.html`); + + // parse meta data + const title = body?.match(//); + const meta_description = body?.match(//); + + // inject meta data into template + const payload = template + .replaceAll("{{ title }}", title?.at(1) ?? "{{ title }}") + .replaceAll( + "{{ meta_description }}", + meta_description?.at(1) ?? "{{ meta_description }}", + ) + .replaceAll("{{ content }}", body ?? ""); + + // deno-lint-ignore no-unsafe-finally + return new Response(payload, { + status, + headers, }); } } -await serve(handler); +await serve(handler, { + onListen: ({ hostname, port }) => { + logger.info(`Listening on http://${hostname}:${port}`); + }, +}); diff --git a/website/public/browserconfig.xml b/website/public/browserconfig.xml new file mode 100644 index 0000000..00c6284 --- /dev/null +++ b/website/public/browserconfig.xml @@ -0,0 +1,9 @@ + + + + + + #ff2d20 + + + diff --git a/website/template.html b/website/template.html new file mode 100644 index 0000000..0ae3005 --- /dev/null +++ b/website/template.html @@ -0,0 +1,93 @@ + + + + + {{ title }} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ [Logo] + +
+ + {{ content }} + + + +