import config from '../nuxt.config' const year = new Date().getFullYear() const makeTag = ( tag, tagName = 'meta') => { const attributes = Object.entries(tag).map( ([ name, value ]) => `${name}="${value}"` ).join(' ') return `<${tagName} ${attributes}>` } const mapMetaTag = ( tag ) => { if ( tag.hasOwnProperty('property') ) { return [ `property-${tag.property}`, makeTag(tag) ] } if ( tag.hasOwnProperty('name') ) { return [ `name-${tag.name}`, makeTag(tag) ] } if ( tag.hasOwnProperty('charset') ) { return [ 'charset', makeTag(tag) ] } } const mapLinkTag = ( tag ) => { return [ `type-${tag.type}`, makeTag(tag, 'link') ] } const defaultMeta = Object.fromEntries(config.head.meta.map( mapMetaTag )) const defaultLinkTags = Object.fromEntries(config.head.link.map( mapLinkTag )) class DefaultLayout { generateMetaTags = function ( renderData ) { const { title = null, description = null, meta: pageMeta = [] } = renderData // console.log('renderData', Object.keys(renderData)) const meta = { ...defaultMeta, 'property-twitter:url': ``, ...Object.fromEntries( pageMeta.map(mapMetaTag) ) } // console.log('renderData.description', renderData.description) // if set // get description from data if ( description ) { // Set meta description meta['name-description'] = `` // Set twitter description meta['property-twitter:description'] = `` } // if set // get title from data if ( title ) { // Set twitter title meta['property-twitter:title'] = `` } return Object.values(meta).join('') } generateLinkTags = ( pageLinkTags = [] ) => { const linkTags = { ...defaultLinkTags, ...Object.fromEntries(pageLinkTags.map( mapLinkTag )) } return Object.values( linkTags ).join('') } render( data ) { const { content, title = null, description = null } = data // Setup inline tailwind this.usingComponent( 'static/tailwind.css' ) // Setup inline tailwind this.usingComponent( 'node_modules/@fontsource/inter/variable.css' ) return /* html */`