commit 08f923875ccd97f39cb19e764709a3dd8c157f2f Author: a Date: Sun Oct 20 21:48:23 2024 -0500 noot diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5b4bdef --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# Fresh build directory +_fresh/ +# npm dependencies +node_modules/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..ec0e33e --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# Fresh project + +Your new Fresh project is ready to go. You can follow the Fresh "Getting +Started" guide here: https://fresh.deno.dev/docs/getting-started + +### Usage + +Make sure to install Deno: https://deno.land/manual/getting_started/installation + +Then start the project: + +``` +deno task start +``` + +This will watch the project directory and restart as necessary. diff --git a/app.config.ts b/app.config.ts new file mode 100644 index 0000000..f83b9f7 --- /dev/null +++ b/app.config.ts @@ -0,0 +1,15 @@ +import { container } from "#/lib/container.ts"; +import { ConfigLoader } from "#/lib/config/index.ts"; +const configLoader = await ConfigLoader.New( + "doorgan.yml", + "doorgan.yaml", + Deno.env.get("HOME")+"/.config/doorgan.yml", + Deno.env.get("HOME")+"/.config/doorgan.yaml" +) +container.bind({ + provide: ConfigLoader, + useFactory: () => { + return configLoader; + } +}) + diff --git a/components/Button.tsx b/components/Button.tsx new file mode 100644 index 0000000..f1b80a0 --- /dev/null +++ b/components/Button.tsx @@ -0,0 +1,12 @@ +import { JSX } from "preact"; +import { IS_BROWSER } from "$fresh/runtime.ts"; + +export function Button(props: JSX.HTMLAttributes) { + return ( + +

{props.count}

