summary refs log tree commit diff
path: root/_layouts/post.html
diff options
context:
space:
mode:
Diffstat (limited to '_layouts/post.html')
-rw-r--r--_layouts/post.html26
1 files changed, 25 insertions, 1 deletions
diff --git a/_layouts/post.html b/_layouts/post.html
index 59835ee..2ad1fdd 100644
--- a/_layouts/post.html
+++ b/_layouts/post.html
@@ -82,7 +82,31 @@ layout: default
 {% endif %}
 <br />
 <br />
-<p id="suggest-container"><button onclick="getSuggestBlog('{{ page.url }}')">查看推荐文章</button></p>
+<p id="suggest-container"></p>
+<script>
+var blogurl = "{{ page.url }}";
+var suggest = $("#suggest-container")[0];
+suggest.innerHTML = "Loading...";
+$.get(BlogAPI + "/suggest?id=" + blogurl + "&update=" + lastUpdated.valueOf(), function (data) {
+    if (data.length) {
+        getSearchJSON(function (search) {
+            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 } : null;
+            });
+            merged.forEach(element => {
+                if (element) {
+                    suggest.innerHTML += "<a href=" + element.url + ">" + element.title + "</a> - " + element.date + "<br />";
+                }
+            });
+        });
+    } else {
+        suggest.innerHTML = "暂无推荐文章……";
+    }
+});
+</script>
 <div class="pagination">
   {% if page.previous.url %}
   <span class="prev">