website
git clone https://git.pyrossh.dev/website
木 Personal website of pyrossh. Built with astrojs, shiki, vite.
e889ac1
— pyrossh
2026-07-07T14:49:24+05:30
fix: serve timeago.js inline from assets Worker, remove unsupported wrangler config
packages/workers/assets/src/index.ts
CHANGED
|
@@ -1,9 +1,27 @@
|
|
|
1
1
|
export default {
|
|
2
2
|
async fetch(request: Request, env: any): Promise<Response> {
|
|
3
|
-
if (env.ASSETS) {
|
|
4
|
-
|
|
3
|
+
const url = new URL(request.url);
|
|
4
|
+
|
|
5
|
+
if (url.pathname === "/assets/js/timeago.js") {
|
|
6
|
+
return new Response(`class TimeAgo extends HTMLElement {
|
|
7
|
+
connectedCallback() {
|
|
8
|
+
const d = new Date(this.getAttribute("date") || this.getAttribute("data-date"));
|
|
5
|
-
|
|
9
|
+
if (isNaN(d.getTime())) return;
|
|
10
|
+
const rtf = new Intl.RelativeTimeFormat("en", { numeric: "auto" });
|
|
11
|
+
const diff = d.getTime() - Date.now();
|
|
12
|
+
for (const [ms, u] of [[864e5,"day"],[36e5,"hour"],[6e4,"minute"],[1e3,"second"]]) {
|
|
13
|
+
if (Math.abs(diff) >= ms) { this.textContent = rtf.format(Math.round(diff/ms), u); break; }
|
|
6
14
|
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
customElements.define("time-ago", TimeAgo);
|
|
18
|
+
class CurrentYear extends HTMLElement {
|
|
19
|
+
connectedCallback() { this.textContent = String(new Date().getFullYear()); }
|
|
20
|
+
}
|
|
21
|
+
customElements.define("current-year", CurrentYear);
|
|
22
|
+
`, { headers: { "content-type": "application/javascript" } });
|
|
23
|
+
}
|
|
24
|
+
|
|
7
25
|
return new Response("Not found", { status: 404 });
|
|
8
26
|
},
|
|
9
27
|
};
|
packages/workers/dev-router/src/index.ts
CHANGED
|
@@ -51,8 +51,9 @@ const routes: Route[] = [
|
|
|
51
51
|
];
|
|
52
52
|
|
|
53
53
|
export default {
|
|
54
|
-
async fetch(request: Request, env:
|
|
54
|
+
async fetch(request: Request, env: any, ctx: ExecutionContext): Promise<Response> {
|
|
55
55
|
const url = new URL(request.url);
|
|
56
|
+
|
|
56
57
|
for (const route of routes) {
|
|
57
58
|
if (route.pattern.test(url.pathname)) {
|
|
58
59
|
try {
|