added canonical link

This commit is contained in:
Sacha Greif 2015-06-19 16:39:13 +09:00
parent 464e1ae481
commit 0c492e3012
2 changed files with 9 additions and 2 deletions

View file

@ -28,6 +28,10 @@ Template.layout.rendered = function(){
link.href = Settings.get('faviconUrl', '/img/favicon.ico');
document.getElementsByTagName('head')[0].appendChild(link);
// canonical
var canonicalLink = document.createElement('link');
canonicalLink.rel = 'canonical';
document.getElementsByTagName('head')[0].appendChild(canonicalLink);
};
Template.layout.events({

View file

@ -154,8 +154,11 @@ Posts.controllers.page = RouteController.extend({
onAfterAction: function () {
var post = this.post();
if (post && post.slug !== this.params.slug) {
window.history.replaceState({}, "", post.getPageUrl());
if (post) {
if (post.slug !== this.params.slug) {
window.history.replaceState({}, "", post.getPageUrl());
}
$('link[rel="canonical"]').attr("href", post.getPageUrl(true));
}
},