2020-04-29 18:44:27 +03:00
|
|
|
const should = require('should');
|
|
|
|
const sinon = require('sinon');
|
2021-10-06 12:52:46 +03:00
|
|
|
const getTitle = require('../../../../core/frontend/meta/title');
|
|
|
|
const settingsCache = require('../../../../core/shared/settings-cache');
|
2017-02-03 16:15:11 +03:00
|
|
|
|
2016-01-17 13:07:52 +03:00
|
|
|
describe('getTitle', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
let localSettingsCache = {};
|
2017-02-03 16:15:11 +03:00
|
|
|
|
|
|
|
beforeEach(function () {
|
2019-01-21 19:53:44 +03:00
|
|
|
sinon.stub(settingsCache, 'get').callsFake(function (key) {
|
2017-02-03 16:15:11 +03:00
|
|
|
return localSettingsCache[key];
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-09-13 19:35:20 +03:00
|
|
|
afterEach(function () {
|
2019-01-21 19:53:44 +03:00
|
|
|
sinon.restore();
|
2017-02-03 16:15:11 +03:00
|
|
|
localSettingsCache = {};
|
2016-09-13 19:35:20 +03:00
|
|
|
});
|
|
|
|
|
2016-01-17 13:07:52 +03:00
|
|
|
it('should return meta_title if on data root', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const title = getTitle({
|
2016-01-17 13:07:52 +03:00
|
|
|
meta_title: 'My test title'
|
|
|
|
});
|
2016-09-13 19:35:20 +03:00
|
|
|
|
2016-01-17 13:07:52 +03:00
|
|
|
title.should.equal('My test title');
|
|
|
|
});
|
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
describe('property: null', function () {
|
|
|
|
it('has correct fallbacks for context: home', function () {
|
|
|
|
localSettingsCache.title = 'My site title';
|
|
|
|
localSettingsCache.meta_title = 'My site meta title';
|
2016-09-13 19:35:20 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
getTitle({}, {context: 'home'})
|
|
|
|
.should.equal('My site meta title');
|
2016-01-17 13:07:52 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
localSettingsCache.meta_title = '';
|
2019-07-25 12:08:29 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
getTitle({}, {context: 'home'})
|
|
|
|
.should.equal('My site title');
|
|
|
|
});
|
2019-07-25 12:08:29 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
it('has correct fallbacks for context: post', function () {
|
|
|
|
localSettingsCache.title = 'My site title';
|
|
|
|
const post = {
|
|
|
|
title: 'Post title',
|
|
|
|
meta_title: 'Post meta title'
|
|
|
|
};
|
2019-07-25 12:08:29 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
getTitle({post}, {context: 'post'})
|
|
|
|
.should.equal('Post meta title');
|
|
|
|
|
|
|
|
post.meta_title = '';
|
|
|
|
|
|
|
|
getTitle({post}, {context: 'post'})
|
|
|
|
.should.equal('Post title');
|
|
|
|
|
|
|
|
post.title = '';
|
|
|
|
|
|
|
|
getTitle({post}, {context: 'post'})
|
|
|
|
.should.equal('');
|
2019-07-25 12:08:29 +03:00
|
|
|
});
|
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
it('has correct fallbacks for context: page', function () {
|
|
|
|
localSettingsCache.title = 'My site title';
|
|
|
|
const page = {
|
|
|
|
title: 'Page title',
|
|
|
|
meta_title: 'Page meta title'
|
|
|
|
};
|
2019-07-25 12:08:29 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
getTitle({page}, {context: 'page'})
|
|
|
|
.should.equal('Page meta title');
|
2019-07-25 12:08:29 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
page.meta_title = '';
|
|
|
|
|
|
|
|
getTitle({page}, {context: 'page'})
|
|
|
|
.should.equal('Page title');
|
|
|
|
|
|
|
|
page.title = '';
|
|
|
|
|
|
|
|
getTitle({page}, {context: 'page'})
|
|
|
|
.should.equal('');
|
2019-07-25 12:08:29 +03:00
|
|
|
});
|
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
// NOTE: this is a legacy format and should be resolved with https://github.com/TryGhost/Ghost/issues/10042
|
|
|
|
it('has correct fallbacks for context: page (legacy format)', function () {
|
|
|
|
localSettingsCache.title = 'My site title';
|
|
|
|
const post = {
|
|
|
|
title: 'Page title',
|
|
|
|
meta_title: 'Page meta title'
|
|
|
|
};
|
2019-07-25 12:08:29 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
getTitle({post}, {context: 'page'})
|
|
|
|
.should.equal('Page meta title');
|
2017-02-03 16:15:11 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
post.meta_title = '';
|
2017-02-03 16:15:11 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
getTitle({post}, {context: 'page'})
|
|
|
|
.should.equal('Page title');
|
2016-01-17 13:07:52 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
post.title = '';
|
2016-09-13 19:35:20 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
getTitle({post}, {context: 'page'})
|
|
|
|
.should.equal('');
|
2016-01-17 13:07:52 +03:00
|
|
|
});
|
2016-09-13 19:35:20 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
it('has correct fallbacks for context: author', function () {
|
|
|
|
localSettingsCache.title = 'Site title';
|
|
|
|
localSettingsCache.meta_title = 'Site meta title';
|
|
|
|
const author = {
|
|
|
|
name: 'Author name'
|
|
|
|
};
|
2016-01-17 13:07:52 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
getTitle({author}, {context: 'author'})
|
|
|
|
.should.equal('Author name - Site title');
|
|
|
|
});
|
2016-09-13 19:35:20 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
it('has correct fallbacks for context: author_paged', function () {
|
|
|
|
localSettingsCache.title = 'Site title';
|
|
|
|
localSettingsCache.meta_title = 'Site meta title';
|
|
|
|
const author = {
|
|
|
|
name: 'Author name'
|
|
|
|
};
|
2016-09-13 19:35:20 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
getTitle({author}, {context: ['author', 'paged'], pagination: {total: 40, page: 3}})
|
|
|
|
.should.equal('Author name - Site title (Page 3)');
|
|
|
|
});
|
2016-01-17 13:07:52 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
it('has correct fallbacks for context: tag', function () {
|
|
|
|
localSettingsCache.title = 'Site title';
|
|
|
|
localSettingsCache.meta_title = 'Site meta title';
|
|
|
|
const tag = {
|
|
|
|
name: 'Tag name',
|
|
|
|
meta_title: 'Tag meta title'
|
|
|
|
};
|
2016-09-13 19:35:20 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
getTitle({tag}, {context: 'tag'})
|
|
|
|
.should.equal('Tag meta title');
|
|
|
|
|
|
|
|
tag.meta_title = '';
|
|
|
|
|
|
|
|
getTitle({tag}, {context: 'tag'})
|
|
|
|
.should.equal('Tag name - Site title');
|
2016-01-17 13:07:52 +03:00
|
|
|
});
|
2016-09-13 19:35:20 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
it('has correct fallbacks for context: tag_paged', function () {
|
|
|
|
localSettingsCache.title = 'Site title';
|
|
|
|
localSettingsCache.meta_title = 'Site meta title';
|
|
|
|
const tag = {
|
|
|
|
name: 'Tag name',
|
|
|
|
meta_title: 'Tag meta title'
|
|
|
|
};
|
2016-01-17 13:07:52 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
getTitle({tag}, {context: ['tag', 'paged'], pagination: {total: 40, page: 3}})
|
|
|
|
.should.equal('Tag meta title');
|
|
|
|
|
|
|
|
tag.meta_title = '';
|
2019-11-11 13:36:00 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
getTitle({tag}, {context: ['tag', 'paged'], pagination: {total: 40, page: 3}})
|
|
|
|
.should.equal('Tag name - Site title (Page 3)');
|
|
|
|
});
|
2019-11-11 13:36:00 +03:00
|
|
|
});
|
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
describe('property: og', function () {
|
|
|
|
it('has correct fallbacks for context: home', function () {
|
|
|
|
localSettingsCache.title = 'My site title';
|
|
|
|
localSettingsCache.meta_title = 'My site meta title';
|
|
|
|
localSettingsCache.og_title = 'My site og title';
|
2018-03-19 11:48:07 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
getTitle({}, {context: 'home'}, {property: 'og'})
|
|
|
|
.should.equal('My site og title');
|
|
|
|
|
|
|
|
localSettingsCache.og_title = '';
|
|
|
|
|
|
|
|
getTitle({}, {context: 'home'}, {property: 'og'})
|
|
|
|
.should.equal('My site title');
|
2018-03-19 11:48:07 +03:00
|
|
|
});
|
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
it('has correct fallbacks for context: post', function () {
|
|
|
|
const post = {
|
|
|
|
title: 'Post title',
|
|
|
|
meta_title: 'Post meta title',
|
|
|
|
og_title: 'Post og title'
|
|
|
|
};
|
2018-03-19 11:48:07 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
getTitle({post}, {context: 'post'}, {property: 'og'})
|
|
|
|
.should.equal('Post og title');
|
2016-09-13 19:35:20 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
post.og_title = '';
|
2016-01-17 13:07:52 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
getTitle({post}, {context: 'post'}, {property: 'og'})
|
|
|
|
.should.equal('Post meta title');
|
2016-09-13 19:35:20 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
post.meta_title = '';
|
✨ [FEATURE] AMP⚡ (#7229)
closes #6588, #7095
* `ImageObject` with image dimensions (#7152, #7151, #7153)
- Returns meta data as promise
- returns a new Promise from meta data
- uses `Promise.props()` to resolve `getClient()` and `getMetaData()`
- Adds 'image-size' util
The util returns an object like this
```
{
height: 50,
url: 'http://myblog.com/images/cat.jpg',
width: 50
};
```
if the dimensions can be fetched and rejects with error, if not.
In case we get a locally stored image or a not complete url (like `//www.gravatar.com/andsoon`), we add the protocol to the incomplete one and use `urlFor()` to get the absolute URL. If the request fails or `image-size` is not able to read the file, we reject with error.
- adds 'image-size' module to dependencies
- adds `getImageSizeFromUrl` function that returns image dimensions
- In preparation of AMP support and to improve our schema.org JSON-LD and structured data, I made the following changes:
- Changes the following properties to be `Objects`, which have a `url` property by default and a `dimensions` property, if `width` and `height` are available:
- `metaData.coverImage`
- `metaData.authorImage`
- `metaData.blog.logo`
- Checks cache by calling `getCachedImageSizeFromUrl`. If image dimensions were fetched already, returns them from cache instead of fetching them again.
- If we have image dimensions on hand, the output in our JSON-LD changes from normal urls to be full `ImageObjects`. Applies to all images and logos.
- Special case for `publisher.logo` as it has size restrictions: if the image doesn't fulfil the restrictions (<=600 width and <=60 height), we simply output the url instead, so like before.
- Adds new property for schema.org JSON-LD: `mainEntityOfPage` as an Object.
- Adds additional Open Graph data (if we have the image size): `og:image:width` and `og:image:height`
- Adds/updates tests
* AMP router and controller (#7171, #7157)
Implements AMP in `/apps/`:
- renders `amp.hbs` if route is `/:slug/amp/`
- updates `setResponseContext` to set context to `['amp', 'post']` for a amp post and `['amp', 'page']` for a page, but will not render amp template for a page
- updates `context_spec`
- registers 'amp' as new internal app
- adds the `amp.hbs` template to `core/server/apps/amp` which will be the default template for AMP posts.
- adds `isAmpURL` to `post-lookup`
* 🎨 Use `context` in meta as array (#7205)
Instead of reading the first value of the context array, we're checking if it includes certain context values.
This is a preparation change for AMP, where the context will be delivered as `['amp', 'post']`.
* ✨ AMP helpers (#7174, #7216, #7215, #7223)
- Adds AMP helpers `{{amp_content}}`, `{{amp_component}}` and `{{amp_ghost_head}}` to support AMP:
- `{{amp_content}}`:
- Adds `Amperize` as dependency
- AMP app uses new helper `{{amp_content}}` to render AMP HTML
- `Amperize` transforms regular HTML into AMP HTML
- Adds test for `{{amp_content}}` helper
- Adds 'Sanitize-HTML` as dependendy
- After the HTML get 'amperized' we still might have some HTML tags, which are prohibited in AMP HTML, so we use `sanitize-html` to remove those. With every update, `Amperize` gets and it is able to transform more HTML tags, they valid AMP HTML tags (e. g. `video` and `amp-video`) and will therefore not be removed.
- `{{amp_ghost_head}}`:
- registers `{{amp_ghost_head}}` helper, but uses `{{ghost_head}}` code
- uses `{{amp_ghost_head}}` in `amp.hbs` instead of `{{ghost_head}}`
- `{{ghost_head}}`:
- Render `amphtml` link in metadata for post, which links to the amp post (`getAmpUrl`)
- Updates all test in metadata to support `amp` context
- Changes context conditionals to work with full array instead of first array value
- Adds conditionals, so no additional javascript gets rendered in `{{ghost_head}}`
- Removes trailing `/amp/` in URLs, so only `amphtml` link on regular post renders it
- Adds a conditional, so no code injection will be included, for an `amp` context.
- `{{amp_components}}`:
- AMP app uses new helper `{{amp_components}}` to render necessary script tags for AMP extended components as `amp-iframe`, `amp-anime` and `amp-form`
- Adds test for `{{amp_components}}`
2016-08-22 19:49:27 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
getTitle({post}, {context: 'post'}, {property: 'og'})
|
|
|
|
.should.equal('Post title');
|
2017-08-03 14:48:39 +03:00
|
|
|
});
|
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
it('has correct fallbacks for context: page', function () {
|
|
|
|
localSettingsCache.title = 'My site title';
|
|
|
|
const page = {
|
|
|
|
title: 'Page title',
|
|
|
|
meta_title: 'Page meta title',
|
|
|
|
og_title: 'Page og title'
|
|
|
|
};
|
2017-08-03 14:48:39 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
getTitle({page}, {context: 'page'}, {property: 'og'})
|
|
|
|
.should.equal('Page og title');
|
|
|
|
|
|
|
|
page.og_title = '';
|
|
|
|
|
|
|
|
getTitle({page}, {context: 'page'}, {property: 'og'})
|
|
|
|
.should.equal('Page meta title');
|
|
|
|
|
|
|
|
page.meta_title = '';
|
|
|
|
|
|
|
|
getTitle({page}, {context: 'page'}, {property: 'og'})
|
|
|
|
.should.equal('Page title');
|
2017-08-03 14:48:39 +03:00
|
|
|
});
|
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
// NOTE: this is a legacy format and should be resolved with https://github.com/TryGhost/Ghost/issues/10042
|
|
|
|
it('has correct fallbacks for context: page (legacy format)', function () {
|
|
|
|
localSettingsCache.title = 'My site title';
|
|
|
|
const post = {
|
|
|
|
title: 'Page title',
|
|
|
|
meta_title: 'Page meta title',
|
|
|
|
og_title: 'Page og title'
|
|
|
|
};
|
2017-08-03 14:48:39 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
getTitle({post}, {context: 'page'}, {property: 'og'})
|
|
|
|
.should.equal('Page og title');
|
|
|
|
|
|
|
|
post.og_title = '';
|
|
|
|
|
|
|
|
getTitle({post}, {context: 'page'}, {property: 'og'})
|
|
|
|
.should.equal('Page meta title');
|
|
|
|
|
|
|
|
post.meta_title = '';
|
|
|
|
|
|
|
|
getTitle({post}, {context: 'page'}, {property: 'og'})
|
|
|
|
.should.equal('Page title');
|
2017-08-03 14:48:39 +03:00
|
|
|
});
|
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
it('has correct fallbacks for context: author', function () {
|
|
|
|
localSettingsCache.title = 'Site title';
|
|
|
|
localSettingsCache.meta_title = 'Site meta title';
|
|
|
|
const author = {
|
|
|
|
name: 'Author name'
|
|
|
|
};
|
2017-08-03 14:48:39 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
getTitle({author}, {context: 'author'}, {property: 'og'})
|
|
|
|
.should.equal('Author name - Site title');
|
|
|
|
});
|
2017-02-03 16:15:11 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
it('has correct fallbacks for context: author_paged', function () {
|
|
|
|
localSettingsCache.title = 'Site title';
|
|
|
|
localSettingsCache.meta_title = 'Site meta title';
|
|
|
|
const author = {
|
|
|
|
name: 'Author name'
|
|
|
|
};
|
2016-01-17 13:07:52 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
getTitle({author}, {context: ['author', 'paged'], pagination: {total: 40, page: 3}}, {property: 'og'})
|
|
|
|
.should.equal('Author name - Site title (Page 3)');
|
|
|
|
});
|
2019-03-12 03:17:27 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
it('has correct fallbacks for context: tag', function () {
|
|
|
|
localSettingsCache.title = 'Site title';
|
|
|
|
localSettingsCache.meta_title = 'Site meta title';
|
|
|
|
const tag = {
|
|
|
|
name: 'Tag name',
|
|
|
|
meta_title: 'Tag meta title'
|
|
|
|
};
|
2019-03-12 03:17:27 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
getTitle({tag}, {context: 'tag'}, {property: 'og'})
|
|
|
|
.should.equal('Tag meta title');
|
2019-08-09 17:25:12 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
tag.meta_title = '';
|
2019-08-09 17:25:12 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
getTitle({tag}, {context: 'tag'}, {property: 'og'})
|
|
|
|
.should.equal('Tag name - Site title');
|
|
|
|
});
|
2019-09-03 10:03:31 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
it('has correct fallbacks for context: tag_paged', function () {
|
|
|
|
localSettingsCache.title = 'Site title';
|
|
|
|
localSettingsCache.meta_title = 'Site meta title';
|
|
|
|
const tag = {
|
|
|
|
name: 'Tag name',
|
|
|
|
meta_title: 'Tag meta title'
|
|
|
|
};
|
2019-09-03 10:03:31 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
getTitle({tag}, {context: ['tag', 'paged'], pagination: {total: 40, page: 3}}, {property: 'og'})
|
|
|
|
.should.equal('Tag meta title');
|
2017-02-03 16:15:11 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
tag.meta_title = '';
|
|
|
|
|
|
|
|
getTitle({tag}, {context: ['tag', 'paged'], pagination: {total: 40, page: 3}}, {property: 'og'})
|
|
|
|
.should.equal('Tag name - Site title (Page 3)');
|
|
|
|
});
|
2016-01-17 13:07:52 +03:00
|
|
|
});
|
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
describe('property: twitter', function () {
|
|
|
|
it('has correct fallbacks for context: home', function () {
|
|
|
|
localSettingsCache.title = 'My site title';
|
|
|
|
localSettingsCache.meta_title = 'My site meta title';
|
|
|
|
localSettingsCache.twitter_title = 'My site twitter title';
|
2017-02-03 16:15:11 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
getTitle({}, {context: 'home'}, {property: 'twitter'})
|
|
|
|
.should.equal('My site twitter title');
|
✨ [FEATURE] AMP⚡ (#7229)
closes #6588, #7095
* `ImageObject` with image dimensions (#7152, #7151, #7153)
- Returns meta data as promise
- returns a new Promise from meta data
- uses `Promise.props()` to resolve `getClient()` and `getMetaData()`
- Adds 'image-size' util
The util returns an object like this
```
{
height: 50,
url: 'http://myblog.com/images/cat.jpg',
width: 50
};
```
if the dimensions can be fetched and rejects with error, if not.
In case we get a locally stored image or a not complete url (like `//www.gravatar.com/andsoon`), we add the protocol to the incomplete one and use `urlFor()` to get the absolute URL. If the request fails or `image-size` is not able to read the file, we reject with error.
- adds 'image-size' module to dependencies
- adds `getImageSizeFromUrl` function that returns image dimensions
- In preparation of AMP support and to improve our schema.org JSON-LD and structured data, I made the following changes:
- Changes the following properties to be `Objects`, which have a `url` property by default and a `dimensions` property, if `width` and `height` are available:
- `metaData.coverImage`
- `metaData.authorImage`
- `metaData.blog.logo`
- Checks cache by calling `getCachedImageSizeFromUrl`. If image dimensions were fetched already, returns them from cache instead of fetching them again.
- If we have image dimensions on hand, the output in our JSON-LD changes from normal urls to be full `ImageObjects`. Applies to all images and logos.
- Special case for `publisher.logo` as it has size restrictions: if the image doesn't fulfil the restrictions (<=600 width and <=60 height), we simply output the url instead, so like before.
- Adds new property for schema.org JSON-LD: `mainEntityOfPage` as an Object.
- Adds additional Open Graph data (if we have the image size): `og:image:width` and `og:image:height`
- Adds/updates tests
* AMP router and controller (#7171, #7157)
Implements AMP in `/apps/`:
- renders `amp.hbs` if route is `/:slug/amp/`
- updates `setResponseContext` to set context to `['amp', 'post']` for a amp post and `['amp', 'page']` for a page, but will not render amp template for a page
- updates `context_spec`
- registers 'amp' as new internal app
- adds the `amp.hbs` template to `core/server/apps/amp` which will be the default template for AMP posts.
- adds `isAmpURL` to `post-lookup`
* 🎨 Use `context` in meta as array (#7205)
Instead of reading the first value of the context array, we're checking if it includes certain context values.
This is a preparation change for AMP, where the context will be delivered as `['amp', 'post']`.
* ✨ AMP helpers (#7174, #7216, #7215, #7223)
- Adds AMP helpers `{{amp_content}}`, `{{amp_component}}` and `{{amp_ghost_head}}` to support AMP:
- `{{amp_content}}`:
- Adds `Amperize` as dependency
- AMP app uses new helper `{{amp_content}}` to render AMP HTML
- `Amperize` transforms regular HTML into AMP HTML
- Adds test for `{{amp_content}}` helper
- Adds 'Sanitize-HTML` as dependendy
- After the HTML get 'amperized' we still might have some HTML tags, which are prohibited in AMP HTML, so we use `sanitize-html` to remove those. With every update, `Amperize` gets and it is able to transform more HTML tags, they valid AMP HTML tags (e. g. `video` and `amp-video`) and will therefore not be removed.
- `{{amp_ghost_head}}`:
- registers `{{amp_ghost_head}}` helper, but uses `{{ghost_head}}` code
- uses `{{amp_ghost_head}}` in `amp.hbs` instead of `{{ghost_head}}`
- `{{ghost_head}}`:
- Render `amphtml` link in metadata for post, which links to the amp post (`getAmpUrl`)
- Updates all test in metadata to support `amp` context
- Changes context conditionals to work with full array instead of first array value
- Adds conditionals, so no additional javascript gets rendered in `{{ghost_head}}`
- Removes trailing `/amp/` in URLs, so only `amphtml` link on regular post renders it
- Adds a conditional, so no code injection will be included, for an `amp` context.
- `{{amp_components}}`:
- AMP app uses new helper `{{amp_components}}` to render necessary script tags for AMP extended components as `amp-iframe`, `amp-anime` and `amp-form`
- Adds test for `{{amp_components}}`
2016-08-22 19:49:27 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
localSettingsCache.twitter_title = '';
|
|
|
|
|
|
|
|
getTitle({}, {context: 'home'}, {property: 'twitter'})
|
|
|
|
.should.equal('My site title');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has correct fallbacks for context: post', function () {
|
|
|
|
const post = {
|
|
|
|
title: 'Post title',
|
|
|
|
meta_title: 'Post meta title',
|
|
|
|
twitter_title: 'Post twitter title'
|
|
|
|
};
|
|
|
|
|
|
|
|
getTitle({post}, {context: 'post'}, {property: 'twitter'})
|
|
|
|
.should.equal('Post twitter title');
|
|
|
|
|
|
|
|
post.twitter_title = '';
|
2017-02-03 16:15:11 +03:00
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
getTitle({post}, {context: 'post'}, {property: 'twitter'})
|
|
|
|
.should.equal('Post meta title');
|
|
|
|
|
|
|
|
post.meta_title = '';
|
|
|
|
|
|
|
|
getTitle({post}, {context: 'post'}, {property: 'twitter'})
|
|
|
|
.should.equal('Post title');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has correct fallbacks for context: page', function () {
|
|
|
|
localSettingsCache.title = 'My site title';
|
|
|
|
const page = {
|
|
|
|
title: 'Page title',
|
|
|
|
meta_title: 'Page meta title',
|
|
|
|
twitter_title: 'Page twitter title'
|
|
|
|
};
|
|
|
|
|
|
|
|
getTitle({page}, {context: 'page'}, {property: 'twitter'})
|
|
|
|
.should.equal('Page twitter title');
|
|
|
|
|
|
|
|
page.twitter_title = '';
|
|
|
|
|
|
|
|
getTitle({page}, {context: 'page'}, {property: 'twitter'})
|
|
|
|
.should.equal('Page meta title');
|
|
|
|
|
|
|
|
page.meta_title = '';
|
|
|
|
|
|
|
|
getTitle({page}, {context: 'page'}, {property: 'twitter'})
|
|
|
|
.should.equal('Page title');
|
|
|
|
});
|
|
|
|
|
|
|
|
// NOTE: this is a legacy format and should be resolved with https://github.com/TryGhost/Ghost/issues/10042
|
|
|
|
it('has correct fallbacks for context: page (legacy format)', function () {
|
|
|
|
localSettingsCache.title = 'My site title';
|
|
|
|
const post = {
|
|
|
|
title: 'Page title',
|
|
|
|
meta_title: 'Page meta title',
|
|
|
|
twitter_title: 'Page twitter title'
|
|
|
|
};
|
|
|
|
|
|
|
|
getTitle({post}, {context: 'page'}, {property: 'twitter'})
|
|
|
|
.should.equal('Page twitter title');
|
|
|
|
|
|
|
|
post.twitter_title = '';
|
|
|
|
|
|
|
|
getTitle({post}, {context: 'page'}, {property: 'twitter'})
|
|
|
|
.should.equal('Page meta title');
|
|
|
|
|
|
|
|
post.meta_title = '';
|
|
|
|
|
|
|
|
getTitle({post}, {context: 'page'}, {property: 'twitter'})
|
|
|
|
.should.equal('Page title');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has correct fallbacks for context: author', function () {
|
|
|
|
localSettingsCache.title = 'Site title';
|
|
|
|
localSettingsCache.meta_title = 'Site meta title';
|
|
|
|
const author = {
|
|
|
|
name: 'Author name'
|
|
|
|
};
|
|
|
|
|
|
|
|
getTitle({author}, {context: 'author'}, {property: 'twitter'})
|
|
|
|
.should.equal('Author name - Site title');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has correct fallbacks for context: author_paged', function () {
|
|
|
|
localSettingsCache.title = 'Site title';
|
|
|
|
localSettingsCache.meta_title = 'Site meta title';
|
|
|
|
const author = {
|
|
|
|
name: 'Author name'
|
|
|
|
};
|
|
|
|
|
|
|
|
getTitle({author}, {context: ['author', 'paged'], pagination: {total: 40, page: 3}}, {property: 'twitter'})
|
|
|
|
.should.equal('Author name - Site title (Page 3)');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has correct fallbacks for context: tag', function () {
|
|
|
|
localSettingsCache.title = 'Site title';
|
|
|
|
localSettingsCache.meta_title = 'Site meta title';
|
|
|
|
const tag = {
|
|
|
|
name: 'Tag name',
|
|
|
|
meta_title: 'Tag meta title'
|
|
|
|
};
|
|
|
|
|
|
|
|
getTitle({tag}, {context: 'tag'}, {property: 'twitter'})
|
|
|
|
.should.equal('Tag meta title');
|
|
|
|
|
|
|
|
tag.meta_title = '';
|
|
|
|
|
|
|
|
getTitle({tag}, {context: 'tag'}, {property: 'twitter'})
|
|
|
|
.should.equal('Tag name - Site title');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has correct fallbacks for context: tag_paged', function () {
|
|
|
|
localSettingsCache.title = 'Site title';
|
|
|
|
localSettingsCache.meta_title = 'Site meta title';
|
|
|
|
const tag = {
|
|
|
|
name: 'Tag name',
|
|
|
|
meta_title: 'Tag meta title'
|
|
|
|
};
|
|
|
|
|
|
|
|
getTitle({tag}, {context: ['tag', 'paged'], pagination: {total: 40, page: 3}}, {property: 'twitter'})
|
|
|
|
.should.equal('Tag meta title');
|
|
|
|
|
|
|
|
tag.meta_title = '';
|
|
|
|
|
|
|
|
getTitle({tag}, {context: ['tag', 'paged'], pagination: {total: 40, page: 3}}, {property: 'twitter'})
|
|
|
|
.should.equal('Tag name - Site title (Page 3)');
|
|
|
|
});
|
2016-01-17 13:07:52 +03:00
|
|
|
});
|
|
|
|
|
2019-07-25 12:08:29 +03:00
|
|
|
it('should return site title with page if unknown type', function () {
|
|
|
|
localSettingsCache.title = 'My site title 4';
|
2016-09-13 19:35:20 +03:00
|
|
|
|
2016-01-17 13:07:52 +03:00
|
|
|
var title = getTitle({}, {
|
✨ [FEATURE] AMP⚡ (#7229)
closes #6588, #7095
* `ImageObject` with image dimensions (#7152, #7151, #7153)
- Returns meta data as promise
- returns a new Promise from meta data
- uses `Promise.props()` to resolve `getClient()` and `getMetaData()`
- Adds 'image-size' util
The util returns an object like this
```
{
height: 50,
url: 'http://myblog.com/images/cat.jpg',
width: 50
};
```
if the dimensions can be fetched and rejects with error, if not.
In case we get a locally stored image or a not complete url (like `//www.gravatar.com/andsoon`), we add the protocol to the incomplete one and use `urlFor()` to get the absolute URL. If the request fails or `image-size` is not able to read the file, we reject with error.
- adds 'image-size' module to dependencies
- adds `getImageSizeFromUrl` function that returns image dimensions
- In preparation of AMP support and to improve our schema.org JSON-LD and structured data, I made the following changes:
- Changes the following properties to be `Objects`, which have a `url` property by default and a `dimensions` property, if `width` and `height` are available:
- `metaData.coverImage`
- `metaData.authorImage`
- `metaData.blog.logo`
- Checks cache by calling `getCachedImageSizeFromUrl`. If image dimensions were fetched already, returns them from cache instead of fetching them again.
- If we have image dimensions on hand, the output in our JSON-LD changes from normal urls to be full `ImageObjects`. Applies to all images and logos.
- Special case for `publisher.logo` as it has size restrictions: if the image doesn't fulfil the restrictions (<=600 width and <=60 height), we simply output the url instead, so like before.
- Adds new property for schema.org JSON-LD: `mainEntityOfPage` as an Object.
- Adds additional Open Graph data (if we have the image size): `og:image:width` and `og:image:height`
- Adds/updates tests
* AMP router and controller (#7171, #7157)
Implements AMP in `/apps/`:
- renders `amp.hbs` if route is `/:slug/amp/`
- updates `setResponseContext` to set context to `['amp', 'post']` for a amp post and `['amp', 'page']` for a page, but will not render amp template for a page
- updates `context_spec`
- registers 'amp' as new internal app
- adds the `amp.hbs` template to `core/server/apps/amp` which will be the default template for AMP posts.
- adds `isAmpURL` to `post-lookup`
* 🎨 Use `context` in meta as array (#7205)
Instead of reading the first value of the context array, we're checking if it includes certain context values.
This is a preparation change for AMP, where the context will be delivered as `['amp', 'post']`.
* ✨ AMP helpers (#7174, #7216, #7215, #7223)
- Adds AMP helpers `{{amp_content}}`, `{{amp_component}}` and `{{amp_ghost_head}}` to support AMP:
- `{{amp_content}}`:
- Adds `Amperize` as dependency
- AMP app uses new helper `{{amp_content}}` to render AMP HTML
- `Amperize` transforms regular HTML into AMP HTML
- Adds test for `{{amp_content}}` helper
- Adds 'Sanitize-HTML` as dependendy
- After the HTML get 'amperized' we still might have some HTML tags, which are prohibited in AMP HTML, so we use `sanitize-html` to remove those. With every update, `Amperize` gets and it is able to transform more HTML tags, they valid AMP HTML tags (e. g. `video` and `amp-video`) and will therefore not be removed.
- `{{amp_ghost_head}}`:
- registers `{{amp_ghost_head}}` helper, but uses `{{ghost_head}}` code
- uses `{{amp_ghost_head}}` in `amp.hbs` instead of `{{ghost_head}}`
- `{{ghost_head}}`:
- Render `amphtml` link in metadata for post, which links to the amp post (`getAmpUrl`)
- Updates all test in metadata to support `amp` context
- Changes context conditionals to work with full array instead of first array value
- Adds conditionals, so no additional javascript gets rendered in `{{ghost_head}}`
- Removes trailing `/amp/` in URLs, so only `amphtml` link on regular post renders it
- Adds a conditional, so no code injection will be included, for an `amp` context.
- `{{amp_components}}`:
- AMP app uses new helper `{{amp_components}}` to render necessary script tags for AMP extended components as `amp-iframe`, `amp-anime` and `amp-form`
- Adds test for `{{amp_components}}`
2016-08-22 19:49:27 +03:00
|
|
|
context: ['paged'],
|
2016-01-17 13:07:52 +03:00
|
|
|
pagination: {
|
|
|
|
total: 40,
|
|
|
|
page: 35
|
|
|
|
}
|
|
|
|
});
|
2016-09-13 19:35:20 +03:00
|
|
|
|
2019-07-25 12:08:29 +03:00
|
|
|
title.should.equal('My site title 4 (Page 35)');
|
2016-01-17 13:07:52 +03:00
|
|
|
});
|
2021-10-27 13:18:24 +03:00
|
|
|
|
|
|
|
it('should not display "null" for an undefined site title', function () {
|
|
|
|
localSettingsCache.title = null;
|
|
|
|
|
|
|
|
var title = getTitle({
|
|
|
|
tag: {
|
|
|
|
name: 'My tag'
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
context: ['tag']
|
|
|
|
});
|
|
|
|
|
|
|
|
title.should.equal('My tag');
|
|
|
|
|
|
|
|
title = getTitle({
|
|
|
|
tag: {
|
|
|
|
name: 'My tag'
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
context: ['tag', 'paged'],
|
|
|
|
pagination: {
|
|
|
|
total: 40,
|
|
|
|
page: 35
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
title.should.equal('My tag - (Page 35)');
|
|
|
|
|
|
|
|
title = getTitle({
|
|
|
|
author: {
|
|
|
|
name: 'My name'
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
context: ['author']
|
|
|
|
});
|
|
|
|
|
|
|
|
title.should.equal('My name');
|
|
|
|
|
|
|
|
title = getTitle({
|
|
|
|
author: {
|
|
|
|
name: 'My name'
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
context: ['author', 'paged'],
|
|
|
|
pagination: {
|
|
|
|
total: 40,
|
|
|
|
page: 35
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
title.should.equal('My name - (Page 35)');
|
|
|
|
});
|
2016-01-17 13:07:52 +03:00
|
|
|
});
|