feat: support Waline

This commit is contained in:
HPCesia 2025-03-06 14:37:23 +08:00
parent abbbb63ef0
commit 8dd3d663b1
7 changed files with 142 additions and 16 deletions

View File

@ -12,6 +12,7 @@ import { wrapCode } from './src/plugins/shiki-transformers.ts';
import { rehypeHeadingIds } from '@astrojs/markdown-remark'; import { rehypeHeadingIds } from '@astrojs/markdown-remark';
import mdx from '@astrojs/mdx'; import mdx from '@astrojs/mdx';
import sitemap from '@astrojs/sitemap'; import sitemap from '@astrojs/sitemap';
import vue from '@astrojs/vue';
// import { transformerNotationDiff } from '@shikijs/transformers'; // import { transformerNotationDiff } from '@shikijs/transformers';
// import { transformerNotationHighlight } from '@shikijs/transformers'; // import { transformerNotationHighlight } from '@shikijs/transformers';
import tailwindcss from '@tailwindcss/vite'; import tailwindcss from '@tailwindcss/vite';
@ -36,6 +37,7 @@ export default defineConfig({
sitemap({ filter: (page) => !page.includes('/archives/') && !page.includes('/about/') }), sitemap({ filter: (page) => !page.includes('/archives/') && !page.includes('/about/') }),
pagefind(), pagefind(),
mdx(), mdx(),
vue(),
], ],
markdown: { markdown: {
shikiConfig: { shikiConfig: {

View File

@ -17,6 +17,7 @@
"@astrojs/mdx": "^4.1.0", "@astrojs/mdx": "^4.1.0",
"@astrojs/rss": "^4.0.11", "@astrojs/rss": "^4.0.11",
"@astrojs/sitemap": "^3.2.1", "@astrojs/sitemap": "^3.2.1",
"@astrojs/vue": "^5.0.7",
"@iconify-json/ic": "^1.2.2", "@iconify-json/ic": "^1.2.2",
"@iconify-json/material-symbols": "^1.2.14", "@iconify-json/material-symbols": "^1.2.14",
"@iconify-json/mdi": "^1.2.3", "@iconify-json/mdi": "^1.2.3",
@ -29,6 +30,7 @@
"@swup/scripts-plugin": "^2.1.0", "@swup/scripts-plugin": "^2.1.0",
"@swup/scroll-plugin": "^3.3.2", "@swup/scroll-plugin": "^3.3.2",
"@tailwindcss/vite": "^4.0.9", "@tailwindcss/vite": "^4.0.9",
"@waline/client": "^3.5.5",
"astro": "^5.4.1", "astro": "^5.4.1",
"astro-compress": "2.3.5", "astro-compress": "2.3.5",
"astro-icon": "^1.1.5", "astro-icon": "^1.1.5",
@ -56,7 +58,8 @@
"swup": "^4.8.1", "swup": "^4.8.1",
"tailwindcss": "^4.0.9", "tailwindcss": "^4.0.9",
"typescript": "^5.7.3", "typescript": "^5.7.3",
"unist-util-visit": "^5.0.0" "unist-util-visit": "^5.0.0",
"vue": "^3.5.13"
}, },
"devDependencies": { "devDependencies": {
"@astrojs/check": "^0.9.4", "@astrojs/check": "^0.9.4",

View File

@ -2,6 +2,7 @@
import { commentConfig } from '@/config'; import { commentConfig } from '@/config';
import Giscus from '@components/comment/Giscus.astro'; import Giscus from '@components/comment/Giscus.astro';
import Twikoo from '@components/comment/Twikoo.astro'; import Twikoo from '@components/comment/Twikoo.astro';
import Waline from '@components/comment/Waline.astro';
--- ---
<div id="page-comment"> <div id="page-comment">
@ -12,6 +13,8 @@ import Twikoo from '@components/comment/Twikoo.astro';
return <Twikoo />; return <Twikoo />;
case 'giscus': case 'giscus':
return <Giscus />; return <Giscus />;
case 'waline':
return <Waline />;
} }
})() })()
} }

View File

