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QAAQ,CAAC,IAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;KACrC;IACD,OAAO,CAAC,YAAY,CAAC,SAAS,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC;AACjD,CAAC","sourcesContent":["/**\n@license\nCopyright (c) 2018 The Polymer Project Authors. All rights reserved.\nThis code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt\nThe complete set of authors may be found at http://polymer.github.io/AUTHORS.txt\nThe complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt\nCode distributed by Google as part of the polymer project is also\nsubject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt\n*/\n\n/**\n Utility method that updates the page's open graph and Twitter card metadata.\n It takes an object as a parameter with the following properties:\n title | description | url | image.\n\n If the `url` is not specified, `window.location.href` will be used; for\n all other properties, if they aren't specified, then that metadata field will not\n be set.\n\n Example (in your top level element or document, or in the router callback):\n\n import { updateMetadata } from 'pwa-helpers/metadata.js';\n\n updateMetadata({\n title: 'My App - view 1',\n description: 'This is my sample app',\n url: window.location.href,\n image: '/assets/view1-hero.png'\n });\n\n*/\nexport const updateMetadata = ({\n title,\n description,\n url,\n image,\n imageAlt\n}: {\n title?: string,\n description?: string,\n url?: string,\n image?: string,\n imageAlt?: string\n}) => {\n if (title) {\n document.title = title;\n setMetaTag('property', 'og:title', title);\n }\n\n if (description) {\n setMetaTag('name', 'description', description);\n setMetaTag('property', 'og:description', description);\n }\n\n if (image) {\n setMetaTag('property', 'og:image', image);\n }\n\n if (imageAlt) {\n setMetaTag('property', 'og:image:alt', imageAlt);\n }\n\n url = url || window.location.href;\n setMetaTag('property', 'og:url', url);\n}\n\n/**\n Utility method to create or update the content of a meta tag based on an\n attribute name/value pair.\n\n Example (in your top level element or document, or in the router callback):\n\n import { setMetaTag } from 'pwa-helpers/metadata.js';\n\n setMetaTag('name', 'twitter:card', 'summary');\n \n This would create the following meta tag in the head of the document (or\n update the content attribute if a meta tag with name=\"twitter:card\" exists):\n\n <meta name=\"twitter:card\" content=\"summary\">\n\n*/\nexport function setMetaTag(attrName:string, attrValue:string, content:string) {\n let element = document.head!.querySelector(`meta[${attrName}=\"${attrValue}\"]`);\n if (!element) {\n element = document.createElement('meta');\n element.setAttribute(attrName, attrValue);\n document.head!.appendChild(element);\n }\n element.setAttribute('content', content || '');\n}\n"]}
\No newline at end of file