Skip to content

Commit

Permalink
✨ Feat: add post-chat search engine powered by PostChat
Browse files Browse the repository at this point in the history
  • Loading branch information
Lruihao committed Dec 19, 2024
1 parent fcd72c9 commit 3e210af
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion README.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
- 支持**代码高亮**
- 一键**复制代码**到剪贴板
Expand Down
19 changes: 18 additions & 1 deletion assets/js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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');
Expand Down Expand Up @@ -301,6 +316,8 @@ class FixIt {
context: cseConfig.gotoResultsPage
}]);
}
} else {
finish([]);
}
},
templates: {
Expand Down
9 changes: 4 additions & 5 deletions hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion layouts/partials/assets.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
Expand All @@ -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 -}}

Expand Down

0 comments on commit 3e210af

Please sign in to comment.