Skip to content

Commit

Permalink
⚡ Perf: PostChat support all types page and PostSummary only for publ…
Browse files Browse the repository at this point in the history
…ic posts
  • Loading branch information
Lruihao committed Dec 18, 2024
1 parent 1d09297 commit 041d5e2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
3 changes: 3 additions & 0 deletions layouts/partials/assets.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
{{- /*
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
"chat" "postChatUser.min.js"
"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 := "" -}}
{{- $fingerprint := .Scratch.Get "fingerprint" -}}
{{- $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" -}}
Expand Down Expand Up @@ -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 -}}
Expand Down
3 changes: 0 additions & 3 deletions layouts/posts/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,6 @@ <h1 class="single-title animate__animated animate__flipInX">
{{- /* Expiration Reminder */ -}}
{{- partial "single/expiration-reminder.html" . -}}
{{- $content -}}

{{- /* PostChat */ -}}
{{- partial "single/post-chat-ai.html" . -}}
{{- end -}}
</div>

Expand Down

0 comments on commit 041d5e2

Please sign in to comment.