0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-08 02:52:39 -05:00

Update dependency @tryghost/url-utils to 0.4.0 (#11156)

no issue

- updates usage of `htmlRelativeToAbsolute` to avoid unnecessary duplication of "home" url fetching (the UrlUtils instance already has that information)
This commit is contained in:
Kevin Ansfield 2019-09-25 12:35:59 +01:00 committed by GitHub
parent d54be917d1
commit d69440bd4f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 29 additions and 35 deletions

View file

@ -124,7 +124,7 @@ function getAmperizeHTML(html, post) {
amperize = amperize || new Amperize();
// make relative URLs abolute
html = urlUtils.htmlRelativeToAbsolute(html, urlUtils.urlFor('home', true), post.url);
html = urlUtils.htmlRelativeToAbsolute(html, post.url);
if (!amperizeCache[post.id] || moment(new Date(amperizeCache[post.id].updated_at)).diff(new Date(post.updated_at)) < 0) {
return new Promise((resolve) => {

View file

@ -21,24 +21,23 @@ generateTags = function generateTags(data) {
return [];
};
generateItem = function generateItem(post, siteUrl, secure) {
var itemUrl = urlService.getUrlByResourceId(post.id, {secure: secure, absolute: true}),
htmlContent = cheerio.load(urlUtils.htmlRelativeToAbsolute(post.html, siteUrl, itemUrl), {decodeEntities: false}),
item = {
title: post.title,
// @TODO: DRY this up with data/meta/index & other excerpt code
description: post.custom_excerpt || post.meta_description || downsize(htmlContent.html(), {words: 50}),
guid: post.id,
url: itemUrl,
date: post.published_at,
categories: generateTags(post),
author: post.primary_author ? post.primary_author.name : null,
custom_elements: []
},
imageUrl;
generateItem = function generateItem(post, secure) {
const itemUrl = urlService.getUrlByResourceId(post.id, {secure, absolute: true});
const htmlContent = cheerio.load(urlUtils.htmlRelativeToAbsolute(post.html, itemUrl, {secure}), {decodeEntities: false});
const item = {
title: post.title,
// @TODO: DRY this up with data/meta/index & other excerpt code
description: post.custom_excerpt || post.meta_description || downsize(htmlContent.html(), {words: 50}),
guid: post.id,
url: itemUrl,
date: post.published_at,
categories: generateTags(post),
author: post.primary_author ? post.primary_author.name : null,
custom_elements: []
};
if (post.feature_image) {
imageUrl = urlUtils.urlFor('image', {image: post.feature_image, secure: secure}, true);
const imageUrl = urlUtils.urlFor('image', {image: post.feature_image, secure}, true);
// Add a media content tag
item.custom_elements.push({
@ -73,13 +72,14 @@ generateItem = function generateItem(post, siteUrl, secure) {
* @param {{title, description, safeVersion, secure, posts}} data
*/
generateFeed = function generateFeed(baseUrl, data) {
const siteUrl = urlUtils.urlFor('home', {secure: data.secure}, true);
const {secure} = data;
const feed = new RSS({
title: data.title,
description: data.description,
generator: 'Ghost ' + data.safeVersion,
feed_url: urlUtils.urlFor({relativeUrl: baseUrl, secure: data.secure}, true),
site_url: siteUrl,
feed_url: urlUtils.urlFor({relativeUrl: baseUrl, secure}, true),
site_url: urlUtils.urlFor('home', {secure}, true),
image_url: urlUtils.urlFor({relativeUrl: 'favicon.png'}, true),
ttl: '60',
custom_namespaces: {
@ -90,7 +90,7 @@ generateFeed = function generateFeed(baseUrl, data) {
return data.posts.reduce((feedPromise, post) => {
return feedPromise.then(() => {
const item = generateItem(post, siteUrl, data.secure);
const item = generateItem(post, secure);
return feed.item(item);
});
}, Promise.resolve()).then(() => {

View file

@ -57,7 +57,6 @@ const forPost = (id, attrs, frame) => {
attrs.html = urlUtils.htmlRelativeToAbsolute(
attrs.html,
urlUtils.urlFor('home', true),
attrs.url,
urlOptions
);

View file

@ -22,7 +22,7 @@ const urlsForPost = (id, attrs, options) => {
}
if (attrs.html) {
attrs.html = urlUtils.htmlRelativeToAbsolute(attrs.html, urlUtils.urlFor('home', true), attrs.url);
attrs.html = urlUtils.htmlRelativeToAbsolute(attrs.html, attrs.url);
}
if (attrs.url) {

View file

@ -57,7 +57,6 @@ const forPost = (id, attrs, frame) => {
attrs.html = urlUtils.htmlRelativeToAbsolute(
attrs.html,
urlUtils.urlFor('home', true),
attrs.url,
urlOptions
);

View file

@ -35,14 +35,12 @@ describe('Unit: canary/utils/serializers/output/utils/url', function () {
post.hasOwnProperty('url').should.be.true();
urlUtils.urlFor.callCount.should.eql(2);
urlUtils.urlFor.callCount.should.eql(1);
urlUtils.urlFor.getCall(0).args.should.eql(['image', {image: 'value'}, true]);
urlUtils.urlFor.getCall(1).args.should.eql(['home', true]);
urlUtils.htmlRelativeToAbsolute.callCount.should.eql(1);
urlUtils.htmlRelativeToAbsolute.getCall(0).args.should.eql([
'## markdown',
'urlFor',
'getUrlByResourceId',
{assetsOnly: true}
]);

View file

@ -35,14 +35,12 @@ describe('Unit: v2/utils/serializers/output/utils/url', function () {
post.hasOwnProperty('url').should.be.true();
urlUtils.urlFor.callCount.should.eql(2);
urlUtils.urlFor.callCount.should.eql(1);
urlUtils.urlFor.getCall(0).args.should.eql(['image', {image: 'value'}, true]);
urlUtils.urlFor.getCall(1).args.should.eql(['home', true]);
urlUtils.htmlRelativeToAbsolute.callCount.should.eql(1);
urlUtils.htmlRelativeToAbsolute.getCall(0).args.should.eql([
'## markdown',
'urlFor',
'getUrlByResourceId',
{assetsOnly: true}
]);

View file

@ -45,7 +45,7 @@
"@tryghost/members-ssr": "0.5.0",
"@tryghost/social-urls": "0.1.2",
"@tryghost/string": "^0.1.3",
"@tryghost/url-utils": "0.3.1",
"@tryghost/url-utils": "0.4.0",
"ajv": "6.10.2",
"amperize": "0.6.0",
"analytics-node": "3.3.0",

View file

@ -259,10 +259,10 @@
dependencies:
unidecode "^0.1.8"
"@tryghost/url-utils@0.3.1":
version "0.3.1"
resolved "https://registry.yarnpkg.com/@tryghost/url-utils/-/url-utils-0.3.1.tgz#5338e71edfb2f8a5ff3f393fb4847ea8e808dd9f"
integrity sha512-B1q2Eayl+qSMosq2qBoqOJP7uUdXfqiSl9n1GDfTxkgdX1rGuGfw5gM9KtV9MuqA/7nrwKQwzV01TG+PYi/OaA==
"@tryghost/url-utils@0.4.0":
version "0.4.0"
resolved "https://registry.yarnpkg.com/@tryghost/url-utils/-/url-utils-0.4.0.tgz#aaa23b588e84712fb36321a3cc99e193cf0bd13d"
integrity sha512-7ElNmBlQTYeoLReEKz2CPjb3+yk7QddNNgBpDQvu3QcAOZ+lAMi4bxGR9ol5+jZb019vtRQlMIfnBJxAdD8rng==
dependencies:
cheerio "0.22.0"
lodash "4.17.11"