-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
title.js
52 lines (46 loc) · 1.89 KB
/
title.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var _ = require('lodash'),
settingsCache = require('../../services/settings/cache');
function getTitle(data, root, options) {
var title = '',
context = root ? root.context : null,
postSdTitle,
blogTitle = settingsCache.get('title'),
pagination = root ? root.pagination : null,
pageString = '';
options = options ? options : {};
if (pagination && pagination.total > 1) {
pageString = _.has(options.hash, 'page') ? options.hash.page.replace('%', pagination.page) : ' (Page ' + pagination.page + ')';
}
// If there's a specific meta title
if (data.meta_title) {
title = data.meta_title;
// Home title
} else if (_.includes(context, 'home')) {
title = blogTitle;
// Author title, paged
} else if (_.includes(context, 'author') && data.author && _.includes(context, 'paged')) {
title = data.author.name + ' - ' + blogTitle + pageString;
// Author title, index
} else if (_.includes(context, 'author') && data.author) {
title = data.author.name + ' - ' + blogTitle;
// Tag title, paged
} else if (_.includes(context, 'tag') && data.tag && _.includes(context, 'paged')) {
title = data.tag.meta_title || data.tag.name + ' - ' + blogTitle + pageString;
// Tag title, index
} else if (_.includes(context, 'tag') && data.tag) {
title = data.tag.meta_title || data.tag.name + ' - ' + blogTitle;
// Post title
} else if ((_.includes(context, 'post') || _.includes(context, 'page')) && data.post) {
if (options && options.property) {
postSdTitle = options.property + '_title';
title = data.post[postSdTitle] || '';
} else {
title = data.post.meta_title || data.post.title;
}
// Fallback
} else {
title = blogTitle + pageString;
}
return (title || '').trim();
}
module.exports = getTitle;