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