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 fb33748b..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: { @@ -1130,6 +1147,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 +1302,7 @@ class FixIt { this.initWatermark(); this.initAutoMark(); this.initReward(); + this.initPostChatUser(); window.setTimeout(() => { this.initComment(); diff --git a/hugo.toml b/hugo.toml index 44253f36..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 @@ -886,6 +886,52 @@ 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 + # 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 + 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/assets.html b/layouts/partials/assets.html index 03df5c2c..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 -}} @@ -265,6 +267,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/plugin/post-chat-ai.html b/layouts/partials/plugin/post-chat-ai.html new file mode 100644 index 00000000..9307054b --- /dev/null +++ b/layouts/partials/plugin/post-chat-ai.html @@ -0,0 +1,112 @@ +{{- /* + PostChat AI service. + PostChat: https://postchat.zhheo.com/addCode.html + PostSummary: https://postchat.zhheo.com/summary.html +*/ -}} +{{- $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 + "chat" "postChatUser.min.js" + "summary" "tianli_gpt.min.js" + "both" "postChatUser_summary.min.js" +-}} +{{- /* PostSummary only for public posts */ -}} +{{- $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 -}} + +{{- if $enable | and $key -}} + {{- $configJS := "" -}} + {{- $fingerprint := .Scratch.Get "fingerprint" -}} + {{- $sourceOpts := dict "Fingerprint" $fingerprint "Defer" true -}} + + {{- /* PostSummary */ -}} + {{- 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" -}} + {{- $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 -}} + {{- $blackDom := slice + ".expiration-reminder" + "meting-js" + ".lnt" + -}} + {{- with $chatConfig.blackDom -}} + {{- $blackDom = $blackDom | append . -}} + {{- end -}} + {{- $upLoadWeb := cond (.IsHome | or $password) false $chatConfig.upLoadWeb -}} + {{- $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" $upLoadWeb + "showInviteLink" $chatConfig.showInviteLink + "userTitle" $chatConfig.userTitle + "userDesc" $chatConfig.userDesc + "addButton" $chatConfig.addButton + "blackDom" $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 $summaryEnable -}} + {{- $postChatJS = add $sourcePrefix (index $jsMap "both") -}} + {{- else if $chatConfig.enable -}} + {{- $postChatJS = add $sourcePrefix (index $jsMap "chat") -}} + {{- else if $summaryEnable -}} + {{- $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/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 -}} -