From 5931bf378628536ff1ead72708601d500b2e1960 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Wed, 18 Dec 2024 16:39:39 +0800 Subject: [PATCH 1/9] :tada: Feat: add PostChat AI support --- hugo.toml | 47 +++++++++++ layouts/partials/single/post-chat-ai.html | 98 +++++++++++++++++++++++ layouts/posts/single.html | 3 + 3 files changed, 148 insertions(+) create mode 100644 layouts/partials/single/post-chat-ai.html diff --git a/hugo.toml b/hugo.toml index 44253f36..7ca32762 100644 --- a/hugo.toml +++ b/hugo.toml @@ -886,6 +886,53 @@ enableEmoji = true # "corner-indicator", "fill-left", "flash", "flat-top", "loading-bar", "mac-osx", "material", "minimal"] theme = "minimal" + # FixIt 0.3.17 | NEW PostChat AI config + # Summary AI, knowledge base search and knowledge base dialogue support + # Docs: https://postchat.zhheo.com/ + [params.postChat] + enable = false + # Get PostChat Key from my invitation link, thanks for your support! + # https://ai.tianli0.top/?InviteID=IRE1S88Z + key = "ed872bf9336506bea545183089f5034f81fea6af" + # How users initiate chats: ["iframe", "magic"] + userMode = "magic" + addButton = true + defaultInput = false + left = "" + bottom = "" + width = "" + height = "" + fill = "" + backgroundColor = "" + upLoadWeb = true + showInviteLink = true + userTitle = "" + userDesc = "" + # dom container to be blacked out, e.g. [".aplayer"] + blackDom = [] + # Only for iframe mode + frameWidth = "" # e.g. "375px" + frameHeight = "" # e.g. "600px" + # only for magic mode + userIcon = "" + defaultChatQuestions = [] + defaultSearchQuestions = [] + + # FixIt 0.3.17 | NEW Summary AI config + # See https://postchat.zhheo.com/summary.html + [params.postSummary] + enable = false + # If you set `params.postChat.key`, you don't need to set `params.postSummary.key` + key = "" + title = "" + # themes options: ["", "simple", "yanzhi"] + theme = "" + postURL = "" + blacklist = "" + wordLimit = 1000 + typingAnimate = true + beginningText = "" + # FixIt 0.3.10 | NEW Global Feed config for RSS, Atom and JSON feed. [params.feed] # The number of posts to include in the feed. If set to -1, all posts. diff --git a/layouts/partials/single/post-chat-ai.html b/layouts/partials/single/post-chat-ai.html new file mode 100644 index 00000000..0af3e36a --- /dev/null +++ b/layouts/partials/single/post-chat-ai.html @@ -0,0 +1,98 @@ +{{- /* + PostChat AI service for single page. (Only for type "posts") + PostChat: https://postchat.zhheo.com/addCode.html + PostSummary: https://postchat.zhheo.com/summary.html +*/ -}} +{{- $chatConfig := .Param "postChat" -}} +{{- $summaryConfig := .Param "postSummary" -}} +{{- $enable := $chatConfig.enable | or $summaryConfig.enable -}} +{{- $key := $chatConfig.key | default $summaryConfig.key -}} +{{- $sourcePrefix := "https://ai.tianli0.top/static/public/" -}} +{{- $jsMap := dict + "chat" "postChatUser.min.js" + "summary" "tianli_gpt.min.js" + "both" "postChatUser_summary.min.js" +-}} + +{{- if $enable | and $key -}} + {{- $configJS := "" -}} + {{- $fingerprint := .Scratch.Get "fingerprint" -}} + {{- $sourceOpts := dict "Fingerprint" $fingerprint "Defer" true -}} + + {{- /* PostSummary */ -}} + {{- if $summaryConfig.enable -}} + {{- $postChatCSS := "https://ai.tianli0.top/static/public/postChatUser_summary.min.css" -}} + {{- dict "Source" $postChatCSS "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/style.html" -}} + {{- $p := "tianliGPT" -}} + {{- $postSummaryConfig := printf "let %v_postSelector='#content';" $p -}} + {{- with $summaryConfig.title -}} + {{- $postSummaryConfig = add $postSummaryConfig (printf "let %v_Title='%v';" $p .) -}} + {{- end -}} + {{- with $summaryConfig.theme -}} + {{- $postSummaryConfig = add $postSummaryConfig (printf "let %v_theme='%v';" $p .) -}} + {{- end -}} + {{- with $summaryConfig.postURL -}} + {{- $postSummaryConfig = add $postSummaryConfig (printf "let %v_postURL='%v';" $p .) -}} + {{- end -}} + {{- with $summaryConfig.blacklist -}} + {{- $postSummaryConfig = add $postSummaryConfig (printf "let %v_blacklist='%v';" $p .) -}} + {{- end -}} + {{- with $summaryConfig.wordLimit -}} + {{- $postSummaryConfig = add $postSummaryConfig (printf "let %v_wordLimit='%v';" $p .) -}} + {{- end -}} + {{- if eq $summaryConfig.typingAnimate false -}} + {{- $postSummaryConfig = add $postSummaryConfig (printf "let %v_typingAnimate=false;" $p) -}} + {{- end -}} + {{- with $summaryConfig.beginningText -}} + {{- $postSummaryConfig = add $postSummaryConfig (printf "let %v_BeginningText='%v';" $p .) -}} + {{- end -}} + {{- if $chatConfig.enable -}} + {{- $postSummaryConfig = add $postSummaryConfig (printf "let %v_recommendation=true;" $p) -}} + {{- else -}} + {{- $postSummaryConfig = add $postSummaryConfig (printf "let %v_key='%v';" $p $key) -}} + {{- end -}} + {{- $configJS = add $configJS $postSummaryConfig -}} + {{- end -}} + + {{- /* PostChat */ -}} + {{- if $chatConfig.enable -}} + {{- $sourceOpts = dict "Attr" (printf "data-postChat_key=%q" $key) | merge $sourceOpts -}} + {{- $postChatConfig := dict + "userMode" $chatConfig.userMode + "defaultInput" $chatConfig.defaultInput + "left" $chatConfig.left + "bottom" $chatConfig.bottom + "width" $chatConfig.width + "height" $chatConfig.height + "fill" $chatConfig.fill + "backgroundColor" $chatConfig.backgroundColor + "upLoadWeb" $chatConfig.upLoadWeb + "showInviteLink" $chatConfig.showInviteLink + "userTitle" $chatConfig.userTitle + "userDesc" $chatConfig.userDesc + "addButton" $chatConfig.addButton + "blackDom" $chatConfig.blackDom + "frameWidth" $chatConfig.frameWidth + "frameHeight" $chatConfig.frameHeight + "userIcon" $chatConfig.userIcon + "defaultChatQuestions" $chatConfig.defaultChatQuestions + "defaultSearchQuestions" $chatConfig.defaultSearchQuestions + -}} + {{- $configJS = add $configJS ($postChatConfig | jsonify | printf "var postChatConfig=%s") -}} + {{- end -}} + + {{- /* Insert config */ -}} + {{- $configJS | dict "Content" | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} + + {{- /* Insert script */ -}} + {{- $postChatJS := "" -}} + {{- if $chatConfig.enable | and $summaryConfig.enable -}} + {{- $postChatJS = add $sourcePrefix (index $jsMap "both") -}} + {{- else if $chatConfig.enable -}} + {{- $postChatJS = add $sourcePrefix (index $jsMap "chat") -}} + {{- else if $summaryConfig.enable -}} + {{- $postChatJS = add $sourcePrefix (index $jsMap "summary") -}} + {{- end -}} + {{- $sourceOpts = dict "Source" $postChatJS | merge $sourceOpts -}} + {{- $sourceOpts | dict "Scratch" $.Scratch "Data" | partial "scratch/script.html" -}} +{{- end -}} diff --git a/layouts/posts/single.html b/layouts/posts/single.html index b2592a39..f06cbeb0 100644 --- a/layouts/posts/single.html +++ b/layouts/posts/single.html @@ -166,6 +166,9 @@ {{- /* Expiration Reminder */ -}} {{- partial "single/expiration-reminder.html" . -}} {{- $content -}} + + {{- /* PostChat */ -}} + {{- partial "single/post-chat-ai.html" . -}} {{- end -}} From 1d0929778488562da5d482b1ae25395b30733251 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Wed, 18 Dec 2024 17:17:12 +0800 Subject: [PATCH 2/9] :zap: Perf: add embed blockDoms for PostChat only --- layouts/partials/single/expiration-reminder.html | 2 +- layouts/partials/single/post-chat-ai.html | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/layouts/partials/single/expiration-reminder.html b/layouts/partials/single/expiration-reminder.html index 45367302..97a89eb7 100644 --- a/layouts/partials/single/expiration-reminder.html +++ b/layouts/partials/single/expiration-reminder.html @@ -14,7 +14,7 @@ {{- $type = "warning" -}} {{- $icon = "fa-exclamation-triangle" -}} {{- end -}} -
+
{{ T (printf "admonition.%v" $type) }}
diff --git a/layouts/partials/single/post-chat-ai.html b/layouts/partials/single/post-chat-ai.html index 0af3e36a..807b00e3 100644 --- a/layouts/partials/single/post-chat-ai.html +++ b/layouts/partials/single/post-chat-ai.html @@ -57,6 +57,14 @@ {{- /* PostChat */ -}} {{- if $chatConfig.enable -}} {{- $sourceOpts = dict "Attr" (printf "data-postChat_key=%q" $key) | merge $sourceOpts -}} + {{- $blackDom := slice + ".expiration-reminder" + "meting-js" + -}} + {{/* 合并 $blackDom 和 $chatConfig.blackDom */}} + {{- with $chatConfig.blackDom -}} + {{- $blackDom = $blackDom | append . -}} + {{- end -}} {{- $postChatConfig := dict "userMode" $chatConfig.userMode "defaultInput" $chatConfig.defaultInput @@ -71,7 +79,7 @@ "userTitle" $chatConfig.userTitle "userDesc" $chatConfig.userDesc "addButton" $chatConfig.addButton - "blackDom" $chatConfig.blackDom + "blackDom" $blackDom "frameWidth" $chatConfig.frameWidth "frameHeight" $chatConfig.frameHeight "userIcon" $chatConfig.userIcon From 041d5e2517fddc3c902630ee1f86a5ee6188212b Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Wed, 18 Dec 2024 17:56:42 +0800 Subject: [PATCH 3/9] :zap: Perf: PostChat support all types page and PostSummary only for public posts --- layouts/partials/assets.html | 3 +++ .../partials/{single => plugin}/post-chat-ai.html | 15 ++++++++++----- layouts/posts/single.html | 3 --- 3 files changed, 13 insertions(+), 8 deletions(-) rename layouts/partials/{single => plugin}/post-chat-ai.html (90%) diff --git a/layouts/partials/assets.html b/layouts/partials/assets.html index 03df5c2c..0b0b2304 100644 --- a/layouts/partials/assets.html +++ b/layouts/partials/assets.html @@ -265,6 +265,9 @@ {{- end -}} {{- end -}} +{{- /* PostChat */ -}} +{{- partial "plugin/post-chat-ai.html" . -}} + {{- range $params.library.css -}} {{- dict "Source" . "Fingerprint" $fingerprint | dict "Scratch" $.Scratch "Data" | partial "scratch/style.html" -}} {{- end -}} diff --git a/layouts/partials/single/post-chat-ai.html b/layouts/partials/plugin/post-chat-ai.html similarity index 90% rename from layouts/partials/single/post-chat-ai.html rename to layouts/partials/plugin/post-chat-ai.html index 807b00e3..9e4b6ef3 100644 --- a/layouts/partials/single/post-chat-ai.html +++ b/layouts/partials/plugin/post-chat-ai.html @@ -1,11 +1,12 @@ {{- /* - PostChat AI service for single page. (Only for type "posts") + PostChat AI service. PostChat: https://postchat.zhheo.com/addCode.html PostSummary: https://postchat.zhheo.com/summary.html + TODO dark/light mode switch */ -}} +{{- $params := partial "function/params.html" -}} {{- $chatConfig := .Param "postChat" -}} {{- $summaryConfig := .Param "postSummary" -}} -{{- $enable := $chatConfig.enable | or $summaryConfig.enable -}} {{- $key := $chatConfig.key | default $summaryConfig.key -}} {{- $sourcePrefix := "https://ai.tianli0.top/static/public/" -}} {{- $jsMap := dict @@ -13,6 +14,10 @@ "summary" "tianli_gpt.min.js" "both" "postChatUser_summary.min.js" -}} +{{- /* PostSummary only for public posts */ -}} +{{- $isPost := (eq .Kind "page") | and (eq .Type "posts") | and (not $params.password) -}} +{{- $summaryEnable := cond $isPost $summaryConfig.enable false -}} +{{- $enable := $chatConfig.enable | or $summaryEnable -}} {{- if $enable | and $key -}} {{- $configJS := "" -}} @@ -20,7 +25,7 @@ {{- $sourceOpts := dict "Fingerprint" $fingerprint "Defer" true -}} {{- /* PostSummary */ -}} - {{- if $summaryConfig.enable -}} + {{- if $summaryEnable -}} {{- $postChatCSS := "https://ai.tianli0.top/static/public/postChatUser_summary.min.css" -}} {{- dict "Source" $postChatCSS "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/style.html" -}} {{- $p := "tianliGPT" -}} @@ -94,11 +99,11 @@ {{- /* Insert script */ -}} {{- $postChatJS := "" -}} - {{- if $chatConfig.enable | and $summaryConfig.enable -}} + {{- if $chatConfig.enable | and $summaryEnable -}} {{- $postChatJS = add $sourcePrefix (index $jsMap "both") -}} {{- else if $chatConfig.enable -}} {{- $postChatJS = add $sourcePrefix (index $jsMap "chat") -}} - {{- else if $summaryConfig.enable -}} + {{- else if $summaryEnable -}} {{- $postChatJS = add $sourcePrefix (index $jsMap "summary") -}} {{- end -}} {{- $sourceOpts = dict "Source" $postChatJS | merge $sourceOpts -}} diff --git a/layouts/posts/single.html b/layouts/posts/single.html index f06cbeb0..b2592a39 100644 --- a/layouts/posts/single.html +++ b/layouts/posts/single.html @@ -166,9 +166,6 @@ {{- /* Expiration Reminder */ -}} {{- partial "single/expiration-reminder.html" . -}} {{- $content -}} - - {{- /* PostChat */ -}} - {{- partial "single/post-chat-ai.html" . -}} {{- end -}}
From 91f3ad7471e4182927b136c56de7b7365b4874a3 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Wed, 18 Dec 2024 20:58:42 +0800 Subject: [PATCH 4/9] :bug: Fix(ignore): PostChat and PostSummary config merge error --- layouts/partials/plugin/post-chat-ai.html | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/layouts/partials/plugin/post-chat-ai.html b/layouts/partials/plugin/post-chat-ai.html index 9e4b6ef3..35cfbb21 100644 --- a/layouts/partials/plugin/post-chat-ai.html +++ b/layouts/partials/plugin/post-chat-ai.html @@ -5,8 +5,14 @@ TODO dark/light mode switch */ -}} {{- $params := partial "function/params.html" -}} -{{- $chatConfig := .Param "postChat" -}} -{{- $summaryConfig := .Param "postSummary" -}} +{{- $chatConfig := .Site.Params.postChat -}} +{{- $summaryConfig := .Site.Params.postSummary -}} +{{- with .Params.postChat -}} + {{- $chatConfig = . | merge .Site.Params.postChat -}} +{{- end -}} +{{- with .Params.postSummary -}} + {{- $summaryConfig = . | merge .Site.Params.postSummary -}} +{{- end -}} {{- $key := $chatConfig.key | default $summaryConfig.key -}} {{- $sourcePrefix := "https://ai.tianli0.top/static/public/" -}} {{- $jsMap := dict @@ -65,8 +71,8 @@ {{- $blackDom := slice ".expiration-reminder" "meting-js" + ".lnt" -}} - {{/* 合并 $blackDom 和 $chatConfig.blackDom */}} {{- with $chatConfig.blackDom -}} {{- $blackDom = $blackDom | append . -}} {{- end -}} @@ -79,7 +85,7 @@ "height" $chatConfig.height "fill" $chatConfig.fill "backgroundColor" $chatConfig.backgroundColor - "upLoadWeb" $chatConfig.upLoadWeb + "upLoadWeb" (cond .IsHome false $chatConfig.upLoadWeb) "showInviteLink" $chatConfig.showInviteLink "userTitle" $chatConfig.userTitle "userDesc" $chatConfig.userDesc From e2eeaf96321406daac00b9b6db5a2c833a691ad4 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Wed, 18 Dec 2024 21:25:17 +0800 Subject: [PATCH 5/9] :memo: Docs(ignore): update todo list --- layouts/partials/plugin/post-chat-ai.html | 1 + 1 file changed, 1 insertion(+) diff --git a/layouts/partials/plugin/post-chat-ai.html b/layouts/partials/plugin/post-chat-ai.html index 35cfbb21..5afdb637 100644 --- a/layouts/partials/plugin/post-chat-ai.html +++ b/layouts/partials/plugin/post-chat-ai.html @@ -3,6 +3,7 @@ PostChat: https://postchat.zhheo.com/addCode.html PostSummary: https://postchat.zhheo.com/summary.html TODO dark/light mode switch + TODO chat API development */ -}} {{- $params := partial "function/params.html" -}} {{- $chatConfig := .Site.Params.postChat -}} From 68b028e9b64b70a9675e5d7c623537ec66f29355 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Thu, 19 Dec 2024 10:05:48 +0800 Subject: [PATCH 6/9] :bug: Fix(ignore): private posts disable upLoadWeb always --- layouts/partials/plugin/post-chat-ai.html | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/layouts/partials/plugin/post-chat-ai.html b/layouts/partials/plugin/post-chat-ai.html index 5afdb637..0ef13076 100644 --- a/layouts/partials/plugin/post-chat-ai.html +++ b/layouts/partials/plugin/post-chat-ai.html @@ -5,15 +5,9 @@ TODO dark/light mode switch TODO chat API development */ -}} -{{- $params := partial "function/params.html" -}} -{{- $chatConfig := .Site.Params.postChat -}} -{{- $summaryConfig := .Site.Params.postSummary -}} -{{- with .Params.postChat -}} - {{- $chatConfig = . | merge .Site.Params.postChat -}} -{{- end -}} -{{- with .Params.postSummary -}} - {{- $summaryConfig = . | merge .Site.Params.postSummary -}} -{{- end -}} +{{- $params := .Params | merge .Site.Params -}} +{{- $chatConfig := $params.postChat -}} +{{- $summaryConfig := $params.postSummary -}} {{- $key := $chatConfig.key | default $summaryConfig.key -}} {{- $sourcePrefix := "https://ai.tianli0.top/static/public/" -}} {{- $jsMap := dict @@ -22,7 +16,8 @@ "both" "postChatUser_summary.min.js" -}} {{- /* PostSummary only for public posts */ -}} -{{- $isPost := (eq .Kind "page") | and (eq .Type "posts") | and (not $params.password) -}} +{{- $password := .Params.password | default .Site.Params.page.password -}} +{{- $isPost := (eq .Kind "page") | and (eq .Type "posts") | and (not $password) -}} {{- $summaryEnable := cond $isPost $summaryConfig.enable false -}} {{- $enable := $chatConfig.enable | or $summaryEnable -}} @@ -77,6 +72,7 @@ {{- with $chatConfig.blackDom -}} {{- $blackDom = $blackDom | append . -}} {{- end -}} + {{- $upLoadWeb := cond (.IsHome | or $password) false $chatConfig.upLoadWeb -}} {{- $postChatConfig := dict "userMode" $chatConfig.userMode "defaultInput" $chatConfig.defaultInput @@ -86,7 +82,7 @@ "height" $chatConfig.height "fill" $chatConfig.fill "backgroundColor" $chatConfig.backgroundColor - "upLoadWeb" (cond .IsHome false $chatConfig.upLoadWeb) + "upLoadWeb" $upLoadWeb "showInviteLink" $chatConfig.showInviteLink "userTitle" $chatConfig.userTitle "userDesc" $chatConfig.userDesc From fcd72c9d661aa138bf27b26cd4d4937eceb2b5fc Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Thu, 19 Dec 2024 10:59:55 +0800 Subject: [PATCH 7/9] :zap: Perf(postChat): auto switch dark/light theme mode --- assets/js/theme.js | 17 +++++++++++++++++ layouts/partials/plugin/post-chat-ai.html | 1 - 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/assets/js/theme.js b/assets/js/theme.js index fb33748b..eca93e9d 100644 --- a/assets/js/theme.js +++ b/assets/js/theme.js @@ -1130,6 +1130,22 @@ class FixIt { this.scrollEventSet.add(_closeRewardExclude); } + initPostChatUser() { + window.postChat_mode = postChatConfig.userMode || 'iframe'; + if (window.postChat_mode !== 'iframe' || !window.postChatUser) { + return; + } + postChat_theme = this.isDark ? 'dark' : 'light'; + this.switchThemeEventSet.add((isDark) => { + const targetFrame = document.getElementById("postChat_iframeContainer") + if (targetFrame) { + window.postChatUser.setPostChatTheme(isDark ? 'dark' : 'light'); + } else { + postChat_theme = isDark ? 'dark' : 'light'; + } + }); + } + onScroll() { const $headers = []; const ACCURACY = 20; @@ -1269,6 +1285,7 @@ class FixIt { this.initWatermark(); this.initAutoMark(); this.initReward(); + this.initPostChatUser(); window.setTimeout(() => { this.initComment(); diff --git a/layouts/partials/plugin/post-chat-ai.html b/layouts/partials/plugin/post-chat-ai.html index 0ef13076..252c2e18 100644 --- a/layouts/partials/plugin/post-chat-ai.html +++ b/layouts/partials/plugin/post-chat-ai.html @@ -2,7 +2,6 @@ PostChat AI service. PostChat: https://postchat.zhheo.com/addCode.html PostSummary: https://postchat.zhheo.com/summary.html - TODO dark/light mode switch TODO chat API development */ -}} {{- $params := .Params | merge .Site.Params -}} From 3e210af76a9da8de58391ce248744a9473a077a0 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Thu, 19 Dec 2024 12:22:48 +0800 Subject: [PATCH 8/9] :sparkles: Feat: add post-chat search engine powered by PostChat --- README.md | 3 ++- README.zh-cn.md | 3 ++- assets/js/theme.js | 19 ++++++++++++++++++- hugo.toml | 9 ++++----- layouts/partials/assets.html | 4 +++- 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index aeb2cb15..57eb970d 100644 --- a/README.md +++ b/README.md @@ -117,8 +117,9 @@ I don't know why 🤷 - **Sub Menu** supported - **Content Encryption** supported (Pages, Partial) - **Friends** page embedded template -- **Search** supported by [algolia](https://www.algolia.com/), [Fuse.js](https://fusejs.io/) or CSE +- **Search** supported by [algolia](https://www.algolia.com/), [Fuse.js](https://fusejs.io/)、 CSE or [PostChat](https://ai.tianli0.top/?InviteID=IRE1S88Z) - **Custom Search Engine (CSE)** supported by [Google](https://programmablesearchengine.google.com/) +- **AI Summary**、**AI Search** and **AI Chatbot** supported by [PostChat](https://ai.tianli0.top/?InviteID=IRE1S88Z) - **Twemoji** supported - Automatically **highlighting** code - **Copy code** to clipboard with one click diff --git a/README.zh-cn.md b/README.zh-cn.md index c22eeefd..bbf27ed6 100644 --- a/README.zh-cn.md +++ b/README.zh-cn.md @@ -117,8 +117,9 @@ - 支持**二级菜单** - 支持**内容加密**(页面、局部) - 支持**友情链接**的页面模板 -- 支持基于 [algolia](https://www.algolia.com/)、[Fuse.js](https://fusejs.io/) 或 **CSE** 的**搜索** +- 支持基于 [algolia](https://www.algolia.com/)、[Fuse.js](https://fusejs.io/)、 **CSE** 或 [PostChat](https://ai.tianli0.top/?InviteID=IRE1S88Z) 的**搜索** - 支持基于 [Google](https://programmablesearchengine.google.com/) 的**自定义搜索引擎 (CSE)** +- 支持基于 [PostChat](https://ai.tianli0.top/?InviteID=IRE1S88Z) 的 **AI 摘要**、**AI 搜索** 和 **AI 智能客服** - 支持 **Twemoji** - 支持**代码高亮** - 一键**复制代码**到剪贴板 diff --git a/assets/js/theme.js b/assets/js/theme.js index eca93e9d..da77d085 100644 --- a/assets/js/theme.js +++ b/assets/js/theme.js @@ -124,6 +124,21 @@ class FixIt { const $searchToggle = document.getElementById(`search-toggle-${suffix}`); const $searchLoading = document.getElementById(`search-loading-${suffix}`); const $searchClear = document.getElementById(`search-clear-${suffix}`); + const $searchCancel = document.getElementById('search-cancel-mobile'); + + // goto the PostChat panel rather than search results + if (searchConfig.type === 'post-chat' && window.postChatUser) { + if (isMobile) { + $searchInput.addEventListener('focus', () => { + window.postChatUser.setSearchInput(''); + }, false); + } else { + $searchToggle.addEventListener('click', () => { + window.postChatUser.setSearchInput(''); + }, false); + } + return; + } if (isMobile) { this._searchMobileOnce = true; @@ -132,7 +147,7 @@ class FixIt { document.body.classList.add('blur'); $header.classList.add('open'); }, false); - document.getElementById('search-cancel-mobile').addEventListener('click', () => { + $searchCancel.addEventListener('click', () => { this.disableScrollEvent = false; $header.classList.remove('open'); document.body.classList.remove('blur'); @@ -301,6 +316,8 @@ class FixIt { context: cseConfig.gotoResultsPage }]); } + } else { + finish([]); } }, templates: { diff --git a/hugo.toml b/hugo.toml index 7ca32762..32e87d22 100644 --- a/hugo.toml +++ b/hugo.toml @@ -389,7 +389,7 @@ enableEmoji = true # Search config [params.search] enable = false - # type of search engine ["algolia", "fuse", "cse"] + # type of search engine ["algolia", "fuse", "cse", "post-chat"] type = "fuse" # max index length of the chunked content contentLength = 4000 @@ -887,12 +887,11 @@ enableEmoji = true theme = "minimal" # FixIt 0.3.17 | NEW PostChat AI config - # Summary AI, knowledge base search and knowledge base dialogue support - # Docs: https://postchat.zhheo.com/ + # Based on your posts to build a knowledge base, support AI summary, AI search, and AI Chatbot. + # Get PostChat Key from my invitation link, thanks for your support! + # https://ai.tianli0.top/?InviteID=IRE1S88Z [params.postChat] enable = false - # Get PostChat Key from my invitation link, thanks for your support! - # https://ai.tianli0.top/?InviteID=IRE1S88Z key = "ed872bf9336506bea545183089f5034f81fea6af" # How users initiate chats: ["iframe", "magic"] userMode = "magic" diff --git a/layouts/partials/assets.html b/layouts/partials/assets.html index 0b0b2304..dd3a1f0a 100644 --- a/layouts/partials/assets.html +++ b/layouts/partials/assets.html @@ -22,7 +22,7 @@ {{- $source := $cdn.fuseJS | default "lib/fuse/fuse.min.js" -}} {{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} {{- $config = dict "isCaseSensitive" $search.fuse.isCaseSensitive "minMatchCharLength" $search.fuse.minMatchCharLength "findAllMatches" $search.fuse.findAllMatches "location" $search.fuse.location "threshold" $search.fuse.threshold "distance" $search.fuse.distance "ignoreLocation" $search.fuse.ignoreLocation "useExtendedSearch" $search.fuse.useExtendedSearch "ignoreFieldNorm" $search.fuse.ignoreFieldNorm | dict "search" | merge $config -}} - {{- else if eq $search.type "cse" -}} + {{- else if eq $search.type "cse" -}} {{- $config = dict "type" "cse" | dict "search" | merge $config -}} {{- $cse := .Site.Params.cse -}} {{- $config = dict "resultsPage" $cse.resultsPage "gotoResultsPage" (T "assets.gotoResultsPage") | dict "cse" | merge $config -}} @@ -32,6 +32,8 @@ {{- if eq $cse.engine "bing" -}} {{- /* Unsupported */ -}} {{- end -}} + {{- else if eq $search.type "post-chat" -}} + {{- $config = dict "type" "post-chat" | dict "search" | merge $config -}} {{- end -}} {{- end -}} From 10b46284a11b865781ce69da4e682ea93d64548d Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Thu, 19 Dec 2024 12:42:15 +0800 Subject: [PATCH 9/9] :memo: Chore: remove todo comment --- layouts/partials/plugin/post-chat-ai.html | 1 - 1 file changed, 1 deletion(-) diff --git a/layouts/partials/plugin/post-chat-ai.html b/layouts/partials/plugin/post-chat-ai.html index 252c2e18..9307054b 100644 --- a/layouts/partials/plugin/post-chat-ai.html +++ b/layouts/partials/plugin/post-chat-ai.html @@ -2,7 +2,6 @@ PostChat AI service. PostChat: https://postchat.zhheo.com/addCode.html PostSummary: https://postchat.zhheo.com/summary.html - TODO chat API development */ -}} {{- $params := .Params | merge .Site.Params -}} {{- $chatConfig := $params.postChat -}}