From 13fdf05a91226e9691ebffd06628fb7477617b11 Mon Sep 17 00:00:00 2001 From: Niki Wix Skaarup Date: Sat, 12 Apr 2025 20:25:38 +0200 Subject: [PATCH] restructured and simplified favicon --- bunfig.toml | 2 ++ image-plugin.ts | 30 ++++++++++++++++++++ src/client/components/login.svelte | 6 ++-- src/client/components/progress-table.svelte | 2 +- src/client/index.html | 22 -------------- src/client/util.ts | 2 +- src/images.d.ts | 25 ++++++++++++++++ src/index.ts | 28 +++++++----------- src/{client => routes}/index.css | 12 ++------ src/routes/index.html | 19 +++++++++++++ src/{client => routes}/index.svelte | 10 +++---- src/{client => routes}/index.ts | 1 - src/server/db/index.ts | 2 +- src/{client => }/static/favicon.png | Bin src/{client => }/static/manifest.json | 0 src/{client => }/static/robots.txt | 0 src/{client => }/static/sitemap.txt | 0 tsconfig.json | 16 ++++++++++- 18 files changed, 117 insertions(+), 60 deletions(-) create mode 100644 image-plugin.ts delete mode 100644 src/client/index.html create mode 100644 src/images.d.ts rename src/{client => routes}/index.css (60%) create mode 100644 src/routes/index.html rename src/{client => routes}/index.svelte (51%) rename src/{client => routes}/index.ts (97%) rename src/{client => }/static/favicon.png (100%) rename src/{client => }/static/manifest.json (100%) rename src/{client => }/static/robots.txt (100%) rename src/{client => }/static/sitemap.txt (100%) diff --git a/bunfig.toml b/bunfig.toml index 676dd9e..9fb5867 100644 --- a/bunfig.toml +++ b/bunfig.toml @@ -1,3 +1,5 @@ +preload = ["./image-plugin.ts"] + [install.scopes] "@jsr" = "https://npm.jsr.io" diff --git a/image-plugin.ts b/image-plugin.ts new file mode 100644 index 0000000..9f08d92 --- /dev/null +++ b/image-plugin.ts @@ -0,0 +1,30 @@ +import { plugin, type BunPlugin } from "bun"; +import { readFileSync } from 'fs'; + +const imageLoaderPlugin: BunPlugin = { + name: "image-loader", + setup(builder) { + builder.onLoad({ filter: /\.(png|jpg|jpeg|webp)/ }, async ({ path }) => { + try { + const file = Bun.file(path); + const bytes = await file.bytes(); + return { + exports: { default: bytes }, + loader: "object", + } + } catch (err) { + console.error(err); + if (err instanceof Error) { + throw new Error(`Failed to load file: ${err.message}`); + } else if (typeof err === 'string') { + throw new Error(`Failed to load file: ${err}`); + } + throw new Error("Failed to load file"); + } + }); + } +}; + +plugin(imageLoaderPlugin); + +export default imageLoaderPlugin; diff --git a/src/client/components/login.svelte b/src/client/components/login.svelte index 9cd40c1..a1e49b2 100644 --- a/src/client/components/login.svelte +++ b/src/client/components/login.svelte @@ -1,9 +1,11 @@ - - - -
- - diff --git a/src/client/util.ts b/src/client/util.ts index e8ef1ff..d642ddf 100644 --- a/src/client/util.ts +++ b/src/client/util.ts @@ -1,5 +1,5 @@ import { userstate } from './shared.svelte'; -import type { SelectEntry } from '../server/pt-api'; +import type { SelectEntry } from '@server/pt-api'; export async function fetchEntries(retry: boolean = false): Promise { try { diff --git a/src/images.d.ts b/src/images.d.ts new file mode 100644 index 0000000..790fdbc --- /dev/null +++ b/src/images.d.ts @@ -0,0 +1,25 @@ + +declare module '*.png' { + const value: Uint8Array; + // const file: Bun.BunFile; + // export { file }; + export default value; +} +declare module '*.jpeg' { + const value: Uint8Array; + // const file: Bun.BunFile; + // export { file }; + export default value; +} +declare module '*.jpg' { + const value: Uint8Array; + // const file: Bun.BunFile; + // export { file }; + export default value; +} +declare module '*.webp' { + const value: Uint8Array; + // const file: Bun.BunFile; + // export { file }; + export default value; +} diff --git a/src/index.ts b/src/index.ts index 3d6a8a1..eef39a1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,18 +1,14 @@ -import { env } from 'bun'; -import homepage from './client/index.html'; -import robotsTxt from './client/static/robots.txt'; -import sitemapTxt from './client/static/sitemap.txt'; -// @ts-ignore ts2307 -import icon from './client/static/favicon.png' with { type: 'file' }; -const favicon = await Bun.file(icon).bytes(); -const development = env.NODE_ENV !== 'production'; -import { randomUUIDv7 } from 'bun'; -import ptApi from './server/pt-api'; -import auth from './server/auth'; +import { env, randomUUIDv7 } from 'bun'; +import homepage from '@routes/index.html'; +import robotsTxt from '@static/robots.txt'; +import sitemapTxt from '@static/sitemap.txt'; +import favicon from '@static/favicon.png'; +import ptApi from '@server/pt-api'; +import auth from '@server/auth'; -declare global { - var loginTokens: Set; -} +const development = env.NODE_ENV !== 'production'; + +const faviconInit = { headers: new Headers({ 'Content-Type': 'image/png' }) }; let entriesCache = ''; let entriesCacheTime = 0; @@ -36,9 +32,7 @@ Bun.serve({ '/sitemap.txt': new Response(sitemapTxt, { headers: { 'Content-Type': 'text/plain' }, }), - '/favicon.ico': new Response(favicon, { - headers: { 'Content-Type': 'image/png' }, - }), + '/favicon.ico': new Response(favicon, faviconInit), '/health': new Response('OK'), '/api/entries': { async GET(req) { diff --git a/src/client/index.css b/src/routes/index.css similarity index 60% rename from src/client/index.css rename to src/routes/index.css index acc8c12..4faa1ed 100644 --- a/src/client/index.css +++ b/src/routes/index.css @@ -1,5 +1,4 @@ -@import 'tailwindcss' source('.'); -@source './components/main.svelte'; +@import 'tailwindcss' source('../'); @theme { --breakout-size: calc((var(--breakpoint-xl) - var(--breakpoint-lg)) / 2); @@ -20,15 +19,10 @@ .content { grid-template-columns: - [ultrawide-start] var(--ultrawide-val) - [breakout-start] var(--breakout-val) - [content-start] var(--content-val) - [content-end] var(--breakout-val) - [breakout-end] var(--ultrawide-val) - [ultrawide-end]; + [ultrawide-start] var(--ultrawide-val) [breakout-start] var(--breakout-val) [content-start] var(--content-val) [content-end] var(--breakout-val) [breakout-end] var(--ultrawide-val) [ultrawide-end]; } - .content > * { + .content>* { grid-column: content; } } diff --git a/src/routes/index.html b/src/routes/index.html new file mode 100644 index 0000000..48ad6fa --- /dev/null +++ b/src/routes/index.html @@ -0,0 +1,19 @@ + + + + Progress tracker + + + + + + + + + + +
+ + diff --git a/src/client/index.svelte b/src/routes/index.svelte similarity index 51% rename from src/client/index.svelte rename to src/routes/index.svelte index b07b08b..0c0192e 100644 --- a/src/client/index.svelte +++ b/src/routes/index.svelte @@ -1,10 +1,10 @@ diff --git a/src/client/index.ts b/src/routes/index.ts similarity index 97% rename from src/client/index.ts rename to src/routes/index.ts index 3a852b5..99e0b8c 100644 --- a/src/client/index.ts +++ b/src/routes/index.ts @@ -1,6 +1,5 @@ import { mount, unmount } from 'svelte'; import index from './index.svelte'; -import './index.css'; declare global { var didMount: boolean | undefined; diff --git a/src/server/db/index.ts b/src/server/db/index.ts index 7e04444..b754c07 100644 --- a/src/server/db/index.ts +++ b/src/server/db/index.ts @@ -1,7 +1,7 @@ import { Database } from 'bun:sqlite'; import { env } from 'bun'; import { drizzle } from 'drizzle-orm/bun-sqlite'; -import { createWrappedTimer } from '../wrapped-timer'; +import { createWrappedTimer } from '@server/wrapped-timer'; import { users } from './schema'; function initDb() { diff --git a/src/client/static/favicon.png b/src/static/favicon.png similarity index 100% rename from src/client/static/favicon.png rename to src/static/favicon.png diff --git a/src/client/static/manifest.json b/src/static/manifest.json similarity index 100% rename from src/client/static/manifest.json rename to src/static/manifest.json diff --git a/src/client/static/robots.txt b/src/static/robots.txt similarity index 100% rename from src/client/static/robots.txt rename to src/static/robots.txt diff --git a/src/client/static/sitemap.txt b/src/static/sitemap.txt similarity index 100% rename from src/client/static/sitemap.txt rename to src/static/sitemap.txt diff --git a/tsconfig.json b/tsconfig.json index eb040b6..7e9f16c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -23,7 +23,21 @@ // Some stricter flags (disabled by default) "noUnusedLocals": false, "noUnusedParameters": false, - "noPropertyAccessFromIndexSignature": false + "noPropertyAccessFromIndexSignature": false, + "paths": { + "@client/*": [ + "./src/client/*" + ], + "@server/*": [ + "./src/server/*" + ], + "@routes/*": [ + "./src/routes/*" + ], + "@static/*": [ + "./src/static/*" + ], + } }, "exclude": [ "node_modules"