diff --git a/settings.yaml b/settings.yaml index f8686e4a..13ae8c59 100644 --- a/settings.yaml +++ b/settings.yaml @@ -684,28 +684,22 @@ spec: label: 爱发电赞助 value: powerLink: / - list: + url: https://api.afdian.cnkj.site/api/creator/get-top-sponsors?user_id= + userId: + showNum: 3 children: - $formkit: url name: powerLink label: 赞助地址 - - $formkit: repeater - name: list - label: 爱发电赞助列表 - value: [ ] - children: - - $formkit: attachment - name: avatar - label: 头像 - - $formkit: text - name: name - label: 名称 - - $formkit: url - name: link - label: 链接 - - $formkit: text - name: descr - label: 描述 + - $formkit: text + name: url + label: 接口地址 + - $formkit: text + name: userId + label: 用户ID + - $formkit: number + name: showNum + label: 最大展示条数 - $formkit: group name: welcome label: 小板报 diff --git a/templates/about.html b/templates/about.html index 8d54ef06..264551a1 100644 --- a/templates/about.html +++ b/templates/about.html @@ -1,6 +1,6 @@ + th:replace="~{modules/layouts/layout :: layout(content = ~{::content}, htmlType = 'about',title = ${${singlePage.spec.title} + ' | ' + site.title}, head = ~{::head})}"> - +
@@ -40,7 +40,7 @@ th:text="${authorTag.tag}">
-
关于本站
+
diff --git a/templates/assets/js/halo.js b/templates/assets/js/halo.js index b93e840f..e361ae6b 100644 --- a/templates/assets/js/halo.js +++ b/templates/assets/js/halo.js @@ -355,6 +355,64 @@ let halo = { changeMarginLeft(element) { var randomMargin = Math.floor(Math.random() * 901) + 100; // 生成100-1000之间的随机数 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 = ` +
+
+
+
${data[0].name}
+
更多支持,为爱发电
+
`; + } + + if (values.length > 1) { + var i = 0; + var htmlText = ''; + for (let value of values) { + if (i > parseInt(show_num)) { + break; + } + htmlText += ` ${value["name"]}`; + 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() } diff --git a/templates/assets/zhheo/blogex.js b/templates/assets/zhheo/blogex.js index 41989caf..aba8820f 100644 --- a/templates/assets/zhheo/blogex.js +++ b/templates/assets/zhheo/blogex.js @@ -597,7 +597,8 @@ function initBlog() { GLOBAL_CONFIG.loadingBox && heo.hideLoading(), heo.tagPageActive(), initObserver(), - checkUrlAndAddHideBanner() + checkUrlAndAddHideBanner(), + halo.getTopSponsors() } diff --git a/templates/modules/variables/site-config.html b/templates/modules/variables/site-config.html index 3a326815..f866c176 100644 --- a/templates/modules/variables/site-config.html +++ b/templates/modules/variables/site-config.html @@ -53,7 +53,9 @@ }, source: { 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: { linksUrl: [[${ theme.config.link.linksUrl }]], diff --git a/templates/modules/widgets/aside/power.html b/templates/modules/widgets/aside/power.html index c02cfbea..8a246bbd 100644 --- a/templates/modules/widgets/aside/power.html +++ b/templates/modules/widgets/aside/power.html @@ -1,30 +1,21 @@ -
+
爱发电赞助 赞助
- - -
-
-
-
[[${powerList[0].name}]]
-
[[${powerList[0].descr}]]
-
-
-
-
-
- + + + +
+
+
+
- +
-
+
\ No newline at end of file