2023-04-05 20:05:21 -04:00
|
|
|
import React from "react";
|
|
|
|
|
2023-04-05 23:34:20 -04:00
|
|
|
|
|
|
|
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:""
|
2023-04-05 20:05:21 -04:00
|
|
|
};
|
|
|
|
|
2023-04-05 23:34:20 -04:00
|
|
|
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;
|
|
|
|
}
|