From 2aaf4d60548f42b6921d5b12d404e3596c6493b6 Mon Sep 17 00:00:00 2001 From: Vikas Potluri Date: Mon, 17 Sep 2018 04:29:47 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9BDisallowed=20indexing=20of=20previe?= =?UTF-8?q?w=20pages=20(#9762)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #9749 - disallow indexing of /p/ in robots.txt - add meta robots tag to preview pages - robots.txt wont' be applied for blogs not mounted to the root (i.e. https://example.com/blog/) --- core/server/helpers/ghost_head.js | 7 ++++- core/server/public/robots.txt | 1 + .../services/routing/helpers/context.js | 7 ++++- .../integration/helpers/ghost_head_spec.js | 26 +++++++++++++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/core/server/helpers/ghost_head.js b/core/server/helpers/ghost_head.js index 847860057f..90a68a3dec 100644 --- a/core/server/helpers/ghost_head.js +++ b/core/server/helpers/ghost_head.js @@ -87,7 +87,7 @@ function getAjaxHelper(clientId, clientSecret) { * } * * `blog`, `labs` and `config` are the templateOptions, search for `hbs.updateTemplateOptions` in the code base. - * Also see how the root object get's created, https://github.com/wycats/handlebars.js/blob/v4.0.6/lib/handlebars/runtime.js#L259 + * Also see how the root object gets created, https://github.com/wycats/handlebars.js/blob/v4.0.6/lib/handlebars/runtime.js#L259 */ // We use the name ghost_head to match the helper for consistency: module.exports = function ghost_head(options) { // eslint-disable-line camelcase @@ -136,6 +136,11 @@ module.exports = function ghost_head(options) { // eslint-disable-line camelcase escapeExpression(metaData.canonicalUrl) + '" />'); head.push(''); + // don't allow indexing of preview URLs! + if (_.includes(context, 'preview')) { + head.push(writeMetaTag('robots', 'noindex,nofollow', 'name')); + } + // show amp link in post when 1. we are not on the amp page and 2. amp is enabled if (_.includes(context, 'post') && !_.includes(context, 'amp') && settingsCache.get('amp')) { head.push('/); + + done(); + }).catch(done); + }); + + it('implicit indexing settings for non-preview pages', function (done) { + helpers.ghost_head(testUtils.createHbsResponse({ + locals: { + context: ['featured', 'paged', 'index', 'post', 'amp', 'home', 'unicorn'] + } + })).then(function (rendered) { + should.exist(rendered); + rendered.string.should.not.match(//); + + done(); + }).catch(done); + }); + it('outputs structured data but not schema for custom collection', function (done) { helpers.ghost_head(testUtils.createHbsResponse({ locals: {