eno/lib/iso.tsx
2023-04-05 23:34:20 -04:00

34 lines
1010 B
TypeScript

import React from "react";
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:""
};
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;
}