Merge pull request #570 from chengzhongxue/main

爱发电赞助改成api形式
This commit is contained in:
困困鱼 2023-12-19 23:05:54 +08:00 committed by GitHub
commit dc4ce58c31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 89 additions and 43 deletions

View File

@ -684,28 +684,22 @@ spec:
label: 爱发电赞助 label: 爱发电赞助
value: value:
powerLink: / powerLink: /
list: url: https://api.afdian.cnkj.site/api/creator/get-top-sponsors?user_id=
userId:
showNum: 3
children: children:
- $formkit: url - $formkit: url
name: powerLink name: powerLink
label: 赞助地址 label: 赞助地址
- $formkit: repeater
name: list
label: 爱发电赞助列表
value: [ ]
children:
- $formkit: attachment
name: avatar
label: 头像
- $formkit: text - $formkit: text
name: name name: url
label: 名称 label: 接口地址
- $formkit: url
name: link
label: 链接
- $formkit: text - $formkit: text
name: descr name: userId
label: 描述 label: 用户ID
- $formkit: number
name: showNum
label: 最大展示条数
- $formkit: group - $formkit: group
name: welcome name: welcome
label: 小板报 label: 小板报

View File

@ -1,6 +1,6 @@
<!DOCTYPE html> <!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" <html xmlns:th="http://www.thymeleaf.org"
th:replace="~{modules/layouts/layout :: layout(content = ~{::content}, htmlType = 'about',title = ${'关于' + ' | ' + site.title}, head = ~{::head})}"> th:replace="~{modules/layouts/layout :: layout(content = ~{::content}, htmlType = 'about',title = ${${singlePage.spec.title} + ' | ' + site.title}, head = ~{::head})}">
<th:block th:fragment="head"> <th:block th:fragment="head">
<th:block th:replace="~{modules/common/open-graph :: open-graph(_title = ${singlePage.spec.title}, <th:block th:replace="~{modules/common/open-graph :: open-graph(_title = ${singlePage.spec.title},
_permalink = ${singlePage.status.permalink}, _permalink = ${singlePage.status.permalink},
@ -14,7 +14,7 @@
<!-- 头部导航栏 --> <!-- 头部导航栏 -->
<header class="not-top-img" id="page-header"> <header class="not-top-img" id="page-header">
<nav th:replace="~{modules/nav :: nav(title = '关于')}"></nav> <nav th:replace="~{modules/nav :: nav(title = ${singlePage.spec.title})}"></nav>
</header> </header>
<main class="layout hide-aside" id="content-inner"> <main class="layout hide-aside" id="content-inner">
<div id="page"> <div id="page">
@ -40,7 +40,7 @@
th:text="${authorTag.tag}"></span> th:text="${authorTag.tag}"></span>
</div> </div>
</div> </div>
<div class="author-title">关于本站</div> <div class="author-title" th:text="${singlePage.spec.title}"></div>
<th:block th:replace="~{modules/about-widgets :: about-widgets(${theme.config.about.widgetList})}"></th:block> <th:block th:replace="~{modules/about-widgets :: about-widgets(${theme.config.about.widgetList})}"></th:block>

View File

@ -355,6 +355,64 @@ let halo = {
changeMarginLeft(element) { changeMarginLeft(element) {
var randomMargin = Math.floor(Math.random() * 901) + 100; // 生成100-1000之间的随机数 var randomMargin = Math.floor(Math.random() * 901) + 100; // 生成100-1000之间的随机数
element.style.marginLeft = randomMargin + 'px'; element.style.marginLeft = randomMargin + 'px';
},
getTopSponsors() {
var user_id = GLOBAL_CONFIG.source.power.userId
var show_num = GLOBAL_CONFIG.source.power.showNum
function getPower() {
const url = GLOBAL_CONFIG.source.power.url + user_id
fetch(url)
.then(res => res.json())
.then(data => {
if (200 === data["ec"]) {
var values = data["data"]["list"]
saveToLocal.set('power-data', JSON.stringify(values), 10 / (60 * 24))
renderer(values);
}
})
}
function renderer(values){
var data = getArrayItems(values, 1);
let powerStar = document.getElementById("power-star")
if (powerStar) {
powerStar.href = "https://afdian.net/u/" + data[0].user_id
powerStar.innerHTML = `
<div id="power-star-image" style="background-image: url(${data[0].avatar})">
</div>
<div class="power-star-body">
<div id="power-star-title">${data[0].name}</div>
<div id="power-star-desc">更多支持为爱发电</div>
</div>`;
}
if (values.length > 1) {
var i = 0;
var htmlText = '';
for (let value of values) {
if (i > parseInt(show_num)) {
break;
}
htmlText += ` <a href="${"https://afdian.net/u/" + value["user_id"]}" rel="external nofollow" target="_blank" th:title="${value["name"]}">${value["name"]}</a>`;
i = i + 1;
}
if (document.getElementById("power-item-link")) {
document.getElementById("power-item-link").innerHTML = htmlText;
}
}
}
function init(){
const data = saveToLocal.get('power-data')
if (data) {
renderer(JSON.parse(data))
} else {
getPower()
}
}
document.getElementById("power-star") && init()
} }

View File

@ -597,7 +597,8 @@ function initBlog() {
GLOBAL_CONFIG.loadingBox && heo.hideLoading(), GLOBAL_CONFIG.loadingBox && heo.hideLoading(),
heo.tagPageActive(), heo.tagPageActive(),
initObserver(), initObserver(),
checkUrlAndAddHideBanner() checkUrlAndAddHideBanner(),
halo.getTopSponsors()
} }

View File

@ -53,7 +53,9 @@
}, },
source: { source: {
power:{ power:{
list:[[${theme.config.sidebar.power.list}]] url:[[${theme.config.sidebar.power.url}]],
userId:[[${theme.config.sidebar.power.userId}]],
showNum:[[${theme.config.sidebar.power.showNum}]]
}, },
links: { links: {
linksUrl: [[${ theme.config.link.linksUrl }]], linksUrl: [[${ theme.config.link.linksUrl }]],

View File

@ -5,26 +5,17 @@
<a class="power-charge" th:href="${theme.config.sidebar.power.powerLink}" target="_blank" title="赞助博主">赞助 <a class="power-charge" th:href="${theme.config.sidebar.power.powerLink}" target="_blank" title="赞助博主">赞助
</a> </a>
</div> </div>
<th:block th:if="${not #lists.isEmpty(theme.config.sidebar.power.list)}" th:with="powerList = ${theme.config.sidebar.power.list}"> <a id="power-star" rel="external nofollow" target="_blank" title="推荐博主">
<a id="power-star"
th:href="${powerList[0].link}" rel="external nofollow" target="_blank" title="推荐博主">
<div id="power-star-image"
th:style="'background-image: url('+${powerList[0].avatar}+')'">
</div>
<div class="power-star-body">
<div id="power-star-title">[[${powerList[0].name}]]</div>
<div id="power-star-desc">[[${powerList[0].descr}]]</div>
</div>
</a> </a>
<div class="power-list"> <div class="power-list">
<div class="power-item"> <div class="power-item">
<div class="power-item-body"> <div class="power-item-body">
<div class="power-item-link" th:each="power : ${powerList}"> <div class="power-item-link" id="power-item-link">
<a th:href="${power.link}" rel="external nofollow" target="_blank" th:title="${power.name}">[[${power.name}]]</a>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</th:block>
</div> </div>
</div> </div>