diff --git a/lib/iso.tsx b/lib/iso.tsx index dadcf61..8ea9cd0 100644 --- a/lib/iso.tsx +++ b/lib/iso.tsx @@ -20,7 +20,7 @@ type MetaKeys = keyof Meta; export const Meta = { - Stack:[] as Array, + Stack:[] as MetasStackItem[], Meta: { title:"", description:"", @@ -28,6 +28,47 @@ export const Meta = image:"", canonical:"" } as Meta, + ComputeFinal(inStack:MetasStackItem[], inStart=0) + { + const seed = { + title:"", + description:"", + keywords:"", + image:"", + canonical:"" + }; + if(inStack.length>0) + { + let final = {...seed, ...inStack[0]}; + for(let i=inStart+1; i + { + const lookup = key as MetaKeys + const valPrev = final[lookup]; + const valCurr = curr[lookup]; + if(valPrev && valCurr && curr.concatListed) + { + final[lookup] = valPrev + curr.concatListed + valCurr; + } + else if(!valCurr && curr.dropUnlisted) + { + final[lookup] = ""; + } + else + { + final[lookup] = valCurr||""; + } + }); + } + return final; + } + else + { + return seed; + } + }, Context: React.createContext([[], ()=>{}] as [Get:MetasStackItem[], Set:React.StateUpdater]), Provider({children}:{children:Children}) { @@ -47,24 +88,19 @@ export const Meta = }; }, []); - React.useEffect(()=>{ - const stack = binding[0]; - - const last = stack[stack.length-1]; - console.log("updating page title", stack); - if(last && refElements.current) + React.useEffect(()=> + { + if(refElements.current) { - refElements.current.url.forEach(e=>e.setAttribute("content", last.canonical||"")); + const final = Meta.ComputeFinal(binding[0]); - document.title = last.title||""; - refElements.current.title.forEach(e=>e.setAttribute("content", last.title||"")); - - refElements.current.image.forEach(e=>e.setAttribute("content", last.image||"")); - - refElements.current.description.forEach(e=>e.setAttribute("content", last.description||"")); + refElements.current.url.forEach(e=>e.setAttribute("content", final.canonical||"")); + document.title = final.title; + refElements.current.title.forEach(e=>e.setAttribute("content", final.title||"")); + refElements.current.image.forEach(e=>e.setAttribute("content", final.image||"")); + refElements.current.description.forEach(e=>e.setAttribute("content", final.description||"")); } - - }) + }); return {children}; }, Metas({concatListed=undefined, dropUnlisted=false, ...props}:MetasModeArgs&MetasInputs):null @@ -85,24 +121,6 @@ export const Meta = break; } } - const previous = clone[i]; - if(previous) - { - Object.keys(Meta.Meta).forEach(key=> - { - const lookup = key as MetaKeys - const valPrev = previous[lookup]; - const valCurr = props[lookup]; - if(valPrev && valCurr && concatListed) - { - props[lookup] = valPrev + concatListed + valCurr; - } - if(!valCurr) - { - props[lookup] = dropUnlisted ? "" : valPrev; - } - }); - } clone.splice(i+1, 0, {id, depth, concatListed, dropUnlisted, ...props}); return clone; }); @@ -137,7 +155,7 @@ export const Meta = if(!window.innerWidth && props.title) { - Meta.Meta.title = props.title; + Meta.Stack.push({id, depth, concatListed, dropUnlisted, ...props}); } return null; diff --git a/server.tsx b/server.tsx index 4739c50..306b179 100644 --- a/server.tsx +++ b/server.tsx @@ -393,8 +393,10 @@ else if(App && TwindInst) }); Iso.Fetch.ServerTouched = false; + Iso.Meta.Meta = Iso.Meta.ComputeFinal(Iso.Meta.Stack); + const results = Twind.extract(bake, TwindInst); - + type = `text/html`; body = `