/**
 * Copyright JS Foundation and other contributors.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file at
 * https://github.com/jantimon/html-webpack-plugin/blob/main/LICENSE
 *
 * Modified from https://github.com/jantimon/html-webpack-plugin/blob/2f5de7ab9e8bca60e9e200f2e4b4cfab90db28d4/index.js#L800
 */ import { MetaOptions , MetaAttributes } from '@modern-js/utils' ; const tagObjectToString = ( tagDefinition ) => { const attributes = Object . keys ( tagDefinition . attributes || { } ) . filter ( attributeName => tagDefinition . attributes [ attributeName ] !== false ) . map ( attributeName => { if ( tagDefinition . attributes [ attributeName ] === true ) { return attributeName ; } return `${ attributeName }="${ tagDefinition . attributes [ attributeName ] as string }"` ; } ) ; return `<${ [ tagDefinition . tagName ] . concat ( attributes ) . join ( ' ' ) }>${ tagDefinition . innerHTML || '' }${ tagDefinition . voidTag ? '' : `</${ tagDefinition . tagName }>` }` ; } ; export const generateMetaTags = ( metaOptions ? ) : string => { if ( ! metaOptions ) { return '' ; } const metaTagAttributeObjects = Object . keys ( metaOptions ) . map ( metaName => { const metaTagContent = metaOptions [ metaName ] ; return typeof metaTagContent === 'string' ? { name : metaName , content : metaTagContent , } : metaTagContent ; } ) . filter ( attribute => attribute !== false ) ; return metaTagAttributeObjects . map ( metaTagAttributes => { if ( metaTagAttributes === false ) { throw new Error ( 'Invalid meta tag' ) ; } return { tagName : 'meta' , voidTag : true , attributes : metaTagAttributes , } ; } ) . reduce ( ( memo , tagObject ) => `${ memo }\n${ tagObjectToString ( tagObject ) }` , '' ) ; } ;