2014-10-10 16:54:07 +02:00
|
|
|
// # Meta Title Helper
|
|
|
|
// Usage: `{{meta_title}}`
|
|
|
|
//
|
|
|
|
// Page title used for sharing and SEO
|
|
|
|
//
|
|
|
|
// We use the name meta_title to match the helper for consistency:
|
|
|
|
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
|
|
|
|
|
|
|
|
var _ = require('lodash'),
|
|
|
|
config = require('../config'),
|
|
|
|
filters = require('../filters'),
|
|
|
|
meta_title;
|
|
|
|
|
|
|
|
meta_title = function (options) {
|
|
|
|
/*jshint unused:false*/
|
|
|
|
var title = '',
|
|
|
|
blog,
|
|
|
|
page,
|
2015-01-30 23:20:47 +01:00
|
|
|
pageString = '',
|
|
|
|
pagePattern = new RegExp('\\/' + config.routeKeywords.page + '\\/(\\d+)');
|
2014-10-10 16:54:07 +02:00
|
|
|
|
|
|
|
if (_.isString(this.relativeUrl)) {
|
|
|
|
blog = config.theme;
|
2015-01-30 23:20:47 +01:00
|
|
|
page = this.relativeUrl.match(pagePattern);
|
2014-10-10 16:54:07 +02:00
|
|
|
if (page) {
|
|
|
|
pageString = ' - Page ' + page[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.relativeUrl || this.relativeUrl === '/' || this.relativeUrl === '') {
|
|
|
|
title = blog.title;
|
|
|
|
} else if (this.author) {
|
|
|
|
title = this.author.name + pageString + ' - ' + blog.title;
|
|
|
|
} else if (this.tag) {
|
2014-12-21 12:39:49 +01:00
|
|
|
title = _.isEmpty(this.tag.meta_title) ? this.tag.name + pageString + ' - ' + blog.title : this.tag.meta_title;
|
2014-10-10 16:54:07 +02:00
|
|
|
} else if (this.post) {
|
|
|
|
title = _.isEmpty(this.post.meta_title) ? this.post.title : this.post.meta_title;
|
|
|
|
} else {
|
|
|
|
title = blog.title + pageString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return filters.doFilter('meta_title', title).then(function (title) {
|
|
|
|
title = title || '';
|
|
|
|
return title.trim();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = meta_title;
|