Added meta title and description theme helpers

closes #795

- firstly fixes res.locals to include path again
- adds {{media_title}} and {{media_description}} theme helpers
This commit is contained in:
cobbspur 2013-09-17 22:11:02 +01:00
parent adae9f4180
commit 6a5f88ed18
2 changed files with 35 additions and 0 deletions

View File

@ -101,6 +101,7 @@ function ghostLocals(req, res, next) {
// Make sure we have a locals value.
res.locals = res.locals || {};
res.locals.version = packageInfo.version;
res.locals.path = req.path;
if (res.isAdmin) {
_.extend(res.locals, {

View File

@ -218,6 +218,40 @@ coreHelpers = function (ghost) {
});
});
ghost.registerThemeHelper('meta_title', function (options) {
var title, blog;
blog = ghost.blogGlobals();
if (_.isString(this.path)) {
if (!this.path || this.path === '/' || this.path === '' || this.path.match(/\/page/)) {
blog = ghost.blogGlobals();
title = blog.title;
} else {
title = this.post.title;
}
}
return ghost.doFilter('meta_title', title, function (title) {
return new hbs.handlebars.SafeString(title.trim());
});
});
ghost.registerThemeHelper('meta_description', function (options) {
var description, blog;
blog = ghost.blogGlobals();
if (_.isString(this.path)) {
if (!this.path || this.path === '/' || this.path === '' || this.path.match(/\/page/)) {
blog = ghost.blogGlobals();
description = blog.description;
} else {
description = '';
}
}
return ghost.doFilter('meta_description', description, function (description) {
return new hbs.handlebars.SafeString(description.trim());
});
});
ghost.registerThemeHelper('ghost_foot', function (options) {
var foot = [];
foot.push('<script src="/shared/vendor/jquery/jquery.js"></script>');