Switched AMP to be 'off' by default in all new Ghost instances (#13907)

refs https://github.com/TryGhost/Team/issues/1189

Support for AMP is slowly in decline, and makes developing new cards trickier,
since AMP no longer has an effect of SEO we're going to disable it by default
as a first step toward moving away from it.

Co-authored-by: Thibaut Patel <thibaut@ghost.org>
This commit is contained in:
Fabien 'egg' O'Carroll 2022-01-14 18:55:48 +02:00 committed by GitHub
parent 8df29f6574
commit 10c214c148
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 191 additions and 85 deletions

View File

@ -397,7 +397,7 @@
}, },
"amp": { "amp": {
"amp": { "amp": {
"defaultValue": "true", "defaultValue": "false",
"validations": { "validations": {
"isIn": [["true", "false"]] "isIn": [["true", "false"]]
}, },

View File

@ -35,7 +35,7 @@ describe('Settings API', function () {
localUtils.API.checkResponse(jsonResponse, 'settings'); localUtils.API.checkResponse(jsonResponse, 'settings');
JSON.parse(_.find(jsonResponse.settings, {key: 'unsplash'}).value).should.eql(true); JSON.parse(_.find(jsonResponse.settings, {key: 'unsplash'}).value).should.eql(true);
JSON.parse(_.find(jsonResponse.settings, {key: 'amp'}).value).should.eql(true); JSON.parse(_.find(jsonResponse.settings, {key: 'amp'}).value).should.eql(false);
should.not.exist(_.find(jsonResponse.settings, {key: 'permalinks'})); should.not.exist(_.find(jsonResponse.settings, {key: 'permalinks'}));
should.not.exist(_.find(jsonResponse.settings, {key: 'ghost_head'})); should.not.exist(_.find(jsonResponse.settings, {key: 'ghost_head'}));
should.not.exist(_.find(jsonResponse.settings, {key: 'ghost_foot'})); should.not.exist(_.find(jsonResponse.settings, {key: 'ghost_foot'}));

View File

@ -1,8 +1,10 @@
const should = require('should'); const should = require('should');
const sinon = require('sinon');
const supertest = require('supertest'); const supertest = require('supertest');
const testUtils = require('../utils'); const testUtils = require('../utils');
const configUtils = require('../utils/configUtils'); const configUtils = require('../utils/configUtils');
const urlUtils = require('../utils/urlUtils'); const urlUtils = require('../utils/urlUtils');
const settings = require('../../core/shared/settings-cache');
let request; let request;
@ -31,6 +33,10 @@ describe('Advanced URL Configurations', function () {
urlUtils.restore(); urlUtils.restore();
}); });
afterEach(function () {
sinon.restore();
});
it('http://localhost should 404', async function () { it('http://localhost should 404', async function () {
await request.get('/') await request.get('/')
.expect(404); .expect(404);
@ -67,11 +73,22 @@ describe('Advanced URL Configurations', function () {
.expect(404); .expect(404);
}); });
it('/blog/welcome/amp/ should 200', async function () { it('/blog/welcome/amp/ should 200 if amp is enabled', async function () {
sinon.stub(settings, 'get').callsFake(function (key, ...rest) {
if (key === 'amp') {
return true;
}
return settings.get.wrappedMethod.call(settings, key, ...rest);
});
await request.get('/blog/welcome/amp/') await request.get('/blog/welcome/amp/')
.expect(200); .expect(200);
}); });
it('/blog/welcome/amp/ should 301', async function () {
await request.get('/blog/welcome/amp/')
.expect(301);
});
it('/welcome/amp/ should 404', async function () { it('/welcome/amp/ should 404', async function () {
await request.get('/welcome/amp/') await request.get('/welcome/amp/')
.expect(404); .expect(404);

View File

@ -190,6 +190,15 @@ describe('Default Frontend routing', function () {
}); });
describe('AMP post', function () { describe('AMP post', function () {
describe('AMP Enabled', function () {
beforeEach(function () {
sinon.stub(settingsCache, 'get').callsFake(function (key, options) {
if (key === 'amp' && !options) {
return true;
}
return origCache.get(key, options);
});
});
it('should respond with html for valid url', async function () { it('should respond with html for valid url', async function () {
await request.get('/welcome/amp/') await request.get('/welcome/amp/')
.expect('Content-Type', /html/) .expect('Content-Type', /html/)
@ -226,16 +235,18 @@ describe('Default Frontend routing', function () {
.expect(/Page not found/) .expect(/Page not found/)
.expect(assertCorrectFrontendHeaders); .expect(assertCorrectFrontendHeaders);
}); });
});
describe('AMP Disabled', function () { describe('AMP Disabled', function () {
it('/amp/ should redirect to regular post, including any query params', async function () { beforeEach(function () {
sinon.stub(settingsCache, 'get').callsFake(function (key, options) { sinon.stub(settingsCache, 'get').callsFake(function (key, options) {
if (key === 'amp' && !options) { if (key === 'amp' && !options) {
return false; return false;
} }
return origCache.get(key, options); return origCache.get(key, options);
}); });
});
it('/amp/ should redirect to regular post, including any query params', async function () {
await request.get('/welcome/amp/?q=a') await request.get('/welcome/amp/?q=a')
.expect('Location', '/welcome/?q=a') .expect('Location', '/welcome/?q=a')
.expect(301) .expect(301)

View File

@ -66,7 +66,9 @@ describe('Integration - Web - Site canary', function () {
}); });
}); });
describe('AMP enabled', function () {
it('serve amp', function () { it('serve amp', function () {
localUtils.defaultMocks(sinon, {amp: true});
const req = { const req = {
secure: true, secure: true,
method: 'GET', method: 'GET',
@ -81,6 +83,24 @@ describe('Integration - Web - Site canary', function () {
response.body.should.match(/<h1>HTML Ipsum Presents<\/h1>/); response.body.should.match(/<h1>HTML Ipsum Presents<\/h1>/);
}); });
}); });
});
describe('AMP disabled', function () {
it('serve amp', function () {
localUtils.defaultMocks(sinon, {amp: false});
const req = {
secure: true,
method: 'GET',
url: '/html-ipsum/amp/',
host: 'example.com'
};
return localUtils.mockExpress.invoke(app, req)
.then(function (response) {
response.statusCode.should.eql(301);
});
});
});
it('post not found', function () { it('post not found', function () {
const req = { const req = {

View File

@ -66,7 +66,9 @@ describe('Integration - Web - Site v2', function () {
}); });
}); });
describe('AMP enabled', function () {
it('serve amp', function () { it('serve amp', function () {
localUtils.defaultMocks(sinon, {amp: true});
const req = { const req = {
secure: true, secure: true,
method: 'GET', method: 'GET',
@ -81,6 +83,24 @@ describe('Integration - Web - Site v2', function () {
response.body.should.match(/<h1>HTML Ipsum Presents<\/h1>/); response.body.should.match(/<h1>HTML Ipsum Presents<\/h1>/);
}); });
}); });
});
describe('AMP disabled', function () {
it('serve amp', function () {
localUtils.defaultMocks(sinon, {amp: false});
const req = {
secure: true,
method: 'GET',
url: '/html-ipsum/amp/',
host: 'example.com'
};
return localUtils.mockExpress.invoke(app, req)
.then(function (response) {
response.statusCode.should.eql(301);
});
});
});
it('post not found', function () { it('post not found', function () {
const req = { const req = {

View File

@ -66,7 +66,9 @@ describe('Integration - Web - Site v3', function () {
}); });
}); });
describe('AMP enabled', function () {
it('serve amp', function () { it('serve amp', function () {
localUtils.defaultMocks(sinon, {amp: true});
const req = { const req = {
secure: true, secure: true,
method: 'GET', method: 'GET',
@ -81,6 +83,24 @@ describe('Integration - Web - Site v3', function () {
response.body.should.match(/<h1>HTML Ipsum Presents<\/h1>/); response.body.should.match(/<h1>HTML Ipsum Presents<\/h1>/);
}); });
}); });
});
describe('AMP disabled', function () {
it('serve amp', function () {
localUtils.defaultMocks(sinon, {amp: false});
const req = {
secure: true,
method: 'GET',
url: '/html-ipsum/amp/',
host: 'example.com'
};
return localUtils.mockExpress.invoke(app, req)
.then(function (response) {
response.statusCode.should.eql(301);
});
});
});
it('post not found', function () { it('post not found', function () {
const req = { const req = {

View File

@ -11,6 +11,7 @@ const _ = require('lodash');
const testUtils = require('../../utils'); const testUtils = require('../../utils');
const configUtils = require('../../utils/configUtils'); const configUtils = require('../../utils/configUtils');
const config = require('../../../core/shared/config'); const config = require('../../../core/shared/config');
const settingsCache = require('../../../core/shared/settings-cache');
let request; let request;
describe('Frontend Routing', function () { describe('Frontend Routing', function () {
@ -218,6 +219,10 @@ describe('Frontend Routing', function () {
}); });
describe('amp', function () { describe('amp', function () {
describe('amp enabled', function (){
beforeEach(function () {
sinon.stub(settingsCache, 'get').withArgs('amp').returns(true);
});
it('should 404 for amp parameter', function (done) { it('should 404 for amp parameter', function (done) {
// NOTE: only post pages are supported so the router doesn't have a way to distinguish if // NOTE: only post pages are supported so the router doesn't have a way to distinguish if
// the request was done after AMP 'Page' or 'Post' // the request was done after AMP 'Page' or 'Post'
@ -228,6 +233,19 @@ describe('Frontend Routing', function () {
.end(doEnd(done)); .end(doEnd(done));
}); });
}); });
describe('amp disabled', function (){
beforeEach(function () {
sinon.stub(settingsCache, 'get').withArgs('amp').returns(false);
});
it('should 301 for amp parameter', function (done) {
// NOTE: only post pages are supported so the router doesn't have a way to distinguish if
// the request was done after AMP 'Page' or 'Post'
request.get('/static-page-test/amp/')
.expect(301)
.end(doEnd(done));
});
});
});
}); });
describe('Post with Ghost in the url', function () { describe('Post with Ghost in the url', function () {

View File

@ -37,7 +37,7 @@ describe('DB version integrity', function () {
// Only these variables should need updating // Only these variables should need updating
const currentSchemaHash = 'e649797a5de92d417744f6f2623c79cf'; const currentSchemaHash = 'e649797a5de92d417744f6f2623c79cf';
const currentFixturesHash = '07d4b0c4cf159b34344a6b5e88c74e9f'; const currentFixturesHash = '07d4b0c4cf159b34344a6b5e88c74e9f';
const currentSettingsHash = 'b06316ebbf62381158e1c46c97c0b77a'; const currentSettingsHash = 'd73b63e33153c9256bca42ebfd376779';
const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01'; const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';
// If this test is failing, then it is likely a change has been made that requires a DB version bump, // If this test is failing, then it is likely a change has been made that requires a DB version bump,