summaryrefslogtreecommitdiff
path: root/_layouts
diff options
context:
space:
mode:
authormayx <mayx@outlook.com>2024-10-04 08:19:24 +0200
committermayx <mayx@outlook.com>2024-10-04 08:19:24 +0200
commit443d65ac50137666963a3c6b7445c4d40253a8c0 (patch)
tree9ba839465fc042876ccf8de646d4986ad8932ba6 /_layouts
parentc8ce8de1d9b36899e19ca16c9095f1c2ff19d893 (diff)
Update 4 files
- /_layouts/default.html - /_layouts/post.html - /js/main.js - /_posts/2024-10-01-suggest.md
Diffstat (limited to '_layouts')
-rw-r--r--_layouts/default.html4
-rw-r--r--_layouts/post.html26
2 files changed, 27 insertions, 3 deletions
diff --git a/_layouts/default.html b/_layouts/default.html
index 509ef6a..20595ac 100644
--- a/_layouts/default.html
+++ b/_layouts/default.html
@@ -28,11 +28,11 @@
gtag('config', '{{ site.google_analytics }}');
var lastUpdated = new Date("{{ site.time | date: "%FT%T%z" }}");
function getSearchJSON(callback) {
- var searchData = JSON.parse(localStorage.getItem(lastUpdated));
+ var searchData = JSON.parse(localStorage.getItem("blog_" + lastUpdated.valueOf()));
if (!searchData) {
localStorage.clear();
$.getJSON("/search.json", function (data) {
- localStorage.setItem(lastUpdated, JSON.stringify(data));
+ localStorage.setItem("blog_" + lastUpdated.valueOf(), JSON.stringify(data));
callback(data);
});
} else {
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">