Skip to content

Commit

Permalink
feat: add injecting of ld+json schema in head
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Gdula authored and mercs600 committed Oct 28, 2021
1 parent 2f03cfe commit 50c93fe
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
22 changes: 21 additions & 1 deletion lib/templates/mixins/seo/getMeta.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logger from '~typo3/lib/logger'

export default {
methods: {
getMeta () {
Expand All @@ -14,7 +16,8 @@ export default {
twitterDescription,
twitterCard,
twitterImage,
robots
robots,
schema
} = this.page.meta

const data = {
Expand Down Expand Up @@ -127,6 +130,23 @@ export default {
})
}

/**
* Inject ld+json schema
*/
if (schema) {
try {
data.script = [
{
hid: 'schema',
type: 'application/ld+json',
json: JSON.parse(schema)
}
]
} catch (e) {
logger.warn(`Error on parsing ld+json schema: ${e}`)
}
}

/**
* Filter empty meta tags
*/
Expand Down
3 changes: 2 additions & 1 deletion lib/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export namespace TYPO3 {
twitterDescription: string,
twitterCard: string,
twitterImage: object | null
schema: string
}

interface Breadcrumbs {
Expand All @@ -149,7 +150,7 @@ export namespace TYPO3 {
type: string
slug: string
/** page metadata */
meta: object,
meta: Metadata,
/** breadcrumbs data */
breadcrumbs: TYPO3.Breadcrumbs
/** page appearance */
Expand Down

0 comments on commit 50c93fe

Please sign in to comment.