mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
🐛Disallowed indexing of preview pages (#9762)
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/)
This commit is contained in:
parent
ecc89b5c0b
commit
2aaf4d6054
4 changed files with 39 additions and 2 deletions
|
@ -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('<meta name="referrer" content="' + referrerPolicy + '" />');
|
||||
|
||||
// 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('<link rel="amphtml" href="' +
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
User-agent: *
|
||||
Sitemap: {{blog-url}}/sitemap.xml
|
||||
Disallow: /ghost/
|
||||
Disallow: /p/
|
||||
|
|
|
@ -18,7 +18,8 @@ const labs = require('../../labs'),
|
|||
subscribePattern = new RegExp('^\\/subscribe\\/'),
|
||||
// routeKeywords.amp: 'amp'
|
||||
ampPattern = new RegExp('\\/amp\\/$'),
|
||||
homePattern = new RegExp('^\\/$');
|
||||
homePattern = new RegExp('^\\/$'),
|
||||
previewPattern = new RegExp('^\\/p\\/');
|
||||
|
||||
function setResponseContext(req, res, data) {
|
||||
var pageParam = req.params && req.params.page !== undefined ? parseInt(req.params.page, 10) : 1;
|
||||
|
@ -46,6 +47,10 @@ function setResponseContext(req, res, data) {
|
|||
res.locals.context.push('amp');
|
||||
}
|
||||
|
||||
if (previewPattern.test(res.locals.relativeUrl)) {
|
||||
res.locals.context.push('preview');
|
||||
}
|
||||
|
||||
// Each page can only have at most one of these
|
||||
if (res.routerOptions && res.routerOptions.context) {
|
||||
res.locals.context = res.locals.context.concat(res.routerOptions.context);
|
||||
|
|
|
@ -1218,6 +1218,32 @@ describe('{{ghost_head}} helper', function () {
|
|||
}).catch(done);
|
||||
});
|
||||
|
||||
it('disallows indexing for preview pages', function (done) {
|
||||
helpers.ghost_head(testUtils.createHbsResponse({
|
||||
locals: {
|
||||
context: ['preview', 'post']
|
||||
}
|
||||
})).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
rendered.string.should.match(/<meta name="robots" content="noindex,nofollow" \/>/);
|
||||
|
||||
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(/<meta name="robots" content="noindex,nofollow" \/>/);
|
||||
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('outputs structured data but not schema for custom collection', function (done) {
|
||||
helpers.ghost_head(testUtils.createHbsResponse({
|
||||
locals: {
|
||||
|
|
Loading…
Add table
Reference in a new issue