+ + + ); +} diff --git a/islands/MagicPage.tsx b/islands/MagicPage.tsx new file mode 100644 index 0000000..e073cac --- /dev/null +++ b/islands/MagicPage.tsx @@ -0,0 +1,64 @@ +import type { Config, Item, Page } from "#/lib/config/types.ts"; +import { useState } from "preact/hooks"; + + +interface MagicPageProps { + config: Config; + page: Page; +} + + +export default function MagicPage(props: MagicPageProps) { + const {page, config} = props + const [iframeUrl, setIframeUrl]= useState(undefined) + return ( +
+
+ { + page?.categories?.map((category, idx) => { + return ( +
+

{category.name}

+
+ { + category.items?.map((item,idx) => { + return ( +
+
{ + console.log("click event", e) + if(e.buttons === 4) { + globalThis.window.open(item.href, "_blank") + } else if(e.buttons === 1) { + if(item.iframe) { + setIframeUrl(item.href) + } else{ + globalThis.window.open(item.href, "_blank") + } + } + }}> +

{item.iframe && "!"}{item.name}

+
+
+ ); + }) + } +
+
+ ); + }) + } +
+
+ {iframeUrl && + + } +
+
+ ); +} diff --git a/lib/config/index.ts b/lib/config/index.ts new file mode 100644 index 0000000..f1b7631 --- /dev/null +++ b/lib/config/index.ts @@ -0,0 +1,57 @@ +import type { Config } from "#/lib/config/types.ts"; +import { configSchema } from "#/lib/config/types.zod.ts"; +import { parse } from "jsr:@std/yaml"; +import { debounce } from "jsr:@std/async/debounce"; + +export * from "#/lib/config/types.ts" + +export class ConfigLoader { + private currentConfig: Config + private path: string + + constructor(firstConfig: Config, path:string) { + this.path = path + this.currentConfig = firstConfig + const run = debounce(async (e: Deno.FsEvent)=>{ + console.log("config file hmr", e); + const fileText = await Deno.readTextFile(path) + const parsed = parse(fileText) + return [await configSchema.parseAsync(parsed), path] + }, 250) + const watch = async ()=>{ + const watcher = Deno.watchFs(path) + for await (const event of watcher) { + if(event.kind === "remove") { + return + } + run(event) + } + } + watch() + } + + static async New(...paths: string[]) { + const [config, configPath] = await this.firstLoad(paths) + return new ConfigLoader(config, configPath) + + } + config(): Config { + return this.currentConfig + } + static async firstLoad(paths: string[]): Promise<[Config, string]>{ + const errs = [] + for (const path of paths) { + let fileText:string + try { + fileText = await Deno.readTextFile(path) + } catch (e) { + errs.push(e) + console.error(`Failed to load config from ${path}: ${e}`) + continue + } + const parsed = parse(fileText) + return [await configSchema.parseAsync(parsed), path] + } + throw new AggregateError(errs) + } +} diff --git a/lib/config/types.ts b/lib/config/types.ts new file mode 100644 index 0000000..bf3b471 --- /dev/null +++ b/lib/config/types.ts @@ -0,0 +1,23 @@ +export interface Config { + title?: string; + favicon?: string; + faviconType?: string; + pages?: Page[]; +} + +export interface Page { + name?: string; + title?: string; + categories?: Category[]; +} + +export interface Category { + name?: string; + items?: Item[]; +} + +export interface Item { + name: string; + href: string; + iframe?: boolean; +} diff --git a/lib/config/types.zod.ts b/lib/config/types.zod.ts new file mode 100644 index 0000000..c5cff50 --- /dev/null +++ b/lib/config/types.zod.ts @@ -0,0 +1,26 @@ +// Generated by ts-to-zod +import { z } from "zod"; + +export const itemSchema = z.object({ + name: z.string(), + href: z.string(), + iframe: z.boolean().optional(), +}); + +export const categorySchema = z.object({ + name: z.string().optional(), + items: z.array(itemSchema).optional(), +}); + +export const pageSchema = z.object({ + name: z.string().optional(), + title: z.string().optional(), + categories: z.array(categorySchema).optional(), +}); + +export const configSchema = z.object({ + title: z.string().optional(), + favicon: z.string().optional(), + faviconType: z.string().optional(), + pages: z.array(pageSchema).optional(), +}); diff --git a/lib/container.ts b/lib/container.ts new file mode 100644 index 0000000..695a6cc --- /dev/null +++ b/lib/container.ts @@ -0,0 +1,3 @@ +import { Container } from "@needle-di/core"; + +export const container = new Container(); diff --git a/main.ts b/main.ts new file mode 100644 index 0000000..c50bb36 --- /dev/null +++ b/main.ts @@ -0,0 +1,14 @@ +/// +/// +/// +/// +/// + +import "$std/dotenv/load.ts"; +import "#/app.config.ts"; + +import { start } from "$fresh/server.ts"; +import manifest from "#/fresh.gen.ts"; +import config from "#/fresh.config.ts"; + +await start(manifest, config); diff --git a/routes/[page].ts/index.tsx b/routes/[page].ts/index.tsx new file mode 100644 index 0000000..ec1292f --- /dev/null +++ b/routes/[page].ts/index.tsx @@ -0,0 +1,18 @@ +import {useContext} from "preact/hooks"; +import { ConfigContext } from "#/routes/_app.tsx"; +import type { PageProps } from "$fresh/server.ts"; + + +export default function SubPage(props: PageProps) { + const config = useContext(ConfigContext); + const page = config.pages?.find((page) => page.title === props.params.page); + if(!page) { + return
page not found
+ } + return ( +
+
+
+
+ ); +} diff --git a/routes/_404.tsx b/routes/_404.tsx new file mode 100644 index 0000000..c63ae2e --- /dev/null +++ b/routes/_404.tsx @@ -0,0 +1,27 @@ +import { Head } from "$fresh/runtime.ts"; + +export default function Error404() { + return ( + <> + + 404 - Page not found + +
+
+ the Fresh logo: a sliced lemon dripping with juice +

404 - Page not found

+

+ The page you were looking for doesn't exist. +

+ Go back home +
+
+ + ); +} diff --git a/routes/_app.tsx b/routes/_app.tsx new file mode 100644 index 0000000..e7ec1ff --- /dev/null +++ b/routes/_app.tsx @@ -0,0 +1,34 @@ +import { type PageProps } from "$fresh/server.ts"; +import { Partial } from "$fresh/runtime.ts"; +import { container } from "#/lib/container.ts"; +import { ConfigLoader } from "#/lib/config/index.ts"; +import { createContext } from "preact" +import type { Config } from "#/lib/config/types.ts"; +const configLoader = container.get(ConfigLoader); +const config = configLoader.config() +export const ConfigContext = createContext(config) + + +export default function App({ Component }: PageProps) { + const config = configLoader.config() + return ( + + + + + {config.title || "new tab"} + + { + config.favicon && + } + + + + + + + + + + ); +} diff --git a/routes/index.tsx b/routes/index.tsx new file mode 100644 index 0000000..a697169 --- /dev/null +++ b/routes/index.tsx @@ -0,0 +1,17 @@ +import { container } from "#/lib/container.ts"; +import { ConfigLoader } from "#/lib/config/index.ts"; +import MagicPage from "#/islands/MagicPage.tsx"; + + + + +export default function HomePage() { + const configLoader = container.get(ConfigLoader); + const config = configLoader.config() + let page = config.pages?.find((page) => page.name === undefined || page.name === "index"); + if(page === undefined) { + page = { + } + } + return ; +} diff --git a/static/favicon.ico b/static/favicon.ico new file mode 100644 index 0000000..1cfaaa2 Binary files /dev/null and b/static/favicon.ico differ diff --git a/static/logo.svg b/static/logo.svg new file mode 100644 index 0000000..ef2fbe4 --- /dev/null +++ b/static/logo.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/static/styles.css b/static/styles.css new file mode 100644 index 0000000..bd6213e --- /dev/null +++ b/static/styles.css @@ -0,0 +1,3 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; \ No newline at end of file diff --git a/tailwind.config.ts b/tailwind.config.ts new file mode 100644 index 0000000..995bc39 --- /dev/null +++ b/tailwind.config.ts @@ -0,0 +1,7 @@ +import { type Config } from "tailwindcss"; + +export default { + content: [ + "{routes,islands,components}/**/*.{ts,tsx,js,jsx}", + ], +} satisfies Config;