想给自己的博客弄一个天气组件,实现方案参考自[^1]。
生成插件
打开和风天气插件网站,注册一个账号,接着创建一个天气简约插件
。生成代码后,我们只需复制两个<script>
之间的代码,我的如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| <div id="he-plugin-simple"></div> <script> WIDGET = { "CONFIG": { "modules": "01234", "background": "3", "tmpColor": "FFFFFF", "tmpSize": "16", "cityColor": "FFFFFF", "citySize": "16", "aqiColor": "FFFFFF", "aqiSize": "16", "weatherIconSize": "24", "alertIconSize": "18", "padding": "10px 10px 10px 10px", "shadow": "1", "language": "auto", "borderRadius": "5", "fixed": "false", "vertical": "top", "horizontal": "left", "key": "*******************" } } </script> <script src="https://widget.qweather.net/simple/static/js/he-simple-common.js?v=2.0"></script>
|
详细步骤
- 在
Hexo\themes\butterfly\source\js\
路径下新建weather.js
文件,将如下代码复制进去。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| WIDGET = { "CONFIG": { "modules": "01234", "background": "3", "tmpColor": "FFFFFF", "tmpSize": "16", "cityColor": "FFFFFF", "citySize": "16", "aqiColor": "FFFFFF", "aqiSize": "16", "weatherIconSize": "24", "alertIconSize": "18", "padding": "10px 10px 10px 10px", "shadow": "1", "language": "auto", "borderRadius": "5", "fixed": "false", "vertical": "top", "horizontal": "left", "key": "*******************" } }
|
- 在主题配置文件
_config.butterfly.yml
中找到inject
的bottom
处引入以下两个js文件:
1 2
| - <script defer data-pjax src="/js/weather.js"></script> - <script defer data-pjax src="https://widget.qweather.net/simple/static/js/he-simple-common.js?v=2.0"></script>
|
如果你有自定义的js
代码,例如custom.js
,也可以将上面的代码复制进你的custom.js
中,效果一样。
1 2
| - <script defer data-pjax src="/js/custom.js"></script> - <script src="https://widget.qweather.net/simple/static/js/he-simple-common.js?v=2.0"></script>
|
- 记得更换
key
为自己的。
- 如果你开启了
pjax
记得在你的 _config.butterfly.yml
中inject
处修改你的引入代码
在\themes\butterfly\layout\includes\header
路径下找到nav.pug
文件,添加如下代码,注意严格对齐:
1 2
| #he-plugin-simple #none_space
|
- 在
\themes\butterfly\source\css\_layout\head.styl
中将#blog_name
替换为#none_space
,//标识的是注释内容
- 大功告成🎉🎉🎉
[^1]: Hexo:Butterfly添加天气组件_hexo和风天气_Chak Aciano的博客-CSDN博客