Compare commits
No commits in common. "77fa38f53155e87ca92a3927e9e3660231e8a764" and "bf9b56c10dcb1df90889308342c346cbddc0c570" have entirely different histories.
77fa38f531
...
bf9b56c10d
@ -12,7 +12,8 @@
|
|||||||
"tasks":
|
"tasks":
|
||||||
{
|
{
|
||||||
"install": "deno install -f -A --unstable --no-lock -n eno server.tsx",
|
"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",
|
"host": "deno run -A --unstable https://deno.land/std@0.181.0/http/file_server.ts",
|
||||||
"example": "cd example && pwd && deno task dev"
|
"complete": "deno task host & cd example && pwd && deno task dev"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,7 +9,6 @@ export default ()=>
|
|||||||
console.log(Iso.Meta);
|
console.log(Iso.Meta);
|
||||||
const [countGet, countSet] = React.useState(1);
|
const [countGet, countSet] = React.useState(1);
|
||||||
return <div class="p-4 font-sans">
|
return <div class="p-4 font-sans">
|
||||||
<Iso.Metas title="Main Page!"/>
|
|
||||||
<h1 class="my-2 font(bold serif) text(2xl)">Title!!</h1>
|
<h1 class="my-2 font(bold serif) text(2xl)">Title!!</h1>
|
||||||
<h2>subtitle</h2>
|
<h2>subtitle</h2>
|
||||||
<Component/>
|
<Component/>
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import * as Iso from "@eno/iso";
|
|
||||||
|
|
||||||
export default ()=>
|
export default ()=>
|
||||||
{
|
{
|
||||||
const [countGet, countSet] = React.useState(1);
|
const [countGet, countSet] = React.useState(1);
|
||||||
return <div class="p-4 text-red-500">
|
return <div class="p-4 text-red-500">
|
||||||
<Iso.Metas title="Component!"/>
|
|
||||||
Component!!!
|
Component!!!
|
||||||
</div>;
|
</div>;
|
||||||
};
|
};
|
@ -1,5 +1,4 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {"lib": ["deno.window", "dom"]},
|
|
||||||
"imports":
|
"imports":
|
||||||
{
|
{
|
||||||
"react": "https://esm.sh/preact@10.13.2/compat",
|
"react": "https://esm.sh/preact@10.13.2/compat",
|
||||||
|
36
lib/iso.tsx
36
lib/iso.tsx
@ -1,34 +1,10 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
|
type Metas = {
|
||||||
type Meta = {title:string, description:string, keywords:string, image:string, canonical:string }
|
Title?:string,
|
||||||
type MetaKeys = keyof Meta;
|
Description?:string
|
||||||
export const Meta:Meta = {
|
|
||||||
title:"",
|
|
||||||
description:"",
|
|
||||||
keywords:"",
|
|
||||||
image:"",
|
|
||||||
canonical:""
|
|
||||||
};
|
};
|
||||||
|
|
||||||
type MetasInputs = { [Property in MetaKeys]?: string };
|
export const Meta:Metas = {
|
||||||
export const Metas =(props:{concatListed?:boolean; dropUnlisted?:boolean}&MetasInputs):null=>
|
Title:"hey"
|
||||||
{
|
};
|
||||||
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;
|
|
||||||
}
|
|
34
server.tsx
34
server.tsx
@ -4,7 +4,6 @@ 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 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 * as Twind from "https://esm.sh/@twind/core@1.1.3";
|
||||||
import React, {JSX, createElement as h} from "react";
|
import React, {JSX, createElement as h} from "react";
|
||||||
import * as Iso from "@eno/iso";
|
|
||||||
|
|
||||||
const Transpiled = new Map();
|
const Transpiled = new Map();
|
||||||
const Transpileable =(inFilePath:string):boolean=>
|
const Transpileable =(inFilePath:string):boolean=>
|
||||||
@ -100,7 +99,7 @@ try
|
|||||||
if(importReact)
|
if(importReact)
|
||||||
{
|
{
|
||||||
ImportObject.imports["react-original"] = importReact;
|
ImportObject.imports["react-original"] = importReact;
|
||||||
ImportObject.imports["react"] = `/${LibPath}/react.tsx`;
|
ImportObject.imports["react"] = `./${LibPath}/react.tsx`;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -120,23 +119,18 @@ try
|
|||||||
const importIso = ImportObject.imports["@eno/iso"];
|
const importIso = ImportObject.imports["@eno/iso"];
|
||||||
if(importIso)
|
if(importIso)
|
||||||
{
|
{
|
||||||
ImportObject.imports["@eno/iso"] = `/${LibPath}/iso.tsx`;
|
ImportObject.imports["@eno/iso"] = `./${LibPath}/iso.tsx`;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
Object.entries(ImportObject.imports).forEach(([key, value])=>{
|
|
||||||
if(value.startsWith("./") && ImportObject.imports)
|
|
||||||
{
|
|
||||||
ImportObject.imports[key] = value.substring(1);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
console.log(`No "imports" found in configuration`);
|
console.log(`No "imports" found in configuration`);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch(e)
|
catch(e)
|
||||||
{
|
{
|
||||||
@ -148,11 +142,6 @@ Deno.serve({ port: Deno.args[0]||3000 }, async(_req:Request) =>
|
|||||||
{
|
{
|
||||||
const url:URL = new URL(_req.url);
|
const url:URL = new URL(_req.url);
|
||||||
const fsPath = Deno.cwd()+url.pathname;
|
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}"...`);
|
console.log(`Request for "${url.pathname}"...`);
|
||||||
|
|
||||||
@ -187,9 +176,10 @@ Deno.serve({ port: Deno.args[0]||3000 }, async(_req:Request) =>
|
|||||||
let type = `text/html`;
|
let type = `text/html`;
|
||||||
let body:BodyInit = ``;
|
let body:BodyInit = ``;
|
||||||
|
|
||||||
const isLib = url.pathname.startsWith(`/${LibPath}/`);
|
const isLib = url.pathname.startsWith(`/${LibPath}/`)
|
||||||
|
|
||||||
if(Transpileable(pathLast))
|
// serve .tsx .jsx .ts .js
|
||||||
|
if(Transpileable(url.pathname))
|
||||||
{
|
{
|
||||||
type = `application/javascript`;
|
type = `application/javascript`;
|
||||||
if(isLib)
|
if(isLib)
|
||||||
@ -199,6 +189,8 @@ Deno.serve({ port: Deno.args[0]||3000 }, async(_req:Request) =>
|
|||||||
else if(!url.searchParams.get("reload"))
|
else if(!url.searchParams.get("reload"))
|
||||||
{
|
{
|
||||||
const path = `file://${Deno.cwd().replaceAll("\\", "/")+url.pathname}`;
|
const path = `file://${Deno.cwd().replaceAll("\\", "/")+url.pathname}`;
|
||||||
|
console.log(path);
|
||||||
|
|
||||||
const imp = await import(path);
|
const imp = await import(path);
|
||||||
const members = [];
|
const members = [];
|
||||||
for( const key in imp ) { members.push(key); }
|
for( const key in imp ) { members.push(key); }
|
||||||
@ -222,9 +214,9 @@ FileListen("${url.pathname}", reloadHandler);`;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// serve static media
|
// serve static media
|
||||||
else if( pathExt )
|
else if( url.pathname.endsWith("/") === false)
|
||||||
{
|
{
|
||||||
type = MIME.typeByExtension(pathExt) || "text/html";
|
type = MIME.typeByExtension(url.pathname.substring(url.pathname.lastIndexOf("."))) || "text/html";
|
||||||
if(isLib)
|
if(isLib)
|
||||||
{
|
{
|
||||||
const _fetch = await fetch(import.meta.resolve(`.${url.pathname}`));
|
const _fetch = await fetch(import.meta.resolve(`.${url.pathname}`));
|
||||||
@ -241,11 +233,9 @@ FileListen("${url.pathname}", reloadHandler);`;
|
|||||||
|
|
||||||
type = `text/html`;
|
type = `text/html`;
|
||||||
body = `<!doctype html>
|
body = `<!doctype html>
|
||||||
<html lang="en">
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>${Iso.Meta.title}</title>
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<meta charset="utf-8"/>
|
|
||||||
<style data-twind>${results.css}</style>
|
<style data-twind>${results.css}</style>
|
||||||
<script type="importmap">${JSON.stringify(ImportObject)}</script>
|
<script type="importmap">${JSON.stringify(ImportObject)}</script>
|
||||||
<script async src="https://ga.jspm.io/npm:es-module-shims@1.5.1/dist/es-module-shims.js" crossorigin="anonymous"></script>
|
<script async src="https://ga.jspm.io/npm:es-module-shims@1.5.1/dist/es-module-shims.js" crossorigin="anonymous"></script>
|
||||||
@ -263,7 +253,7 @@ FileListen("${url.pathname}", reloadHandler);`;
|
|||||||
</html>`;
|
</html>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Response(body, {headers:{"content-type":type as string, "Access-Control-Allow-Origin":"*", charset:"utf-8"}});
|
return new Response(body, {headers:{"content-type":type as string, "Access-Control-Allow-Origin":"*"}});
|
||||||
}
|
}
|
||||||
catch(error)
|
catch(error)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user