Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subtitle支持从网络获取 #708

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,27 @@ subtitle:
sub:
- 从来没有真正的绝境, 只有心灵的迷途
- Never really desperate, only the lost of the soul
api:
enable: true

# 请求地址
# Request url
url: "https://cdn.jsdelivr.net/gh/czqu/czqu.github.io@main/json/quote.json"

# 请求方法
# Request method
# Available: GET | POST | PUT
method: "GET"

# 请求头
# Request headers
headers: {}

# 从请求结果获取字符串的取值字段,最终必须是一个字符串,例如返回结果为 {"data": {"author": "fluid", "content": "An elegant theme"}}, 则取值字段为 ['data', 'content'];如果返回是列表则自动选择第一项
# The value field of the string obtained from the response. For example, the response content is {"data": {"author": "fluid", "content": "An elegant theme"}}, the expected `keys: ['data','content']`; if the return is a list, the first item is automatically selected
keys:
- ['data','translation']
- ['data','content']

# 手机二级菜单.
navMenu:
Expand Down
100 changes: 76 additions & 24 deletions layout/_partial/bg-cover-content.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,82 @@
<div class="brand">
<div class="title center-align">
<% if (config.subtitle && config.subtitle.length > 0) { %>
<%= config.subtitle %>
<%= config.subtitle %>
<% } else { %>
subtitle
<% } %>
</div>

<div class="description center-align">
<% if (theme.subtitle.enable) { %>
<span id="subtitle"></span>
<script src="https://cdn.jsdelivr.net/npm/typed.js@2.0.11"></script>
<script>
var typed = new Typed("#subtitle", {
strings: [
<% theme.subtitle.sub.forEach(function(item){%>
<span id="subtitle"></span>
<script src="https://cdn.jsdelivr.net/npm/typed.js@2.0.11"></script>
<script>
<% if ( theme.subtitle.api.enable && theme.subtitle.enable) { %>
textArr=new Array();
$.ajax({
type: '<%= theme.subtitle.api.method %>',
url: '<%= theme.subtitle.api.url %>',
headers: <%- JSON.stringify(theme.subtitle.api.headers || {}) %>,
dataType: 'json',
success: function (result) {
var text;
if (result) {
var keys = [
<% theme.subtitle.api.keys.forEach(function(item){%>
"<%= item %>",
<% }) %>
];
var temp = result;
for (item of keys)
{
key=item.split(',');
if (result instanceof Array) {
result = result[0]
}
for (const k of key) {
var value = result[k]
if (typeof value === 'string') {
text = value
break
} else if (value instanceof Object) {
result = value
}
}
if (text!=null)
{
textArr.push (text);
}
}
result = temp;

}
var typed = new Typed("#subtitle", {
strings: textArr,
startDelay: <%= theme.subtitle.startDelay %>,
typeSpeed: <%= theme.subtitle.typeSpeed %>,
loop: <%= theme.subtitle.loop %>,
backSpeed: <%= theme.subtitle.backSpeed %>,
showCursor: <%= theme.subtitle.showCursor %>
});

}
})
<% } else { %>
var typed = new Typed("#subtitle", {
strings: [
<% theme.subtitle.sub.forEach(function(item){%>
"<%= item %>",
<% }) %>
],
startDelay: <%= theme.subtitle.startDelay %>,
typeSpeed: <%= theme.subtitle.typeSpeed %>,
loop: <%= theme.subtitle.loop %>,
backSpeed: <%= theme.subtitle.backSpeed %>,
showCursor: <%= theme.subtitle.showCursor %>
});
</script>
<% }) %>
],
startDelay: <%= theme.subtitle.startDelay %>,
typeSpeed: <%= theme.subtitle.typeSpeed %>,
loop: <%= theme.subtitle.loop %>,
backSpeed: <%= theme.subtitle.backSpeed %>,
showCursor: <%= theme.subtitle.showCursor %>
});
<% } %>
</script>
<% } else { %>
<%= config.description %>
<% } %>
Expand All @@ -36,13 +88,13 @@
</div>

<% if (theme.banner.enable) { %>
<script>
// 每天切换 banner 图. Switch banner image every day.
var bannerUrl = "<%- theme.jsDelivr.url %><%- url_for('/medias/banner/') %>" + new Date().getDay() + '.jpg';
$('.bg-cover').css('background-image', 'url(' + bannerUrl + ')');
</script>
<script>
// 每天切换 banner 图. Switch banner image every day.
var bannerUrl = "<%- theme.jsDelivr.url %><%- url_for('/medias/banner/') %>" + new Date().getDay() + '.jpg';
$('.bg-cover').css('background-image', 'url(' + bannerUrl + ')');
</script>
<% } else { %>
<script>
$('.bg-cover').css('background-image', 'url(<%- theme.jsDelivr.url %><%- url_for('/medias/banner/0.jpg') %>)');
</script>
<script>
$('.bg-cover').css('background-image', 'url(<%- theme.jsDelivr.url %><%- url_for('/medias/banner/0.jpg') %>)');
</script>
<% } %>
2 changes: 1 addition & 1 deletion layout/_partial/head.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<head>
<meta charset="utf-8">
<meta name="keywords" content="<%= keyWords %>">
<meta name="description" content="<%= config.description %>">
<meta name="description" content="<%= description %>">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="renderer" content="webkit|ie-stand|ie-comp">
Expand Down