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] :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 -}}