分类展示图片#35
Open
co-neco wants to merge 1 commit into
Open
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
1 需求描述
我有几套图,一个是路人女主,一个是苍之彼方的四重奏等。我的需求是根据当前日期(每月的几号),展示某一套图。
2 实现
修改engine.js对图库的获取:图库在传给randomBG方法前,根据当前日期过滤出某一套图,然后传给randomBG。
3 使用
3.1 放入图片链接
在个人博客工程的source/_data/image_host目录下放入几套图的链接,每一套图用一个文件表示,举例如下:
saenai.txt:
https://tva4.sinaimg.cn/large/afc1d3e3ly8gt2oy0jlc8j20q611fn16.jpg
https://tva3.sinaimg.cn/large/afc1d3e3ly8gt2oy13xnsj20q60zzwk2.jpg
https://tva1.sinaimg.cn/large/afc1d3e3ly8gt2oy2q4dnj20q60zrwkw.jpg
aokana.txt:
https://gitee.com/co-neco/pic_bed/raw/master/cg%20(1196).jpg
https://gitee.com/co-neco/pic_bed/raw/master/cg%20(1180).jpg
https://gitee.com/co-neco/pic_bed/raw/master/cg%20(1179).jpg
3.2 执行add_hyphen_for_image_url.py脚本
该脚本需要一个参数,就是source/_data/image_host目录的路径。
执行该脚本后,会生成一个source/_data/image.yml文件,该文件的形式如下:
# aokana.txt
https://gitee.com/co-neco/pic_bed/raw/master/cg%20(1196).jpg
https://gitee.com/co-neco/pic_bed/raw/master/cg%20(1180).jpg
https://gitee.com/co-neco/pic_bed/raw/master/cg%20(1179).jpg
# saenai.txt:
https://tva4.sinaimg.cn/large/afc1d3e3ly8gt2oy0jlc8j20q611fn16.jpg
https://tva3.sinaimg.cn/large/afc1d3e3ly8gt2oy13xnsj20q60zzwk2.jpg
https://tva1.sinaimg.cn/large/afc1d3e3ly8gt2oy2q4dnj20q60zrwkw.jpg
3.3 重启hexo的本地服务器
重启之后(hexo s --debug),就能看到这两套图只会显示其中某一套。
4 注意事项
因为主题部署之后,网页的图片链接是写死的,所以我们需要每天重新部署一次。
这里使用github的schedule事件,使用方法如下:
这里设置凌晨一点是避免过多任务都在0点执行。另外由于github的schedule事件不准,所以重启的时间会稍有延后,大概10多分钟。