diff --git a/plugins/plugin-comment/package.json b/plugins/plugin-comment/package.json index db5634ce48..a9d48e3017 100644 --- a/plugins/plugin-comment/package.json +++ b/plugins/plugin-comment/package.json @@ -32,7 +32,7 @@ ".": "./lib/node/index.js", "./client": "./lib/client/index.js", "./client/*": "./lib/client/*", - "./pageview": "./lib/client/composables/pageview.js", + "./pageview": "./lib/client/pageview.js", "./package.json": "./package.json" }, "main": "./lib/node/index.js", diff --git a/plugins/plugin-comment/src/client/composables/pageview.ts b/plugins/plugin-comment/src/client/composables/pageview.ts deleted file mode 100644 index 51c263ff8f..0000000000 --- a/plugins/plugin-comment/src/client/composables/pageview.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { WalineAbort } from '@waline/client' -import { useWalineOptions } from '../helpers/index.js' - -export type AbortPageview = (reason?: any) => void -export type UpdatePageview = () => Promise - -export const usePageView = (): UpdatePageview => { - const commentOptions = useWalineOptions() - - return async (): Promise => { - try { - const { pageviewCount } = await import( - /* webpackMode: "week" */ /* webpackChunkName: "pageview" */ '@waline/client/pageview' - ) - return pageviewCount({ serverURL: commentOptions.serverURL }) - } catch (err) { - console.error('@waline/client is not installed!') - } - } -} diff --git a/plugins/plugin-comment/src/client/helpers/comment.ts b/plugins/plugin-comment/src/client/helpers/comment.ts index 7be5536a49..3b8e0e92fa 100644 --- a/plugins/plugin-comment/src/client/helpers/comment.ts +++ b/plugins/plugin-comment/src/client/helpers/comment.ts @@ -22,7 +22,7 @@ const defineCommentConfig = (options: T): void => { } export const useCommentOptions = (): T => - inject(commentSymbol)! + inject(commentSymbol)! ?? comment export const defineArtalkConfig = defineCommentConfig diff --git a/plugins/plugin-comment/src/client/pageview.ts b/plugins/plugin-comment/src/client/pageview.ts new file mode 100644 index 0000000000..b857179645 --- /dev/null +++ b/plugins/plugin-comment/src/client/pageview.ts @@ -0,0 +1,18 @@ +import { useWalineOptions } from './helpers/index.js' + +export type AbortPageview = (reason?: any) => void +export type UpdatePageview = Promise + +export const updatePageview = async (): UpdatePageview => { + const commentOptions = useWalineOptions() + + try { + const { pageviewCount } = await import( + /* webpackMode: "week" */ /* webpackChunkName: "pageview" */ '@waline/client/pageview' + ) + + return pageviewCount({ serverURL: commentOptions.serverURL }) + } catch (err) { + console.error('@waline/client is not installed!') + } +}