mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Merge pull request #3817 from felixrieseberg/iss685
Prev & Next Links for Ghost_Head
This commit is contained in:
commit
3a1839dfa3
2 changed files with 43 additions and 1 deletions
|
@ -489,7 +489,9 @@ coreHelpers.ghost_head = function (options) {
|
||||||
blog = config.theme(),
|
blog = config.theme(),
|
||||||
head = [],
|
head = [],
|
||||||
majorMinor = /^(\d+\.)?(\d+)/,
|
majorMinor = /^(\d+\.)?(\d+)/,
|
||||||
trimmedVersion = this.version;
|
trimmedVersion = this.version,
|
||||||
|
trimmedUrlpattern = /.+(?=\/page\/\d*\/)/,
|
||||||
|
trimmedUrl, next, prev;
|
||||||
|
|
||||||
trimmedVersion = trimmedVersion ? trimmedVersion.match(majorMinor)[0] : '?';
|
trimmedVersion = trimmedVersion ? trimmedVersion.match(majorMinor)[0] : '?';
|
||||||
|
|
||||||
|
@ -501,6 +503,20 @@ coreHelpers.ghost_head = function (options) {
|
||||||
return coreHelpers.url.call(self, {hash: {absolute: true}}).then(function (url) {
|
return coreHelpers.url.call(self, {hash: {absolute: true}}).then(function (url) {
|
||||||
head.push('<link rel="canonical" href="' + url + '" />');
|
head.push('<link rel="canonical" href="' + url + '" />');
|
||||||
|
|
||||||
|
if (self.pagination) {
|
||||||
|
trimmedUrl = self.relativeUrl.match(trimmedUrlpattern);
|
||||||
|
if (self.pagination.prev) {
|
||||||
|
prev = (self.pagination.prev > 1 ? prev = '/page/' + self.pagination.prev + '/' : prev = '/');
|
||||||
|
prev = (trimmedUrl) ? '/' + trimmedUrl + prev : prev;
|
||||||
|
head.push('<link rel="prev" href="' + config.urlFor({relativeUrl: prev}, true) + '" />');
|
||||||
|
}
|
||||||
|
if (self.pagination.next) {
|
||||||
|
next = '/page/' + self.pagination.next + '/';
|
||||||
|
next = (trimmedUrl) ? '/' + trimmedUrl + next : next;
|
||||||
|
head.push('<link rel="next" href="' + config.urlFor({relativeUrl: next}, true) + '" />');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return filters.doFilter('ghost_head', head);
|
return filters.doFilter('ghost_head', head);
|
||||||
}).then(function (head) {
|
}).then(function (head) {
|
||||||
var headString = _.reduce(head, function (memo, item) { return memo + '\n' + item; }, '');
|
var headString = _.reduce(head, function (memo, item) { return memo + '\n' + item; }, '');
|
||||||
|
|
|
@ -550,6 +550,32 @@ describe('Core Helpers', function () {
|
||||||
done();
|
done();
|
||||||
}).catch(done);
|
}).catch(done);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('returns next & prev URL correctly for middle page', function (done) {
|
||||||
|
configUpdate({url: 'http://testurl.com'});
|
||||||
|
helpers.ghost_head.call({version: '0.3.0', relativeUrl: '/page/3/', pagination: {next: '4', prev: '2'}}).then(function (rendered) {
|
||||||
|
should.exist(rendered);
|
||||||
|
rendered.string.should.equal('<meta name="generator" content="Ghost 0.3" />\n' +
|
||||||
|
'<link rel="alternate" type="application/rss+xml" title="Ghost" href="/rss/">\n' +
|
||||||
|
'<link rel="canonical" href="http://testurl.com/page/3/" />\n' +
|
||||||
|
'<link rel="prev" href="http://testurl.com/page/2/" />\n' +
|
||||||
|
'<link rel="next" href="http://testurl.com/page/4/" />');
|
||||||
|
done();
|
||||||
|
}).catch(done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns next & prev URL correctly for second page', function (done) {
|
||||||
|
configUpdate({url: 'http://testurl.com'});
|
||||||
|
helpers.ghost_head.call({version: '0.3.0', relativeUrl: '/page/2/', pagination: {next: '3', prev: '1'}}).then(function (rendered) {
|
||||||
|
should.exist(rendered);
|
||||||
|
rendered.string.should.equal('<meta name="generator" content="Ghost 0.3" />\n' +
|
||||||
|
'<link rel="alternate" type="application/rss+xml" title="Ghost" href="/rss/">\n' +
|
||||||
|
'<link rel="canonical" href="http://testurl.com/page/2/" />\n' +
|
||||||
|
'<link rel="prev" href="http://testurl.com/" />\n' +
|
||||||
|
'<link rel="next" href="http://testurl.com/page/3/" />');
|
||||||
|
done();
|
||||||
|
}).catch(done);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('ghost_foot Helper', function () {
|
describe('ghost_foot Helper', function () {
|
||||||
|
|
Loading…
Add table
Reference in a new issue