Avatar

thierryc

2 public vals
Joined February 16, 2024

Utilities for Classless CSS

Forked from Paul Kinlan's Classless CSS Demo

Usage

For projects that should be pretty in an unopinionated way

Create valimport { randomStyle } from "https://esm.town/v/stevekrouse/classless_css"; export default async function(req: Request): Promise<Response> { return new Response(`<h1>Welcome to Val Town!</h1>${randomStyle}`, { headers: { "Content-Type": "text/html", }, }); }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import frameworks from "https://esm.sh/gh/PaulKinlan/classless-css-demo@1a68518805/src/frameworks.ts";
import { randomize } from "https://esm.town/v/stevekrouse/randomize";
delete frameworks[""];
function absolutePath(url: string) {
if (url.startsWith("http")) return url;
else return `https://classless-css-demo.deno.dev` + url;
}
export const random = randomize(Object.entries(frameworks))[0][1];
export const randomURL = absolutePath(random.cssUrl);
export const randomStyle = `<link rel="stylesheet" href="${randomURL}">`;
export default function(req: Response) {
const url = new URL(req.url);
if (url.pathname === "/") {
// return a list of all the framework names as iframes
return new Response(
"<h1>Fork of Paul Kinlan's Classless CSS</h1>" + Object.entries(frameworks)
.map(
([name, data]) =>
`<div><iframe width="90%" style="padding:10px" src="https://classless-css-demo.deno.dev${data.htmlUrl}"></iframe></div>`)
.join(""),
{
headers: {
"Content-Type": "text/html",
},
},
);
}
const name = url.pathname.replace("/", "");
const framework = frameworks[name] || random;
const frameworkURL = absolutePath(framework.cssUrl);
const frameworkStyle = `<link rel="stylesheet" href="${frameworkURL}">`;
return new Response(`<h1>${framework.name} Classless Style!</h1>${frameworkStyle}`, {
headers: {
"Content-Type": "text/html",
},
});
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { email } from "https://esm.town/v/std/email";
import { fetch } from "https://esm.town/v/std/fetch";
export const isMyWebsiteDown = async () => {
const URL = "https://www.anotherplanet.io";
const [date, time] = new Date().toISOString().split("T");
let ok = true;
let reason: string;
try {
const res = await fetch(URL);
if (res.status !== 200) {
reason = `(status code: ${res.status})`;
ok = false;
}
} catch (e) {
reason = `couldn't fetch: ${e}`;
ok = false;
}
if (!ok) {
const subject = `Website down (${URL})`;
const text = `At ${date} ${time} (UTC), ${URL} was down (reason: ${reason}).`;
await email({ subject, text });
}
};
Next