@ -0,0 +1,20 @@
---
import { commentConfig } from '@/config';
import { Waline as WalineComponent } from '@waline/client/component';
import '@waline/client/meta';
import '@waline/client/style';
const walineConfig = commentConfig.waline!;
---
<WalineComponent
serverURL={walineConfig.serverURL}
path="window.location.pathname"
dark={false}
meta={walineConfig.meta || ['nick', 'mail', 'link']}
requiredMeta={walineConfig.requiredMeta || []}
login={walineConfig.login || 'enable'}
wordLimit={walineConfig.wordLimit || 500}
pageSize={walineConfig.pageSize || 10}
reaction={walineConfig.reaction || false}
/>

View File

@ -164,8 +164,8 @@ export const searchConfig: SearchConfig = {
}; };
export const commentConfig: CommentConfig = { export const commentConfig: CommentConfig = {
enable: false, enable: true,
provider: 'twikoo', provider: 'waline',
twikoo: { twikoo: {
envId: 'your-env-id', envId: 'your-env-id',
}, },
@ -176,4 +176,10 @@ export const commentConfig: CommentConfig = {
categoryId: 'your-category-id', categoryId: 'your-category-id',
mapping: 'og:title', mapping: 'og:title',
}, },
waline: {
serverURL: 'https://astral-halo-comment.netlify.app/.netlify/functions/comment',
wordLimit: 100, // Set a lower limit for demo site, to prevent abuse and save free database space cost.
pageSize: 10,
reaction: false,
},
}; };

View File

@ -438,7 +438,7 @@ export type CommentConfig = {
* *
* *
*/ */
provider: 'twikoo' | 'giscus'; provider: 'twikoo' | 'giscus' | 'waline';
/** /**
* The configuration of Twikoo. * The configuration of Twikoo.
* *
@ -566,4 +566,75 @@ export type CommentConfig = {
*/ */
lazyLoad?: boolean; lazyLoad?: boolean;
}; };
/**
* The configuration of Waline.
*
* Waline
*
* @see https://waline.js.org/
*/
waline?: {
/**
* The server URL of Waline.
*
* Waline
*
* @see https://waline.js.org/reference/client/props.html#serverurl
*/
serverURL: string;
/**
* Reviewer attributes of Waline.
*
* Waline
*
* @default ['nick', 'mail', 'link']
* @see https://waline.js.org/reference/client/props.html#meta
*/
meta?: ('nick' | 'mail' | 'link')[];
/**
* Required reviewer attributes of Waline.
*
* Waline
*
* @default []
* @see https://waline.js.org/reference/client/props.html#requiredmeta
*/
requiredMeta?: [] | ['nick'] | ['nick', 'mail'];
/**
* Whether to enable or force to login.
*
*
*
* @default 'enable'
* @see https://waline.js.org/reference/client/props.html#login
*/
login?: 'enable' | 'disable' | 'force';
/**
* The word limit of the comment.
*
*
*
* @default 500
* @see https://waline.js.org/reference/client/props.html#wordlimit
*/
wordLimit?: number;
/**
* The page size of the comments.
*
*
*
* @default 10
* @see https://waline.js.org/reference/client/props.html#pagesize
*/
pageSize?: number;
/**
* Whether to enable reactions.
*
*
*
* @default false
* @see https://waline.js.org/reference/client/props.html#reaction
*/
reaction?: boolean | string[];
};
}; };

View File

@ -11,16 +11,37 @@
} }
], ],
"paths": { "paths": {
"@assets/*": ["src/assets/*"], "@assets/*": [
"@components/*": ["src/components/*"], "src/assets/*"
"@constants/*": ["src/constants/*"], ],
"@i18n/*": ["src/i18n/*"], "@components/*": [
"@layouts/*": ["src/layouts/*"], "src/components/*"
"@scripts/*": ["src/scripts/*"], ],
"@utils/*": ["src/utils/*"], "@constants/*": [
"@/*": ["src/*"] "src/constants/*"
} ],
"@i18n/*": [
"src/i18n/*"
],
"@layouts/*": [
"src/layouts/*"
],
"@scripts/*": [
"src/scripts/*"
],
"@utils/*": [
"src/utils/*"
],
"@/*": [
"src/*"
]
},
"jsx": "preserve"
}, },
"include": ["src/**/*"], "include": [
"exclude": ["dist"] "src/**/*"
} ],
"exclude": [
"dist"
]
}