add util for adding "http" to URL; add isVideo posts helper

This commit is contained in:
Sacha Greif 2015-07-27 15:15:38 +09:00
parent 1f14bcc08b
commit 3b4ee38f99
4 changed files with 21 additions and 12 deletions

View file

@ -21,11 +21,7 @@ serveAPI = function(limitSegment){
properties.domain = Telescope.utils.getDomain(url);
if (post.thumbnailUrl) {
// add http: if missing
if (post.thumbnailUrl.substring(0, 5) !== "http:" && post.thumbnailUrl.substring(0, 6) !== "https:") {
post.thumbnailUrl = "http:"+post.thumbnailUrl;
}
properties.thumbnailUrl = post.thumbnailUrl;
properties.thumbnailUrl = Telescope.utils.addHttp(post.thumbnailUrl);
}
var twitterName = Users.getTwitterNameById(post.userId);

View file

@ -169,6 +169,14 @@ Telescope.utils.invitesEnabled = function() {
return Settings.get("requireViewInvite") || Settings.get("requirePostInvite");
};
// add http: if missing
Telescope.utils.addHttp = function (url) {
if (url.substring(0, 5) !== "http:" && url.substring(0, 6) !== "https:") {
url = "http:"+url;
}
return url;
};
/////////////////////////////
// String Helper Functions //
/////////////////////////////
@ -228,5 +236,4 @@ Telescope.getNestedProperty = function (obj, desc) {
var arr = desc.split(".");
while(arr.length && (obj = obj[arr.shift()]));
return obj;
}
};

View file

@ -92,3 +92,12 @@ Posts.checkForSameUrl = function (url, currentUser) {
Posts.current = function () {
return Posts.findOne(Router.current().data().post._id);
};
/**
* Check to see if a post is a link to a video
* @param {Object} post
*/
Posts.isVideo = function (post) {
return post.media && post.media.type === "video";
};
Posts.helpers({isVideo: function () {return Posts.isVideo(this);}});

View file

@ -30,11 +30,8 @@ servePostRSS = function(view, url) {
};
if (post.thumbnailUrl) {
// add http: if missing
if (post.thumbnailUrl.substring(0, 5) !== "http:" && post.thumbnailUrl.substring(0, 6) !== "https:") {
post.thumbnailUrl = "http:"+post.thumbnailUrl;
}
feedItem.custom_elements = [{"imageUrl": post.thumbnailUrl}, {"content": post.thumbnailUrl}];
var url = Telescope.utils.addHttp(post.thumbnailUrl);
feedItem.custom_elements = [{"imageUrl":url}, {"content": url}];
}
feed.item(feedItem);