From 9a8fbd5286b644fe2d3786a8078dbcfa2e5e3db3 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Sun, 20 Mar 2016 22:33:46 +0000 Subject: [PATCH] Never output null JSON-LD schema refs #5091, #6612 - fixes meta data so it won't output 'null' as a JSON-LD schema - added test coverage for this if/else - this case cannot happen within the existing system, it only happens with custom channels after #6612 --- core/server/helpers/ghost_head.js | 8 +++++--- .../unit/server_helpers/ghost_head_spec.js | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/core/server/helpers/ghost_head.js b/core/server/helpers/ghost_head.js index bd098be0cb..dd25452424 100644 --- a/core/server/helpers/ghost_head.js +++ b/core/server/helpers/ghost_head.js @@ -103,9 +103,11 @@ function ghost_head(options) { head.push.apply(head, finaliseStructuredData(metaData)); head.push(''); - head.push('\n'); + if (metaData.schema) { + head.push('\n'); + } } if (client && client.id && client.secret) { diff --git a/core/test/unit/server_helpers/ghost_head_spec.js b/core/test/unit/server_helpers/ghost_head_spec.js index e2efccba2f..1dc3a610c0 100644 --- a/core/test/unit/server_helpers/ghost_head_spec.js +++ b/core/test/unit/server_helpers/ghost_head_spec.js @@ -595,6 +595,26 @@ describe('{{ghost_head}} helper', function () { }).catch(done); }); + it('outputs structured data but not schema for custom channel', function (done) { + helpers.ghost_head.call( + {safeVersion: '0.3', relativeUrl: '/featured/', context: ['featured']}, + {data: {root: {context: ['featured']}}} + ).then(function (rendered) { + should.exist(rendered); + rendered.string.should.match(//); + rendered.string.should.match(//); + rendered.string.should.match(//); + rendered.string.should.match(//); + rendered.string.should.match(//); + rendered.string.should.match(//); + rendered.string.should.match(//); + + rendered.string.should.not.match(/