GeekaholicLin / hexo-theme-ylion

:blush: 说不定是一个让你感到惊喜的hexo主题 :beers: :candy:
http://blog.geekaholic.cn
MIT License
120 stars 30 forks source link

可以讓文章無圖的時候放預設圖片嗎? #24

Closed mosdeo closed 7 years ago

mosdeo commented 7 years ago

如果該文章沒有圖,就要看著圈圈一直轉,好討厭!
可以設定內文無圖時的預設圖片嗎?

GeekaholicLin commented 7 years ago

是可以的哦,请看文档~ 可以有两种方式覆盖文章内的图片。一个是front-matter针对特定文章的,有一个是在主题配置文件中的defaultImgs设置。

### index article excerpt
### 首页文章简介的图片
### 规则:Front-matter中的自定义'img'字段 > 文章内的图片(随机获取) > defaultImgs(随机获取)
defaultImgs:
  - http://XXXX.example.jpg
  - /img/default-1.jpg
mosdeo commented 7 years ago

我改了 themes/ylion/_config.yml,最後加上這一段

defaultImgs: http://olpvawdcl.bkt.clouddn.com/blog-bg4.png

然後要編譯的時候產生一大堆錯誤,出來的結果也沒成功。不知道要怎麼辦

hexo g INFO Start processing ERROR Theme config load failed. ERROR Process failed: _config.yml YAMLException: duplicated mapping key at line 208, column 1: defaultImgs: http://olpvawdcl.bk ... ^ at generateError (/home/lky/workspace/mosdeo.github.io/node_modules/js-yaml/lib/js-yaml/loader.js:165:10) at throwError (/home/lky/workspace/mosdeo.github.io/node_modules/js-yaml/lib/js-yaml/loader.js:171:9)

後面一堆錯誤我就不貼了

GeekaholicLin commented 7 years ago

还请粘贴一下你的配置文件。初步判断是你的主题配置文件格式错误

mosdeo commented 7 years ago

配置文件在此 https://gist.github.com/mosdeo/9aa0feb7f997ac5e43b6bd028209d049

GeekaholicLin commented 7 years ago

请认真看本项目的配置文件说明(:зゝ∠)

你出错的原因在于,yaml配置文件已经有这个字段了。你搜索一下,然后更改~比如在你的配置文件中是这一部分

https://gist.github.com/mosdeo/9aa0feb7f997ac5e43b6bd028209d049#file-_config-yml-L110-L112

按照配置文件的示例,替换掉url即可~

GeekaholicLin commented 7 years ago

嗯,记得把你在最后添加的去掉。

https://gist.github.com/mosdeo/9aa0feb7f997ac5e43b6bd028209d049#file-_config-yml-L208

mosdeo commented 7 years ago

感謝大大,我昨天才想說;「這個設定怎麼沒有放在原始內容呢?」
原來是我自己重複了,眼殘~
現在已經成功顯示預設圖片。

magicianLy commented 6 years ago

想问一下,如果是文档里面的图片这样也可以吗?