metas reorgnaization started

This commit is contained in:
Seth Trowbridge 2023-04-23 22:17:39 -04:00
parent 4613ff38e2
commit fafdeffeeb
4 changed files with 42 additions and 28 deletions

View File

@ -8,7 +8,7 @@ const Comp = React.lazy(()=>import("./deep/component.tsx"));
export default ()=> export default ()=>
{ {
return <div class="p-4 font-sans"> return <div class="p-4 font-sans">
<Iso.Metas title="Main Page!"/> <Iso.Meta.Metas title="Main Page!"/>
<nav class="p-4"> <nav class="p-4">
<a class="text-red-500" href="/">Home</a> <a class="text-red-500" href="/">Home</a>
<a href="/about">About</a> <a href="/about">About</a>

View File

@ -13,7 +13,7 @@ export default ()=>
console.log("render!!") console.log("render!!")
return <div class="p-4 text-red-500"> return <div class="p-4 text-red-500">
<Iso.Metas title="Component!"/> <Iso.Meta.Metas title="Component!"/>
Component Route is: {routeGet.Path.toString()} Component Route is: {routeGet.Path.toString()}
<button className="p-4 bg-green-500 text-white" onClick={e=>{countSet(countGet+1); routeSet(["lol", "idk"], {count:countGet+1});}}>{countGet}</button> <button className="p-4 bg-green-500 text-white" onClick={e=>{countSet(countGet+1); routeSet(["lol", "idk"], {count:countGet+1});}}>{countGet}</button>
<a href="/page/about-us" className="p-2 text(lg blue-500) font-bold">a link</a> <a href="/page/about-us" className="p-2 text(lg blue-500) font-bold">a link</a>

View File

@ -1,20 +1,28 @@
import React from "react"; import React from "react";
type MetasInputs = { [Property in MetaKeys]?: string };
type Meta = {title:string, description:string, keywords:string, image:string, canonical:string } type Meta = {title:string, description:string, keywords:string, image:string, canonical:string }
type MetaKeys = keyof Meta; type MetaKeys = keyof Meta;
export const Meta:Meta = {
export const Meta =
{
Meta: {
title:"", title:"",
description:"", description:"",
keywords:"", keywords:"",
image:"", image:"",
canonical:"" canonical:""
}; } as Meta,
Context: React.createContext([{} as Meta, ()=>{}] as [Get:Meta, Set:React.StateUpdater<Meta>]),
type MetasInputs = { [Property in MetaKeys]?: string }; Provider({children}:{children:Children})
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 binding = React.useState(Meta.Meta);
const subtractive = props.dropUnlisted ? (key:MetaKeys)=> Meta[key] = "" : (key:MetaKeys)=> {}; return <Meta.Context.Provider value={binding}>{children}</Meta.Context.Provider>;
},
Metas(props:{concatListed?:boolean; dropUnlisted?:boolean}&MetasInputs):null
{
const additive = props.concatListed ? (key:MetaKeys, value:string)=> Meta.Meta[key] += value : (key:MetaKeys, value:string)=> Meta.Meta[key] = value;
const subtractive = props.dropUnlisted ? (key:MetaKeys)=> Meta.Meta[key] = "" : (key:MetaKeys)=> {};
Object.keys(Meta).forEach((key)=>{ Object.keys(Meta).forEach((key)=>{
const metaKey = key as MetaKeys; const metaKey = key as MetaKeys;
@ -23,11 +31,12 @@ export const Metas =(props:{concatListed?:boolean; dropUnlisted?:boolean}&MetasI
}) })
if(window.innerWidth) if(window.innerWidth)
{ {
document.title = Meta.title; document.title = Meta.Meta.title;
} }
return null; return null;
} }
};
export type Children = string | number | React.JSX.Element | React.JSX.Element[]; export type Children = string | number | React.JSX.Element | React.JSX.Element[];

View File

@ -226,7 +226,7 @@ FileListen("${url.pathname}", reloadHandler);`;
Iso.Fetch.ServerBlocking = []; Iso.Fetch.ServerBlocking = [];
Iso.Fetch.ServerTouched = new Set(); Iso.Fetch.ServerTouched = new Set();
Iso.Fetch.ServerRemove = new Set(); Iso.Fetch.ServerRemove = new Set();
let app = <Iso.Router.Provider url={url}><App/></Iso.Router.Provider>; let app = <Iso.Router.Provider url={url}><Iso.Meta.Provider><App/></Iso.Meta.Provider></Iso.Router.Provider>;
await Prepass(app) await Prepass(app)
let bake = SSR(app); let bake = SSR(app);
while(Iso.Fetch.ServerBlocking.length) while(Iso.Fetch.ServerBlocking.length)
@ -235,7 +235,7 @@ FileListen("${url.pathname}", reloadHandler);`;
Iso.Fetch.ServerBlocking = []; Iso.Fetch.ServerBlocking = [];
// at this point, anything that was requested that was not cached, has now been loaded and cached // at this point, anything that was requested that was not cached, has now been loaded and cached
// this next render will use cached resources. using a cached resource (if its "Seed" is true) adds it to the "touched" set. // this next render will use cached resources. using a cached resource (if its "Seed" is true) adds it to the "touched" set.
app = <Iso.Router.Provider url={url}><App/></Iso.Router.Provider>; app = <Iso.Router.Provider url={url}><Iso.Meta.Provider><App/></Iso.Meta.Provider></Iso.Router.Provider>;
await Prepass(app) await Prepass(app)
bake = SSR(app); bake = SSR(app);
} }
@ -255,7 +255,7 @@ FileListen("${url.pathname}", reloadHandler);`;
`<!doctype html> `<!doctype html>
<html lang="en"> <html lang="en">
<head> <head>
<title>${Iso.Meta.title}</title> <title>${Iso.Meta.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"/> <meta charset="utf-8"/>
<style data-twind>${results.css}</style> <style data-twind>${results.css}</style>
@ -271,7 +271,12 @@ FileListen("${url.pathname}", reloadHandler);`;
Twind.install(CSS); Twind.install(CSS);
Fetch.Seed(${JSON.stringify(seed)}); Fetch.Seed(${JSON.stringify(seed)});
const hmrWrap = H( ()=>H(App) ); const hmrWrap = H( ()=>H(App) );
hydrate( H(Router.Provider, null, hmrWrap), document.querySelector("#app")); hydrate(
H(Router.Provider, null,
H(Meta.Provider, null, hmrWrap)
),
document.querySelector("#app")
);
</script> </script>
</body> </body>
</html>`; </html>`;