自定义副标题源
Butterfly的副标题可以使用一言API,但是只有固定的3个API,我打算加上我自建的一言。
打开node_modules/hexo-theme-butterfly/layout/includes/third-party/subtitle.pug
加入以下代码
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 27 28 29 30 31 32
| when 5 script. function subtitleType () { #根据需要修改下面代码 fetch('https://api.sglzp.cn/hitokoto.php?charset=utf-8') .then(response => response.text()) .then(data => { if (!{theme.subtitle.effect}) { var sub = "!{theme.subtitle.sub}".length == 0 ? new Array() : "!{theme.subtitle.sub}".split(',') var both = sub.unshift(data) var typed = new Typed('#subtitle', { strings: sub, startDelay: 300, typeSpeed: 150, loop: !{theme.subtitle.loop}, backSpeed: 50, }) } else { document.getElementById('subtitle').innerHTML = data } }) }
if (!{theme.subtitle.effect}) { if (typeof Typed === 'function') { subtitleType() } else { getScript('!{url_for(theme.CDN.typed)}').then(subtitleType) } } else { subtitleType() }
|
更改主题配置_config.butterfly.yml
1 2 3 4 5 6
| subtitle: enable: true effect: true loop: true source: 5 sub:
|