Custom pages¶
How to add custom HTML pages, styles, and scripts to Pollux.
Adding a page¶
Create your HTML file in src/layout/:
Import it in src/index.ts and add a route:
import helloPage from "./layout/hello.html" with { type: "text" };
import { html } from "./routes/helpers";
import { pages } from "./routes/pages";
// Add to the pages object
export const extraPages = {
"/hello": () => html(helloPage),
};
Then spread it into the routes in src/index.ts:
Adding scripts¶
- Create your JavaScript file in
src/scripts/ - Include it in your HTML with
<script src="/scripts/your-script.js"></script> - Add a route in
src/routes/assets.ts:
Add the route:
Adding styles¶
- Create your CSS file in
src/styles/ - Include it in your HTML with
<link rel="stylesheet" href="/styles/your-style.css" /> - Add a route in
src/routes/assets.ts:
import helloCss from "../styles/hello.css" with { type: "text" };
// Add the route:
"/styles/hello.css": () => new Response(helloCss, {
headers: { "Content-Type": "text/css" },
}),
Inline JavaScript helpers¶
Pollux provides two global helpers available in all pages:
parseColorString(str)— Parsestext|colorformat and returns{ text, color }createError(msg)— returns a styled error elementisUUIDv7(str)— validates a UUIDv7 string