summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormayx <mayx@outlook.com>2024-09-30 16:59:32 +0200
committermayx <mayx@outlook.com>2024-09-30 16:59:32 +0200
commit03d95172417ce5b1973dc72fd225bbfb9367462b (patch)
tree72e3df11b428532b518d367afce729deae55968c
parent9b9efd0f601b037f9fd0e90b969db9e2140d4a90 (diff)
Update 2 files
- /js/main.js - /_layouts/post.html
-rw-r--r--_layouts/post.html1
-rw-r--r--js/main.js14
2 files changed, 9 insertions, 6 deletions
diff --git a/_layouts/post.html b/_layouts/post.html
index 6cf9422..59835ee 100644
--- a/_layouts/post.html
+++ b/_layouts/post.html
@@ -81,6 +81,7 @@ layout: default
<small>tags: <em>{{ page.tags | join: "</em> - <em>" }}</em></small>
{% endif %}
<br />
+<br />
<p id="suggest-container"><button onclick="getSuggestBlog('{{ page.url }}')">查看推荐文章</button></p>
<div class="pagination">
{% if page.previous.url %}
diff --git a/js/main.js b/js/main.js
index 369db5c..4a15c46 100644
--- a/js/main.js
+++ b/js/main.js
@@ -46,20 +46,22 @@ function getSuggestBlog(blogurl) {
var suggest = $("#suggest-container")[0];
suggest.innerHTML = "Loading...";
$.get(BlogAPI + "/suggest?id=" + blogurl, function (data) {
- if (!data) {
- suggest.innerHTML = "暂无推荐文章……";
- } else {
+ if (data) {
getSearchJSON(function (search) {
- suggest.innerHTML = "<b>推荐文章</b><hr />";
+ suggest.innerHTML = '<b>推荐文章</b><hr style="margin: 0 0 5px"/>';
const searchMap = new Map(search.map(item => [item.url, item]));
const merged = data.map(suggestObj => {
const searchObj = searchMap.get(suggestObj.id);
- return searchObj ? { ...searchObj } : suggestObj;
+ return searchObj ? { ...searchObj } : null;
});
merged.forEach(element => {
- suggest.innerHTML += "<a href=" + element.url + ">" + element.title + "</a> - " + element.date + "<br />";
+ if (element) {
+ suggest.innerHTML += "<a href=" + element.url + ">" + element.title + "</a> - " + element.date + "<br />";
+ }
});
});
+ } else {
+ suggest.innerHTML = "暂无推荐文章……";
}
});
}