mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Enable structured data for eleventy layout
This commit is contained in:
parent
f45d48db1d
commit
95f9b24174
1 changed files with 22 additions and 1 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import fs from 'fs'
|
||||
import { JSDOM } from 'jsdom'
|
||||
|
||||
import config from '../nuxt.config'
|
||||
import config from '../nuxt.config.js'
|
||||
|
||||
|
||||
console.log('Running Default Layout file')
|
||||
|
|
@ -94,6 +94,9 @@ const cleanNuxtLayout = ( layout ) => {
|
|||
// Set link tags
|
||||
document.querySelector('title').insertAdjacentHTML('afterend', templateVar('link-tags') )
|
||||
|
||||
// Add meta tags after title node
|
||||
document.querySelector('title').insertAdjacentHTML('afterend', templateVar('structured-data') )
|
||||
|
||||
// Add meta tags after title node
|
||||
document.querySelector('title').insertAdjacentHTML('afterend', templateVar('meta-tags') )
|
||||
|
||||
|
|
@ -172,6 +175,21 @@ class DefaultLayout {
|
|||
return Object.values(meta).join('')
|
||||
}
|
||||
|
||||
generateStructuredData = function ( renderData ) {
|
||||
|
||||
const {
|
||||
structuredData = null
|
||||
} = renderData
|
||||
|
||||
// console.log('renderData', Object.keys(renderData))
|
||||
|
||||
if ( structuredData === null ) return ''
|
||||
|
||||
const structuredDataJson = JSON.stringify( structuredData )
|
||||
|
||||
return `<script type="application/ld+json">${ structuredDataJson }</script>`
|
||||
}
|
||||
|
||||
generateLinkTags = ( pageLinkTags = [] ) => {
|
||||
|
||||
const linkTags = {
|
||||
|
|
@ -211,6 +229,9 @@ class DefaultLayout {
|
|||
// this.generateMetaTags( data )
|
||||
workingLayoutString = workingLayoutString.replace( templateVar('meta-tags'), this.generateMetaTags( data ) )
|
||||
|
||||
// Add structured data
|
||||
workingLayoutString = workingLayoutString.replace( templateVar('structured-data'), this.generateStructuredData( data ) )
|
||||
|
||||
// Set page css
|
||||
// document.querySelector('head').insertAdjacentHTML('beforeend', this.getCss() )
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue