-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add some meta tag * Improve style of code block * Implement `bannerOf` helper, and use for thumbnail * Insert banner image in article content close #4
- Loading branch information
Showing
8 changed files
with
60 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Banner Helper | ||
* @description Get banner url from post. | ||
* @example | ||
* bannerOf(post); | ||
*/ | ||
|
||
hexo.extend.helper.register('bannerOf', function (post) { | ||
var url = post.banner ? post.banner.url : (post.photos && post.photos.length ? post.photos[0] : ''); | ||
var imgRegex = /\<img\s.*?\s?src\s*=\s*['|"]?([^\s'"]+).*?\>/ig; | ||
if (!url) { | ||
var result = imgRegex.exec(post.content); | ||
if (result && result.length > 1) { | ||
url = result[1]; | ||
} | ||
} | ||
return url; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Filter triggered by post rendering. | ||
*/ | ||
|
||
function imgTpl(url) { | ||
return '<img src="' + url + '"/>'; | ||
} | ||
|
||
hexo.extend.filter.register('before_post_render', function (data) { | ||
if (data.banner) { | ||
var img = imgTpl(data.banner.url); | ||
data.content = img + data.content; | ||
} else if (data.photos && data.photos.length) { | ||
var imgs = data.photos.map(imgTpl).join(''); | ||
data.content += imgs + data.content; | ||
} | ||
return data; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters