diff --git a/assets/js/core/tokens.ts b/assets/js/core/tokens.ts index 4e506771..9fec709b 100644 --- a/assets/js/core/tokens.ts +++ b/assets/js/core/tokens.ts @@ -69,8 +69,8 @@ export interface MiscService { initSiteTime: () => void initAutoMark: () => void initReward: () => void - initPostChatUser: () => void initComment: () => void + initPostChat: () => void setup: () => void } diff --git a/assets/js/modules/misc.ts b/assets/js/modules/misc.ts index 72ddae8b..27f9b8d7 100644 --- a/assets/js/modules/misc.ts +++ b/assets/js/modules/misc.ts @@ -104,22 +104,39 @@ export class MiscModule implements MiscService { document.querySelector('#comments')!.remove() } - /** Initialize PostChat theme sync if configured. */ - initPostChatUser() { - if (!window.postChatUser || !window.postChatConfig || window.postChatConfig.userMode === 'magic') - return - window.postChat_theme = this.core.isDark ? 'dark' : 'light' - eventBus.on('fixit:switch-theme', ({ detail }) => { - if (!detail.isChanged) + /** + * Initialize PostChat and postSummary for HongMoAI + */ + initPostChat() { + const initThemeCompatibility = () => { + if (this.core.config.postChat) { + document.body.classList.toggle('dark', this.core.isDark) + eventBus.on('fixit:switch-theme', ({ detail }) => { + if (!detail.isChanged) + return + document.body.classList.toggle('dark', detail.isDark) + }) + } + } + /** Initialize PostChat theme sync if configured. */ + const initPostChatUser = () => { + if (!window.postChatUser || !window.postChatConfig || window.postChatConfig.userMode === 'magic') return - const targetFrame = document.getElementById('postChat_iframeContainer') - if (targetFrame) { - window.postChatUser.setPostChatTheme(detail.isDark ? 'dark' : 'light') - } - else { - window.postChat_theme = detail.isDark ? 'dark' : 'light' - } - }) + window.postChat_theme = this.core.isDark ? 'dark' : 'light' + eventBus.on('fixit:switch-theme', ({ detail }) => { + if (!detail.isChanged) + return + const targetFrame = document.getElementById('postChat_iframeContainer') + if (targetFrame) { + window.postChatUser.setPostChatTheme(detail.isDark ? 'dark' : 'light') + } + else { + window.postChat_theme = detail.isDark ? 'dark' : 'light' + } + }) + } + initThemeCompatibility() + initPostChatUser() } /** Initialize all miscellaneous features. */ @@ -127,7 +144,7 @@ export class MiscModule implements MiscService { this.initSiteTime() this.initAutoMark() this.initReward() - this.initPostChatUser() this.initComment() + this.initPostChat() } } diff --git a/assets/js/types/config.ts b/assets/js/types/config.ts index 01c283fd..059a3ed9 100644 --- a/assets/js/types/config.ts +++ b/assets/js/types/config.ts @@ -31,6 +31,7 @@ export interface FixItConfig { autoBookmark?: boolean encryption?: EncryptionConfig print?: PrintConfig + postChat?: boolean } export interface EchartsConfig { diff --git a/hugo.toml b/hugo.toml index 6bd8c380..8e04b78f 100644 --- a/hugo.toml +++ b/hugo.toml @@ -836,7 +836,7 @@ fullscreen = true # PostChat AI configuration. # Based on your posts to build a knowledge base, support AI summary, AI search, and AI Chatbot. -# See: [洪墨 AI](https://ai.zhheo.com/docs/) +# See: [HongMoAI](https://ai.zhheo.com/docs/) # Get PostChat Key from my invitation link, thanks for your support! # https://ai.zhheo.com/console/login?InviteID=85041330 [params.post_chat] diff --git a/layouts/_partials/base/assets.html b/layouts/_partials/base/assets.html index a2f2a1aa..fa1e5f8b 100644 --- a/layouts/_partials/base/assets.html +++ b/layouts/_partials/base/assets.html @@ -334,7 +334,10 @@ {{- $config = partial "function/camel-case-keys.html" .Site.Params.print | dict "print" | merge $config -}} {{- /* PostChat */ -}} -{{- partial "plugin/post-chat-ai.html" . -}} +{{- $postChatEnable := partial "plugin/post-chat-ai.html" . -}} +{{- if $postChatEnable -}} + {{- $config = dict "postChat" true | merge $config -}} +{{- end -}} {{- $library := dict "Page" . "Key" "library" | partial "function/param.html" -}} {{- range $library.css -}} diff --git a/layouts/_partials/init/index.html b/layouts/_partials/init/index.html index 485d1ae0..6672618f 100644 --- a/layouts/_partials/init/index.html +++ b/layouts/_partials/init/index.html @@ -1,4 +1,4 @@ -{{- hugo.Store.Set "version" "v1.0.0-mrma4qc1" -}} +{{- hugo.Store.Set "version" "v1.0.0-mrmd49g5" -}} {{- .Store.Set "this" dict -}} {{- partial "init/detection-env.html" . -}} diff --git a/layouts/_partials/plugin/post-chat-ai.html b/layouts/_partials/plugin/post-chat-ai.html index 21a69c5f..734a020f 100644 --- a/layouts/_partials/plugin/post-chat-ai.html +++ b/layouts/_partials/plugin/post-chat-ai.html @@ -109,3 +109,5 @@ {{- $sourceOpts = dict "Source" $postChatJS | merge $sourceOpts -}} {{- $sourceOpts | dict "Page" . "Data" | partial "store/script.html" -}} {{- end -}} + +{{- return $enable -}}