summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--_layouts/default.html2
-rw-r--r--_layouts/post.html1
-rw-r--r--js/main.js26
3 files changed, 17 insertions, 12 deletions
diff --git a/_layouts/default.html b/_layouts/default.html
index ff80871..509ef6a 100644
--- a/_layouts/default.html
+++ b/_layouts/default.html
@@ -31,7 +31,7 @@
var searchData = JSON.parse(localStorage.getItem(lastUpdated));
if (!searchData) {
localStorage.clear();
- $.getJSON("search.json", function (data) {
+ $.getJSON("/search.json", function (data) {
localStorage.setItem(lastUpdated, JSON.stringify(data));
callback(data);
});
diff --git a/_layouts/post.html b/_layouts/post.html
index c48fc2c..6cf9422 100644
--- a/_layouts/post.html
+++ b/_layouts/post.html
@@ -80,6 +80,7 @@ layout: default
{% if page.tags %}
<small>tags: <em>{{ page.tags | join: "</em> - <em>" }}</em></small>
{% endif %}
+<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 88aab5d..369db5c 100644
--- a/js/main.js
+++ b/js/main.js
@@ -1,3 +1,4 @@
+var BlogAPI = "https://summary.mayx.eu.org";
(function () {
var $backToTopTxt = "返回顶部", $backToTopEle = $('<div class="backToTop"></div>').appendTo($("body"))
.text($backToTopTxt).attr("title", $backToTopTxt).click(function () {
@@ -16,7 +17,6 @@ $(function () {
$("div#landlord").mouseleave(function () {
$("div.live_ico_box").fadeOut();
});
- var BlogAPI = "https://summary.mayx.eu.org";
function showHitS(hits) {
$.get(BlogAPI + "/count_click?id=" + hits.id, function (data) {
hits.innerHTML = Number(data);
@@ -46,17 +46,21 @@ function getSuggestBlog(blogurl) {
var suggest = $("#suggest-container")[0];
suggest.innerHTML = "Loading...";
$.get(BlogAPI + "/suggest?id=" + blogurl, function (data) {
- getSearchJSON(function (search) {
- suggest.innerHTML = "";
- 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;
+ if (!data) {
+ suggest.innerHTML = "暂无推荐文章……";
+ } else {
+ getSearchJSON(function (search) {
+ suggest.innerHTML = "<b>推荐文章</b><hr />";
+ 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;
+ });
+ merged.forEach(element => {
+ suggest.innerHTML += "<a href=" + element.url + ">" + element.title + "</a> - " + element.date + "<br />";
+ });
});
- merged.forEach(element => {
- suggest.innerHTML += "<a href=" + element.url + ">" + element.title + "</a> - " + element.date + "<br />";
- });
- });
+ }
});
}