summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormayx <mayx@outlook.com>2024-09-30 15:51:26 +0200
committermayx <mayx@outlook.com>2024-09-30 15:51:26 +0200
commit07a3d1835078730be5c6223a555c7c83c9306958 (patch)
tree3d3d30c0fabcaec4fb4123bf4b81fd98b2e7007b
parent550321e80acceb1d4b0bc442964014f80e1d88d3 (diff)
Update 3 files
- /js/main.js - /_layouts/post.html - /search.json
-rw-r--r--_layouts/post.html2
-rw-r--r--js/main.js89
-rw-r--r--search.json13
3 files changed, 56 insertions, 48 deletions
diff --git a/_layouts/post.html b/_layouts/post.html
index 358cede..c48fc2c 100644
--- a/_layouts/post.html
+++ b/_layouts/post.html
@@ -80,7 +80,7 @@ layout: default
{% if page.tags %}
<small>tags: <em>{{ page.tags | join: "</em> - <em>" }}</em></small>
{% endif %}
-
+<p id="suggest-container"><button onclick="getSuggestBlog('{{ page.url }}')">查看推荐文章</button></p>
<div class="pagination">
{% if page.previous.url %}
<span class="prev">
diff --git a/js/main.js b/js/main.js
index 5684316..88aab5d 100644
--- a/js/main.js
+++ b/js/main.js
@@ -1,45 +1,64 @@
-(function() {
+(function () {
var $backToTopTxt = "返回顶部", $backToTopEle = $('<div class="backToTop"></div>').appendTo($("body"))
- .text($backToTopTxt).attr("title", $backToTopTxt).click(function() {
+ .text($backToTopTxt).attr("title", $backToTopTxt).click(function () {
$("html, body").animate({ scrollTop: 0 }, 120);
- }), $backToTopFun = function() {
- var st = $(document).scrollTop(), winh = $(window).height();
- (st > 0)? $backToTopEle.show(): $backToTopEle.hide();
- };
+ }), $backToTopFun = function () {
+ var st = $(document).scrollTop(), winh = $(window).height();
+ (st > 0) ? $backToTopEle.show() : $backToTopEle.hide();
+ };
$(window).bind("scroll", $backToTopFun);
- $(function() { $backToTopFun(); });
+ $(function () { $backToTopFun(); });
})();
-$(function(){
- $("div#landlord").mouseenter(function(){
- $("div.live_ico_box").fadeIn();
- });
- $("div#landlord").mouseleave(function(){
- $("div.live_ico_box").fadeOut();
- });
-function showHitS(hits){
- $.get("https://summary.mayx.eu.org/count_click?id="+hits.id,function(data){
- hits.innerHTML=Number(data);
+$(function () {
+ $("div#landlord").mouseenter(function () {
+ $("div.live_ico_box").fadeIn();
+ });
+ $("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);
});
-}
-function showHitCount() {
- var visitors=$(".visitors-index");
- for(var i = 0; i < visitors.length; i++){
- showHitS(visitors[i]);
}
-
-}
-function addCount() {
-var visitors=$(".visitors");
- $.get("https://summary.mayx.eu.org/count_click_add?id="+visitors[0].id,function(data){
- visitors[0].innerHTML=Number(data);
+ function showHitCount() {
+ var visitors = $(".visitors-index");
+ for (var i = 0; i < visitors.length; i++) {
+ showHitS(visitors[i]);
+ }
+
+ }
+ function addCount() {
+ var visitors = $(".visitors");
+ $.get(BlogAPI + "/count_click_add?id=" + visitors[0].id, function (data) {
+ visitors[0].innerHTML = Number(data);
+ });
+ }
+ if ($('.visitors').length == 1) {
+ addCount();
+ } else if ($('.visitors-index').length > 0) {
+ showHitCount();
+ }
+});
+
+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;
+ });
+ merged.forEach(element => {
+ suggest.innerHTML += "<a href=" + element.url + ">" + element.title + "</a> - " + element.date + "<br />";
+ });
+ });
});
}
-if ($('.visitors').length == 1) {
- addCount();
-} else if ($('.visitors-index').length > 0){
- showHitCount();
-}
-});
today = new Date();
timeold = (today.getTime() - lastUpdated.getTime());
@@ -53,4 +72,4 @@ if (daysold > 90) {
}
var message_Path = '/Live2dHistoire/live2d/';
-var talkAPI = "https://summary.mayx.workers.dev/ai_chat";
+var talkAPI = BlogAPI + "/ai_chat";
diff --git a/search.json b/search.json
index 73c32f4..8ad4e54 100644
--- a/search.json
+++ b/search.json
@@ -1,14 +1,3 @@
---
---
-[
- {% for post in site.posts %}{% unless post.layout == "encrypt" %}
- {
- "title" : "{{ post.title | escape }}",
- "category" : "{{ post.category }}",
- "tags" : "{{ post.tags | join: ', ' }}",
- "url" : "{{ site.baseurl }}{{ post.url }}",
- "date" : "{{ post.date | date: "%Y/%m/%d" }}",
- "content": {{ post.content | strip_html | strip_newlines | jsonify }}
- }{% unless forloop.last %},{% endunless %}{% endunless %}
- {% endfor %}
-]
+[{% for post in site.posts %}{% unless post.layout == "encrypt" %}{ "title": "{{ post.title | escape }}", "category": "{{ post.category }}", "tags": "{{ post.tags | join: ', ' }}", "url": "{{ site.baseurl }}{{ post.url }}", "date": "{{ post.date | date: "%Y/%m/%d" }}", "content": {{ post.content | strip_html | strip_newlines | jsonify }} }{% unless forloop.last %},{% endunless %}{% endunless %}{% endfor %}]