Ghost/core/server/data/meta/title.js
JT Turner 1f4c01d207 Started moving meta data fetching to functions.
issue #6186
- Moved asset helper logic to a asset url function.
- Created author image function to be used in ghost_head helper.
- Created author url function to be used in the ghost_head helper.
- Created canonical url function to be used in the ghost_head helper.
- Moved meta_description helper logic to a function.
- Moved excerpt helper logic to a function.
- Created an index in data/meta to be used in ghost_head helper to get all data.
- Created keyword function to be used in the ghost_head helper.
- Created modified data function to be used in the ghost_head helper.
- Created next url function to be used in the ghost_head helper.
- Created ogType function to be used in the ghost_head helper.
- Created previous url function to be used in the ghost_head helper.
- Created published data function to be used in the ghost_head helper.
- Created rss url function to be used in the ghost_head helper.
- Created schema function to be used in the ghost_head helper.
- Created structured data function to be used in the ghost_head helper.
- Moved meta_title helper logic to a title function.
- Moved url helper logic to a url function.
- Wrote tests for all the new functions

This is just the first step. I plan on refactoring the ghost head to use these new functions.
2016-01-23 13:58:21 -08:00

32 lines
1.0 KiB
JavaScript

var _ = require('lodash'),
config = require('../../config');
function getTitle(data, root) {
var title = '',
context = root ? root.context : null,
blog = config.theme,
pagination = root ? root.pagination : null,
pageString = '';
if (pagination && pagination.total > 1) {
pageString = ' - Page ' + pagination.page;
}
if (data.meta_title) {
title = data.meta_title;
} else if (_.contains(context, 'home')) {
title = blog.title;
} else if (_.contains(context, 'author') && data.author) {
title = data.author.name + pageString + ' - ' + blog.title;
} else if (_.contains(context, 'tag') && data.tag) {
title = data.tag.meta_title || data.tag.name + pageString + ' - ' + blog.title;
} else if ((_.contains(context, 'post') || _.contains(context, 'page')) && data.post) {
title = data.post.meta_title || data.post.title;
} else {
title = blog.title + pageString;
}
return (title || '').trim();
}
module.exports = getTitle;