helpers for logo & thumbnail urls

This commit is contained in:
xavizalote 2016-04-07 14:34:13 +02:00
parent b30ba944be
commit 1f9a92ec17
3 changed files with 22 additions and 3 deletions

View file

@ -3,7 +3,7 @@ import React from 'react';
const PostThumbnail = ({post}) => {
return (
<a className="post-thumbnail" href={Posts.getLink(post)} target={Posts.getLinkTarget(post)}>
<img src={post.thumbnailUrl} />
<img src={Posts.getThumbnailUrl(post)} />
</a>
)
}

View file

@ -318,3 +318,12 @@ Telescope.utils.getFieldLabel = (fieldName, collection) => {
const nameWithSpaces = Telescope.utils.camelToSpaces(fieldName.replace("telescope.", ""));
return label || nameWithSpaces;
}
Telescope.utils.getLogoUrl = () => {
const logoUrl = Telescope.settings.get("logoUrl");
if (!!logoUrl) {
const prefix = Telescope.utils.getSiteUrl().slice(0,-1);
// the logo may be hosted on another website
return logoUrl.indexOf('://') > -1 ? logoUrl : prefix + logoUrl;
}
};

View file

@ -143,3 +143,13 @@ Posts.getNotificationProperties = function (post) {
return properties;
};
Posts.getThumbnailUrl = (post) => {
const thumbnailUrl = post.thumbnailUrl;
if (!!thumbnailUrl) {
const prefix = Telescope.utils.getSiteUrl().slice(0,-1);
// the thumbnail may be hosted on another website
return thumbnailUrl.indexOf('://') > -1 ? thumbnailUrl : prefix + thumbnailUrl;
}
};
Posts.helpers({ getThumbnailUrl() { return Posts.getThumbnailUrl(this); } });