2015-09-18 17:11:36 +09:00
|
|
|
var doSEOStuff = function (post) {
|
|
|
|
|
2015-12-14 17:20:45 +09:00
|
|
|
// clear previously added meta tags
|
|
|
|
DocHead.removeDocHeadAddedTags();
|
|
|
|
|
2015-11-18 15:03:17 +09:00
|
|
|
var link = {rel: "canonical", href: post.getPageUrl(true)};
|
2015-09-18 17:18:18 +09:00
|
|
|
DocHead.addLink(link);
|
|
|
|
|
2015-09-18 17:11:36 +09:00
|
|
|
// Set SEO properties
|
|
|
|
|
|
|
|
var seoProperties = {meta: {}};
|
|
|
|
|
|
|
|
// Set site name
|
2016-02-16 15:08:30 +09:00
|
|
|
DocHead.addMeta({property: "og:site_name", content: Telescope.settings.get("title")});
|
2015-09-18 17:11:36 +09:00
|
|
|
|
|
|
|
// Set title
|
|
|
|
Telescope.SEO.setTitle(post.title);
|
|
|
|
|
|
|
|
// Set description
|
|
|
|
if (!!post.body) {
|
|
|
|
var description = Telescope.utils.trimWords(post.body, 100);
|
|
|
|
Telescope.SEO.setDescription(description);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set image
|
|
|
|
if (!!post.thumbnailUrl) {
|
|
|
|
var image = Telescope.utils.addHttp(post.thumbnailUrl);
|
|
|
|
DocHead.addMeta({property: "twitter:card", content: "summary_large_image"});
|
|
|
|
Telescope.SEO.setImage(image);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set Twitter username
|
2016-02-16 15:08:30 +09:00
|
|
|
if (!!Telescope.settings.get("twitterAccount")) {
|
|
|
|
DocHead.addMeta({property: "twitter:site", content: Telescope.settings.get("twitterAccount")});
|
2015-09-18 17:11:36 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2015-09-17 14:51:14 +09:00
|
|
|
Template.post_page.onCreated(function () {
|
|
|
|
|
|
|
|
var template = this;
|
|
|
|
var postId = FlowRouter.getParam("_id");
|
|
|
|
|
|
|
|
// initialize the reactive variables
|
|
|
|
template.ready = new ReactiveVar(false);
|
|
|
|
|
|
|
|
var postSubscription = Telescope.subsManager.subscribe('singlePost', postId);
|
|
|
|
var postUsersSubscription = Telescope.subsManager.subscribe('postUsers', postId);
|
|
|
|
var commentSubscription = Telescope.subsManager.subscribe('commentsList', {view: 'postComments', postId: postId});
|
|
|
|
|
|
|
|
// Autorun 3: when subscription is ready, update the data helper's terms
|
|
|
|
template.autorun(function () {
|
|
|
|
|
|
|
|
var subscriptionsReady = postSubscription.ready(); // ⚡ reactive ⚡
|
|
|
|
|
2015-09-18 17:11:36 +09:00
|
|
|
// if subscriptions are ready, set terms to subscriptionsTerms and update SEO stuff
|
2015-09-17 14:51:14 +09:00
|
|
|
if (subscriptionsReady) {
|
|
|
|
template.ready.set(true);
|
2015-10-09 14:03:00 +09:00
|
|
|
var post = Posts.findOne(FlowRouter.getParam("_id"));
|
|
|
|
if (post) {
|
2015-10-10 20:04:29 +09:00
|
|
|
doSEOStuff(post);
|
2015-10-21 12:40:01 +09:00
|
|
|
} else {
|
|
|
|
DocHead.addMeta({
|
|
|
|
name: "name",
|
|
|
|
property: "prerender-status-code",
|
|
|
|
content: "404"
|
|
|
|
});
|
|
|
|
DocHead.addMeta({
|
|
|
|
name: "name",
|
|
|
|
property: "robots",
|
|
|
|
content: "noindex, nofollow"
|
|
|
|
});
|
2015-10-09 14:03:00 +09:00
|
|
|
}
|
2015-09-17 14:51:14 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-05-09 13:26:31 +09:00
|
|
|
Template.post_page.helpers({
|
2015-09-17 14:51:14 +09:00
|
|
|
ready: function () {
|
|
|
|
return Template.instance().ready.get();
|
|
|
|
},
|
|
|
|
post: function () {
|
|
|
|
return Posts.findOne(FlowRouter.getParam("_id"));
|
|
|
|
},
|
2015-09-08 11:08:02 +09:00
|
|
|
canView: function () {
|
|
|
|
var post = this;
|
2016-02-06 12:31:12 +09:00
|
|
|
return Users.can.viewPost(Meteor.user(), post);
|
2015-09-08 11:08:02 +09:00
|
|
|
},
|
2015-05-09 13:26:31 +09:00
|
|
|
isPending: function () {
|
2015-09-03 09:30:04 +09:00
|
|
|
return this.status === Posts.config.STATUS_PENDING;
|
2015-05-09 13:26:31 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-04-13 14:52:03 +09:00
|
|
|
Template.post_page.rendered = function(){
|
2014-08-28 11:10:31 +09:00
|
|
|
$('body').scrollTop(0);
|
2014-09-16 15:18:27 -04:00
|
|
|
};
|