Commit ebc4550

HPCesia <me@hpcesia.com>
2025-03-06 07:44:08
fix: Waline path
1 parent fe76e95
Changed files (2)
src
components
types
src/components/comment/Waline.astro
@@ -7,12 +7,13 @@ import '@waline/client/style';
 import '@/styles/waline.css';
 
 const walineConfig = commentConfig.waline!;
+const pathName = walineConfig.path ? walineConfig.path(Astro.url.pathname) : Astro.url.pathname;
 ---
 
 <WalineComponent
   client:visible
   serverURL={walineConfig.serverURL}
-  path="window.location.pathname"
+  path={pathName}
   dark={false}
   meta={walineConfig.meta || ['nick', 'mail', 'link']}
   requiredMeta={walineConfig.requiredMeta || []}
src/types/config.ts
@@ -582,6 +582,17 @@ export type CommentConfig = {
      * @see https://waline.js.org/reference/client/props.html#serverurl
      */
     serverURL: string;
+    /**
+     * The path processor of the page.
+     * The parameter is `Astro.url.pathname`, and the return value will be passed to Waline as `path`.
+     *
+     * 页面路径处理器。传入参数为 `Astro.url.pathname`,返回值将传入 Waline 作为 `path`。
+     *
+     * @default (path) => path
+     * @see https://docs.astro.build/reference/api-reference/#url
+     * @see https://waline.js.org/reference/client/props.html#path
+     */
+    path?: (path: string) => string;
     /**
      * Reviewer attributes of Waline.
      *