0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Merge pull request #4879 from katiefenn/issue-4519-keywords

This commit is contained in:
Hannah Wolfe 2015-03-23 15:00:22 +00:00
commit 7ad47e9240
9 changed files with 77 additions and 38 deletions

View file

@ -80,7 +80,16 @@ cacheInvalidationHeader = function (req, result) {
// Don't set x-cache-invalidate header for drafts // Don't set x-cache-invalidate header for drafts
if (hasStatusChanged || wasDeleted || wasPublishedUpdated) { if (hasStatusChanged || wasDeleted || wasPublishedUpdated) {
cacheInvalidate = '/, /page/*, /rss/, /rss/*, /tag/*, /author/*, /sitemap-*.xml'; cacheInvalidate = [
'/',
'/' + config.routeKeywords.page + '/*',
'/rss/',
'/rss/*',
'/' + config.routeKeywords.tag + '/*',
'/' + config.routeKeywords.author + '/*',
'/sitemap-*.xml'
].join(', ');
if (id && post.slug && post.url) { if (id && post.slug && post.url) {
cacheInvalidate += ', ' + post.url; cacheInvalidate += ', ' + post.url;
} }

View file

@ -202,6 +202,11 @@ ConfigManager.prototype.set = function (config) {
// normalise the URL by removing any trailing slash // normalise the URL by removing any trailing slash
url: this._config.url ? this._config.url.replace(/\/$/, '') : '' url: this._config.url ? this._config.url.replace(/\/$/, '') : ''
}, },
routeKeywords: {
tag: 'tag',
author: 'author',
page: 'page'
},
slugs: { slugs: {
// Used by generateSlug to generate slugs for posts, tags, users, .. // Used by generateSlug to generate slugs for posts, tags, users, ..
// reserved slugs are reserved but can be extended/removed by apps // reserved slugs are reserved but can be extended/removed by apps

View file

@ -129,10 +129,10 @@ function urlFor(context, data, absolute) {
urlPath = data.post.url; urlPath = data.post.url;
secure = data.secure; secure = data.secure;
} else if (context === 'tag' && data.tag) { } else if (context === 'tag' && data.tag) {
urlPath = '/tag/' + data.tag.slug + '/'; urlPath = '/' + ghostConfig.routeKeywords.tag + '/' + data.tag.slug + '/';
secure = data.tag.secure; secure = data.tag.secure;
} else if (context === 'author' && data.author) { } else if (context === 'author' && data.author) {
urlPath = '/author/' + data.author.slug + '/'; urlPath = '/' + ghostConfig.routeKeywords.author + '/' + data.author.slug + '/';
secure = data.author.secure; secure = data.author.secure;
} else if (context === 'image' && data.image) { } else if (context === 'image' && data.image) {
urlPath = data.image; urlPath = data.image;

View file

@ -84,23 +84,25 @@ function handleError(next) {
function setResponseContext(req, res, data) { function setResponseContext(req, res, data) {
var contexts = [], var contexts = [],
pageParam = req.params.page !== undefined ? parseInt(req.params.page, 10) : 1; pageParam = req.params.page !== undefined ? parseInt(req.params.page, 10) : 1,
tagPattern = new RegExp('^\\/' + config.routeKeywords.tag + '\\/'),
authorPattern = new RegExp('^\\/' + config.routeKeywords.author + '\\/');
// paged context // paged context
if (!isNaN(pageParam) && pageParam > 1) { if (!isNaN(pageParam) && pageParam > 1) {
contexts.push('paged'); contexts.push('paged');
} }
if (req.route.path === '/page/:page/') { if (req.route.path === '/' + config.routeKeywords.page + '/:page/') {
contexts.push('index'); contexts.push('index');
} else if (req.route.path === '/') { } else if (req.route.path === '/') {
contexts.push('home'); contexts.push('home');
contexts.push('index'); contexts.push('index');
} else if (/\/rss\/(:page\/)?$/.test(req.route.path)) { } else if (/\/rss\/(:page\/)?$/.test(req.route.path)) {
contexts.push('rss'); contexts.push('rss');
} else if (/^\/tag\//.test(req.route.path)) { } else if (tagPattern.test(req.route.path)) {
contexts.push('tag'); contexts.push('tag');
} else if (/^\/author\//.test(req.route.path)) { } else if (authorPattern.test(req.route.path)) {
contexts.push('author'); contexts.push('author');
} else if (data && data.post && data.post.page) { } else if (data && data.post && data.post.page) {
contexts.push('page'); contexts.push('page');
@ -185,7 +187,7 @@ frontendControllers = {
// Get url for tag page // Get url for tag page
function tagUrl(tag, page) { function tagUrl(tag, page) {
var url = config.paths.subdir + '/tag/' + tag + '/'; var url = config.paths.subdir + '/' + config.routeKeywords.tag + '/' + tag + '/';
if (page && page > 1) { if (page && page > 1) {
url += 'page/' + page + '/'; url += 'page/' + page + '/';
@ -239,10 +241,10 @@ frontendControllers = {
// Get url for tag page // Get url for tag page
function authorUrl(author, page) { function authorUrl(author, page) {
var url = config.paths.subdir + '/author/' + author + '/'; var url = config.paths.subdir + '/' + config.routeKeywords.author + '/' + author + '/';
if (page && page > 1) { if (page && page > 1) {
url += 'page/' + page + '/'; url += config.routeKeywords.page + '/' + page + '/';
} }
return url; return url;
@ -429,11 +431,11 @@ frontendControllers = {
} }
function isTag() { function isTag() {
return req.route.path.indexOf('/tag/') !== -1; return req.route.path.indexOf('/' + config.routeKeywords.tag + '/') !== -1;
} }
function isAuthor() { function isAuthor() {
return req.route.path.indexOf('/author/') !== -1; return req.route.path.indexOf('/' + config.routeKeywords.author + '/') !== -1;
} }
// Initialize RSS // Initialize RSS
@ -442,9 +444,9 @@ frontendControllers = {
baseUrl = config.paths.subdir; baseUrl = config.paths.subdir;
if (isTag()) { if (isTag()) {
baseUrl += '/tag/' + slugParam + '/rss/'; baseUrl += '/' + config.routeKeywords.tag + '/' + slugParam + '/rss/';
} else if (isAuthor()) { } else if (isAuthor()) {
baseUrl += '/author/' + slugParam + '/rss/'; baseUrl += '/' + config.routeKeywords.author + '/' + slugParam + '/rss/';
} else { } else {
baseUrl += '/rss/'; baseUrl += '/rss/';
} }
@ -483,14 +485,14 @@ frontendControllers = {
if (isTag()) { if (isTag()) {
if (page.meta.filters.tags) { if (page.meta.filters.tags) {
title = page.meta.filters.tags[0].name + ' - ' + title; title = page.meta.filters.tags[0].name + ' - ' + title;
feedUrl = siteUrl + 'tag/' + page.meta.filters.tags[0].slug + '/rss/'; feedUrl = siteUrl + config.routeKeywords.tag + '/' + page.meta.filters.tags[0].slug + '/rss/';
} }
} }
if (isAuthor()) { if (isAuthor()) {
if (page.meta.filters.author) { if (page.meta.filters.author) {
title = page.meta.filters.author.name + ' - ' + title; title = page.meta.filters.author.name + ' - ' + title;
feedUrl = siteUrl + 'author/' + page.meta.filters.author.slug + '/rss/'; feedUrl = siteUrl + config.routeKeywords.author + '/' + page.meta.filters.author.slug + '/rss/';
} }
} }

View file

@ -13,16 +13,17 @@ var _ = require('lodash'),
meta_description = function () { meta_description = function () {
var description, var description,
blog; blog,
pagePattern = new RegExp('\\/page\\/');
if (_.isString(this.relativeUrl)) { if (_.isString(this.relativeUrl)) {
blog = config.theme; blog = config.theme;
if (!this.relativeUrl || this.relativeUrl === '/' || this.relativeUrl === '') { if (!this.relativeUrl || this.relativeUrl === '/' || this.relativeUrl === '') {
description = blog.description; description = blog.description;
} else if (this.author) { } else if (this.author) {
description = /\/page\//.test(this.relativeUrl) ? '' : this.author.bio; description = pagePattern.test(this.relativeUrl) ? '' : this.author.bio;
} else if (this.tag) { } else if (this.tag) {
if (/\/page\//.test(this.relativeUrl)) { if (pagePattern.test(this.relativeUrl)) {
description = ''; description = '';
} else { } else {
description = _.isEmpty(this.tag.meta_description) ? '' : this.tag.meta_description; description = _.isEmpty(this.tag.meta_description) ? '' : this.tag.meta_description;

View file

@ -16,13 +16,12 @@ meta_title = function (options) {
var title = '', var title = '',
blog, blog,
page, page,
pageString = ''; pageString = '',
pagePattern = new RegExp('\\/' + config.routeKeywords.page + '\\/(\\d+)');
if (_.isString(this.relativeUrl)) { if (_.isString(this.relativeUrl)) {
blog = config.theme; blog = config.theme;
page = this.relativeUrl.match(pagePattern);
page = this.relativeUrl.match(/\/page\/(\d+)/);
if (page) { if (page) {
pageString = ' - Page ' + page[1]; pageString = ' - Page ' + page[1];
} }

View file

@ -19,15 +19,15 @@ page_url = function (context, block) {
var url = config.paths.subdir; var url = config.paths.subdir;
if (this.tagSlug !== undefined) { if (this.tagSlug !== undefined) {
url += '/tag/' + this.tagSlug; url += '/' + config.routeKeywords.tag + '/' + this.tagSlug;
} }
if (this.authorSlug !== undefined) { if (this.authorSlug !== undefined) {
url += '/author/' + this.authorSlug; url += '/' + config.routeKeywords.author + '/' + this.authorSlug;
} }
if (context > 1) { if (context > 1) {
url += '/page/' + context; url += '/' + config.routeKeywords.page + '/' + context;
} }
url += '/'; url += '/';

View file

@ -37,19 +37,19 @@ frontendRoutes = function () {
}); });
// Tags // Tags
router.get('/tag/:slug/rss/', frontend.rss); router.get('/' + config.routeKeywords.tag + '/:slug/rss/', frontend.rss);
router.get('/tag/:slug/rss/:page/', frontend.rss); router.get('/' + config.routeKeywords.tag + '/:slug/rss/:page/', frontend.rss);
router.get('/tag/:slug/page/:page/', frontend.tag); router.get('/' + config.routeKeywords.tag + '/:slug/' + config.routeKeywords.page + '/:page/', frontend.tag);
router.get('/tag/:slug/', frontend.tag); router.get('/' + config.routeKeywords.tag + '/:slug/', frontend.tag);
// Authors // Authors
router.get('/author/:slug/rss/', frontend.rss); router.get('/' + config.routeKeywords.author + '/:slug/rss/', frontend.rss);
router.get('/author/:slug/rss/:page/', frontend.rss); router.get('/' + config.routeKeywords.author + '/:slug/rss/:page/', frontend.rss);
router.get('/author/:slug/page/:page/', frontend.author); router.get('/' + config.routeKeywords.author + '/:slug/' + config.routeKeywords.page + '/:page/', frontend.author);
router.get('/author/:slug/', frontend.author); router.get('/' + config.routeKeywords.author + '/:slug/', frontend.author);
// Default // Default
router.get('/page/:page/', frontend.homepage); router.get('/' + config.routeKeywords.page + '/:page/', frontend.homepage);
router.get('/', frontend.homepage); router.get('/', frontend.homepage);
router.get('*', frontend.single); router.get('*', frontend.single);

View file

@ -204,6 +204,11 @@ describe('Frontend Controller', function () {
'tag.hbs': '/content/themes/casper/tag.hbs' 'tag.hbs': '/content/themes/casper/tag.hbs'
} }
} }
},
routeKeywords: {
page: 'page',
tag: 'tag',
author: 'author'
} }
}); });
}); });
@ -257,6 +262,11 @@ describe('Frontend Controller', function () {
'tag.hbs': '/content/themes/casper/tag.hbs' 'tag.hbs': '/content/themes/casper/tag.hbs'
} }
} }
},
routeKeywords: {
page: 'page',
tag: 'tag',
author: 'author'
} }
}); });
@ -359,6 +369,11 @@ describe('Frontend Controller', function () {
'tag.hbs': '/content/themes/casper/tag.hbs' 'tag.hbs': '/content/themes/casper/tag.hbs'
} }
} }
},
routeKeywords: {
page: 'page',
tag: 'tag',
author: 'author'
} }
}); });
}); });
@ -450,7 +465,8 @@ describe('Frontend Controller', function () {
it('Redirects to base tag page if page number is 0 with subdirectory', function () { it('Redirects to base tag page if page number is 0 with subdirectory', function () {
frontend.__set__('config', { frontend.__set__('config', {
paths: {subdir: '/blog'} paths: {subdir: '/blog'},
routeKeywords: {tag: 'tag'}
}); });
var req = {params: {page: 0, slug: 'pumpkin'}}; var req = {params: {page: 0, slug: 'pumpkin'}};
@ -464,7 +480,8 @@ describe('Frontend Controller', function () {
it('Redirects to base tag page if page number is 1 with subdirectory', function () { it('Redirects to base tag page if page number is 1 with subdirectory', function () {
frontend.__set__('config', { frontend.__set__('config', {
paths: {subdir: '/blog'} paths: {subdir: '/blog'},
routeKeywords: {tag: 'tag'}
}); });
var req = {params: {page: 1, slug: 'pumpkin'}}; var req = {params: {page: 1, slug: 'pumpkin'}};
@ -489,7 +506,8 @@ describe('Frontend Controller', function () {
it('Redirects to last page if page number too big with subdirectory', function (done) { it('Redirects to last page if page number too big with subdirectory', function (done) {
frontend.__set__('config', { frontend.__set__('config', {
paths: {subdir: '/blog'} paths: {subdir: '/blog'},
routeKeywords: {tag: 'tag'}
}); });
var req = {params: {page: 4, slug: 'pumpkin'}}; var req = {params: {page: 4, slug: 'pumpkin'}};
@ -583,6 +601,11 @@ describe('Frontend Controller', function () {
'post.hbs': '/content/themes/casper/post.hbs' 'post.hbs': '/content/themes/casper/post.hbs'
} }
} }
},
routeKeywords: {
page: 'page',
tag: 'tag',
author: 'author'
} }
}); });
}); });