mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Bug fix - unable to view single page
- The fancyFirstChar plugin expected to always get an array of posts, and therefore broke on the single post pages - Changed the plugin to cope with single objects as well as arrays
This commit is contained in:
parent
b37f542448
commit
7acd165d7a
1 changed files with 27 additions and 20 deletions
|
@ -1,16 +1,11 @@
|
||||||
|
var _ = require('underscore');
|
||||||
|
|
||||||
var fancyFirstChar;
|
var fancyFirstChar;
|
||||||
|
|
||||||
fancyFirstChar = {
|
function fancify(originalContent) {
|
||||||
init: function (ghost) {
|
var newContent,
|
||||||
ghost.registerFilter('prePostsRender', function (posts) {
|
|
||||||
var post,
|
|
||||||
originalContent,
|
|
||||||
newContent,
|
|
||||||
firstCharIndex = 0;
|
firstCharIndex = 0;
|
||||||
|
|
||||||
for (post in posts) {
|
|
||||||
if (posts.hasOwnProperty(post)) {
|
|
||||||
originalContent = posts[post].content_html;
|
|
||||||
if (originalContent.substr(0, 1) === '<') {
|
if (originalContent.substr(0, 1) === '<') {
|
||||||
firstCharIndex = originalContent.indexOf('>') + 1;
|
firstCharIndex = originalContent.indexOf('>') + 1;
|
||||||
}
|
}
|
||||||
|
@ -21,9 +16,21 @@ fancyFirstChar = {
|
||||||
newContent += '</span>';
|
newContent += '</span>';
|
||||||
newContent += originalContent.substr(firstCharIndex + 1, originalContent.length - firstCharIndex - 1);
|
newContent += originalContent.substr(firstCharIndex + 1, originalContent.length - firstCharIndex - 1);
|
||||||
|
|
||||||
posts[post].content_html = newContent;
|
return newContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fancyFirstChar = {
|
||||||
|
init: function (ghost) {
|
||||||
|
ghost.registerFilter('prePostsRender', function (posts) {
|
||||||
|
if (_.isArray(posts)) {
|
||||||
|
_.each(posts, function (post) {
|
||||||
|
post.content_html = fancify(post.content_html);
|
||||||
|
});
|
||||||
|
} else if (posts.hasOwnProperty('content_html')) {
|
||||||
|
posts.content_html = fancify(posts.content_html);
|
||||||
}
|
}
|
||||||
|
|
||||||
return posts;
|
return posts;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Reference in a new issue