Widget:Meta

From The Observatory

<script>

 updateMetaTags({
     title: ,
     description: "",
     canonical: ,
     keywords: 
 });
 function updateMetaTags({ title, description, canonical, keywords }) {
   if (title) {
     document.title = title;
   }
   if (description) {
     let metaDesc = document.querySelector('meta[name="description"]');
     if (!metaDesc) {
       metaDesc = document.createElement('meta');
       metaDesc.setAttribute('name', 'description');
       document.head.appendChild(metaDesc);
     }
     metaDesc.setAttribute('content', description);
   }
   if (canonical) {
     let linkCanonical = document.querySelector('link[rel="canonical"]');
     if (!linkCanonical) {
       linkCanonical = document.createElement('link');
       linkCanonical.setAttribute('rel', 'canonical');
       document.head.appendChild(linkCanonical);
     }
     linkCanonical.setAttribute('href', canonical);
   }
   if (keywords) {
     let metaKeys = document.querySelector('meta[name="keywords"]');
     if (!metaKeys) {
       metaKeys = document.createElement('meta');
       metaKeys.setAttribute('name', 'keywords');
       document.head.appendChild(metaKeys);
     }
     metaKeys.setAttribute('content', keywords);
   }
 }

</script>