Ghost/core/server/helpers
Aileen Nowak a5c29dfc34 [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 18:49:27 +02:00
..
tpl Subscribers: router & form helpers 2016-05-11 10:28:11 +02:00
asset.js Rename confusing 'context' variables 2016-02-21 22:07:15 +00:00
author.js Rename confusing 'context' variables 2016-02-21 22:07:15 +00:00
body_class.js deps: lodash@4.13.1 2016-06-11 13:13:55 -06:00
content.js Refactor helpers & tests into individual files 2014-10-14 22:52:40 +02:00
date.js timezones: Always use the timezone of blog setting 2016-05-20 13:59:45 +02:00
encode.js Rename confusing 'context' variables 2016-02-21 22:07:15 +00:00
excerpt.js Rename confusing 'context' variables 2016-02-21 22:07:15 +00:00
facebook_url.js Add helpers for facebook & twitter urls 2016-05-17 16:39:58 +01:00
foreach.js Update tags & foreach to respect visibility 2016-06-15 12:37:09 +01:00
get.js deps: lodash@4.13.1 2016-06-11 13:13:55 -06:00
ghost_foot.js Remove auto-inclusion of jQuery via ghost_foot 2015-09-02 13:39:22 +01:00
ghost_head.js [FEATURE] AMP (#7229) 2016-08-22 18:49:27 +02:00
has.js deps: lodash@4.13.1 2016-06-11 13:13:55 -06:00
image.js Change url and image into synchronous helpers 2014-12-29 18:44:15 +00:00
index.js Add helpers for facebook & twitter urls 2016-05-17 16:39:58 +01:00
input_email.js Subscribers: router & form helpers 2016-05-11 10:28:11 +02:00
input_password.js rewrites default private.hbs for new zelda styles 2015-05-29 06:25:32 -06:00
is.js deps: lodash@4.13.1 2016-06-11 13:13:55 -06:00
meta_description.js Started moving meta data fetching to functions. 2016-01-23 13:58:21 -08:00
meta_title.js Started moving meta data fetching to functions. 2016-01-23 13:58:21 -08:00
navigation.js Guard for currentUrl being undefined in navigation 2016-06-07 20:10:20 +01:00
page_url.js Fixing undefined page case for page_url helper 2016-04-14 11:22:23 +01:00
pagination.js Clean up paginated URL generation 2016-03-20 22:35:00 +00:00
plural.js Rename confusing 'context' variables 2016-02-21 22:07:15 +00:00
post_class.js Remove filters from theme helpers (no async) 2015-12-08 14:35:04 +00:00
prev_next.js Rename confusing 'context' variables 2016-02-21 22:07:15 +00:00
tags.js Update tags & foreach to respect visibility 2016-06-15 12:37:09 +01:00
template.js Harvest server side strings 2015-12-19 12:12:16 +01:00
title.js Refactor helpers & tests into individual files 2014-10-14 22:52:40 +02:00
twitter_url.js Add helpers for facebook & twitter urls 2016-05-17 16:39:58 +01:00
url.js Started moving meta data fetching to functions. 2016-01-23 13:58:21 -08:00
utils.js Update tags & foreach to respect visibility 2016-06-15 12:37:09 +01:00