Skip to content

Commit

Permalink
Boilerplate text (#2)
Browse files Browse the repository at this point in the history
* home page

* format

* title

* test

* deno test -R

---------

Co-authored-by: Dr. Ernie Prabhakar <19791+drernie@users.noreply.github.com>
  • Loading branch information
drernie and drernie authored Jan 19, 2025
1 parent ec28fce commit 8d5dfd0
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 6 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,3 @@ jobs:
project: "swanfactory-online"
entrypoint: "main.ts"
root: "."


37 changes: 37 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Test
on:
push:
branches:
- "**"
pull_request:
branches:
- "**"

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest

permissions:
id-token: write # Needed for auth with Deno Deploy
contents: read # Needed to clone the repository

steps:
- name: Clone repository
uses: actions/checkout@v4

- name: Install Deno
uses: denoland/setup-deno@v2
with:
deno-version: v2.x

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*

- name: Install step
run: "deno install"

- name: Test
run: "deno test -R"
15 changes: 13 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@ import { serveDir } from "@std/http";
const userPagePattern = new URLPattern({ pathname: "/users/:id" });
const staticPathPattern = new URLPattern({ pathname: "/static/*" });

async function pageResponse(title: string, page: string): Promise<Response> {
const template = await Deno.readTextFile("static/template.html");
const content = await Deno.readTextFile(`static/${page}.html`);
const rendered = template
.replaceAll("{{title}}", title)
.replace("{{content}}", content);
return new Response(rendered, {
headers: { "content-type": "text/html; charset=UTF-8" },
});
}

export default {
fetch(req) {
async fetch(req) {
const url = new URL(req.url);

if (url.pathname === "/") {
return new Response("Home page");
return await pageResponse("Welcome!", "index");
}

const userPageMatch = userPagePattern.exec(url);
Expand Down
4 changes: 2 additions & 2 deletions main_test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { assertEquals } from "@std/assert";
import { assertEquals, assertMatch } from "@std/assert";
import server from "./main.ts";

Deno.test(async function serverFetch() {
const req = new Request("https://deno.land");
const res = await server.fetch(req);
assertEquals(await res.text(), "Home page");
assertMatch(await res.text(), /<title>Welcome!/);
});

Deno.test(async function serverFetchNotFound() {
Expand Down
14 changes: 14 additions & 0 deletions static/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="content">
<p class="intro-text"></p>
The SwanFactory online is your gateway to <strong>Polygogy</strong>—a revolutionary approach to lifelong learning that
empowers everyone to grow, teach, and lead in a continuous cycle of transformation.
</p>
<p class="description"></p>
Dive into the philosophy of Polygogy and discover how you can become a part of this dynamic learning movement:
</p>
<a class="external-link" href="https://theswanfactory.wordpress.com/2025/01/18/the-polygogy-manyfesto-reinventing-lifelong-learning/"
target="_blank">
Read the Polygogy Manyfesto
</a>
<p class="coming-soon">Coming soon: subscribe to our mailing list.</p>
</div>
37 changes: 37 additions & 0 deletions static/template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{title}} - Swan Factory Online</title>
<link
rel="stylesheet"
href="https://www.w3.org/StyleSheets/Core/Swiss"
type="text/css"
>
<style>
.site-footer {
background-color: #f1f1f1;
padding: 20px;
text-align: center;
position: fixed;
bottom: 0;
width: 100%;
font-size: 12px;
font-style: italic;
}
</style>
</head>

<body>
<header class="site-header">
<h1>{{title}}</h1>
</header>
<main>
{{content}}
</main>
<footer class="site-footer">
<p>&copy; 2025 The Swan Factory</p>
</footer>
</body>
</html>

0 comments on commit 8d5dfd0

Please sign in to comment.