Ghost/core/frontend/meta/canonical_url.js
Fabien 'egg' O'Carroll 2dd302a23e
Updated frontend meta helpers to support tag metadata (#12037)
no-issue

- `canonicalUrl`
  - Updated to use `canonical_url` & fall back to previous functionality
- `ogTitle`
  - Updated to use `og_title` and fall back to previous functionality
- `ogImage`
  - Updated to use `og_image` and fall back to previous functionality
- `ogDescription`
  - Updated to use `og_description` and fall back to previous functionality
- `twitterTitle`
  - Updated to use `twitter_title` and fall back to previous functionality
- `twitterImage`
  - Upated to use `twitter_image` and fall back to previous functionality
- `twitterDescription`
  - Updated to use `twitter_description` and fall back to previous functionality
2020-07-10 13:52:48 +02:00

25 lines
674 B
JavaScript

const _ = require('lodash');
const urlUtils = require('../../shared/url-utils');
const getUrl = require('./url');
function getCanonicalUrl(data) {
if ((_.includes(data.context, 'post') || _.includes(data.context, 'page'))
&& data.post && data.post.canonical_url) {
return data.post.canonical_url;
}
if (_.includes(data.context, 'tag') && data.tag && data.tag.canonical_url) {
return data.tag.canonical_url;
}
let url = urlUtils.urlJoin(urlUtils.urlFor('home', true), getUrl(data, false));
if (url.indexOf('/amp/')) {
url = url.replace(/\/amp\/$/i, '/');
}
return url;
}
module.exports = getCanonicalUrl;