From 91a2fe76c58597c7dcc8bcb0334993e153a882be Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Wed, 5 Apr 2023 23:34:20 -0400 Subject: [PATCH 1/3] metas started --- example/app.tsx | 1 + example/deep/component.tsx | 2 ++ example/deno.json | 1 + lib/iso.tsx | 36 ++++++++++++++++++++++++++++++------ 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/example/app.tsx b/example/app.tsx index f72befd..405429d 100644 --- a/example/app.tsx +++ b/example/app.tsx @@ -9,6 +9,7 @@ export default ()=> console.log(Iso.Meta); const [countGet, countSet] = React.useState(1); return
+

Title!!

subtitle

diff --git a/example/deep/component.tsx b/example/deep/component.tsx index 6c39b7d..637cedd 100644 --- a/example/deep/component.tsx +++ b/example/deep/component.tsx @@ -1,9 +1,11 @@ import React from "react"; +import * as Iso from "@eno/iso"; export default ()=> { const [countGet, countSet] = React.useState(1); return
+ Component!!!
; }; \ No newline at end of file diff --git a/example/deno.json b/example/deno.json index 7f3779e..bb0e33d 100644 --- a/example/deno.json +++ b/example/deno.json @@ -1,4 +1,5 @@ { + "compilerOptions": {"lib": ["deno.window", "dom"]}, "imports": { "react": "https://esm.sh/preact@10.13.2/compat", diff --git a/lib/iso.tsx b/lib/iso.tsx index 9573adf..9243188 100644 --- a/lib/iso.tsx +++ b/lib/iso.tsx @@ -1,10 +1,34 @@ import React from "react"; -type Metas = { - Title?:string, - Description?:string + +type Meta = {title:string, description:string, keywords:string, image:string, canonical:string } +type MetaKeys = keyof Meta; +export const Meta:Meta = { + title:"", + description:"", + keywords:"", + image:"", + canonical:"" }; -export const Meta:Metas = { - Title:"hey" -}; \ No newline at end of file +type MetasInputs = { [Property in MetaKeys]?: string }; +export const Metas =(props:{concatListed?:boolean; dropUnlisted?:boolean}&MetasInputs):null=> +{ + const additive = props.concatListed ? (key:MetaKeys, value:string)=> Meta[key] += value : (key:MetaKeys, value:string)=> Meta[key] = value; + const subtractive = props.dropUnlisted ? (key:MetaKeys)=> Meta[key] = "" : (key:MetaKeys)=> {}; + + Object.keys(Meta).forEach((key)=>{ + const metaKey = key as MetaKeys; + const propValue = props[metaKey]||""; + propValue ? additive(metaKey, propValue) : subtractive(metaKey); + }) + + console.log(`rendering metas`, Meta) + + if(window.innerWidth) + { + document.title = Meta.title; + } + + return null; +} \ No newline at end of file From 767e6816407625a35e40000706202a5814cc8df4 Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Thu, 6 Apr 2023 23:44:27 -0400 Subject: [PATCH 2/3] #8 render title --- deno.json | 2 +- server.tsx | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/deno.json b/deno.json index 9f5a0c2..6ca1e43 100644 --- a/deno.json +++ b/deno.json @@ -14,6 +14,6 @@ "install": "deno install -f -A --unstable --no-lock -n eno server.tsx", "run": "deno run -A --unstable --no-lock server.tsx", "host": "deno run -A --unstable https://deno.land/std@0.181.0/http/file_server.ts", - "complete": "deno task host & cd example && pwd && deno task dev" + "example": "cd example && pwd && deno task dev" } } \ No newline at end of file diff --git a/server.tsx b/server.tsx index 5f73a2f..1e7380a 100644 --- a/server.tsx +++ b/server.tsx @@ -4,6 +4,7 @@ import { debounce } from "https://deno.land/std@0.151.0/async/debounce.ts"; import SSR from "https://esm.sh/v113/preact-render-to-string@6.0.2"; import * as Twind from "https://esm.sh/@twind/core@1.1.3"; import React, {JSX, createElement as h} from "react"; +import * as Iso from "@eno/iso"; const Transpiled = new Map(); const Transpileable =(inFilePath:string):boolean=> @@ -233,9 +234,11 @@ FileListen("${url.pathname}", reloadHandler);`; type = `text/html`; body = ` - + + ${Iso.Meta.title} + @@ -253,7 +256,7 @@ FileListen("${url.pathname}", reloadHandler);`; `; } - return new Response(body, {headers:{"content-type":type as string, "Access-Control-Allow-Origin":"*"}}); + return new Response(body, {headers:{"content-type":type as string, "Access-Control-Allow-Origin":"*", charset:"utf-8"}}); } catch(error) { From 0a5d96ce7ab594c469fb98c002ff5cea577fa0ee Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Fri, 7 Apr 2023 21:36:51 -0400 Subject: [PATCH 3/3] route fixes #12 --- deno.json | 1 - server.tsx | 27 +++++++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/deno.json b/deno.json index 6ca1e43..14eb980 100644 --- a/deno.json +++ b/deno.json @@ -12,7 +12,6 @@ "tasks": { "install": "deno install -f -A --unstable --no-lock -n eno server.tsx", - "run": "deno run -A --unstable --no-lock server.tsx", "host": "deno run -A --unstable https://deno.land/std@0.181.0/http/file_server.ts", "example": "cd example && pwd && deno task dev" } diff --git a/server.tsx b/server.tsx index 1e7380a..f07399e 100644 --- a/server.tsx +++ b/server.tsx @@ -100,7 +100,7 @@ try if(importReact) { ImportObject.imports["react-original"] = importReact; - ImportObject.imports["react"] = `./${LibPath}/react.tsx`; + ImportObject.imports["react"] = `/${LibPath}/react.tsx`; } else { @@ -120,18 +120,23 @@ try const importIso = ImportObject.imports["@eno/iso"]; if(importIso) { - ImportObject.imports["@eno/iso"] = `./${LibPath}/iso.tsx`; + ImportObject.imports["@eno/iso"] = `/${LibPath}/iso.tsx`; } else { } + Object.entries(ImportObject.imports).forEach(([key, value])=>{ + if(value.startsWith("./") && ImportObject.imports) + { + ImportObject.imports[key] = value.substring(1); + } + }) } else { console.log(`No "imports" found in configuration`); } - } catch(e) { @@ -143,6 +148,11 @@ Deno.serve({ port: Deno.args[0]||3000 }, async(_req:Request) => { const url:URL = new URL(_req.url); const fsPath = Deno.cwd()+url.pathname; + const pathParts = url.pathname.substring(1, url.pathname.endsWith("/") ? url.pathname.length-1 : url.pathname.length).split("/"); + const pathLast = pathParts[pathParts.length-1]; + const pathExt:string|undefined = pathLast.split(".")[1]; + + console.log(pathParts, pathLast, pathExt); console.log(`Request for "${url.pathname}"...`); @@ -177,10 +187,9 @@ Deno.serve({ port: Deno.args[0]||3000 }, async(_req:Request) => let type = `text/html`; let body:BodyInit = ``; - const isLib = url.pathname.startsWith(`/${LibPath}/`) + const isLib = url.pathname.startsWith(`/${LibPath}/`); - // serve .tsx .jsx .ts .js - if(Transpileable(url.pathname)) + if(Transpileable(pathLast)) { type = `application/javascript`; if(isLib) @@ -190,8 +199,6 @@ Deno.serve({ port: Deno.args[0]||3000 }, async(_req:Request) => else if(!url.searchParams.get("reload")) { const path = `file://${Deno.cwd().replaceAll("\\", "/")+url.pathname}`; - console.log(path); - const imp = await import(path); const members = []; for( const key in imp ) { members.push(key); } @@ -215,9 +222,9 @@ FileListen("${url.pathname}", reloadHandler);`; } } // serve static media - else if( url.pathname.endsWith("/") === false) + else if( pathExt ) { - type = MIME.typeByExtension(url.pathname.substring(url.pathname.lastIndexOf("."))) || "text/html"; + type = MIME.typeByExtension(pathExt) || "text/html"; if(isLib) { const _fetch = await fetch(import.meta.resolve(`.${url.pathname}`));