Skip to content

Commit bdbafa5

Browse files
luyuhuangzkqiang
authored andcommitted
✨ 首页副标题支持随机显示
1 parent b7593ab commit bdbafa5

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

_config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,8 @@ index:
499499
slogan:
500500
enable: true
501501

502-
# 为空则按 hexo config.subtitle 显示
503-
# If empty, text based on `subtitle` in hexo config
502+
# 为空则按 hexo config.subtitle 显示,支持列表格式来实现随机选择一行文字显示
503+
# If empty, text based on `subtitle` in hexo config, support list format to random selection of a row for display
504504
text: "An elegant Material-Design theme for Hexo"
505505

506506
# 通过 API 接口作为首页副标题的内容,必须返回的是 JSON 格式,如果请求失败则按 text 字段显示,该功能必须先开启 typing 打字机功能

layout/_partials/plugins/typed.ejs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
typing(text);
4141
}
4242
})
43+
<% } else if (Array.isArray(theme.index.slogan.text) && theme.index.slogan.text.length > 0) { %>
44+
var texts = <%- JSON.stringify(theme.index.slogan.text) %>;
45+
var idx = Math.floor(Math.random() * texts.length);
46+
typing(texts[idx]);
4347
<% } else { %>
4448
typing(text);
4549
<% } %>

0 commit comments

Comments
 (0)