refactor: declare twikoo global variable

This commit is contained in:
HPCesia 2025-03-18 19:56:48 +08:00
parent cd6071dbfb
commit 7f7d57b94f
2 changed files with 36 additions and 3 deletions

View File

@ -8,8 +8,6 @@ import { CDN } from '@constants/cdn.mjs';
<script>
import { commentConfig } from '@/config';
const twikooConfig = commentConfig.twikoo;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
declare const twikoo: any;
function setup() {
if (typeof twikoo === 'undefined') {
@ -17,7 +15,7 @@ import { CDN } from '@constants/cdn.mjs';
} else {
twikoo.init({
el: '#twikoo-wrap',
...twikooConfig,
...twikooConfig!,
});
}
}

35
src/global.d.ts vendored
View File

@ -4,4 +4,39 @@ declare global {
interface Window {
swup: Swup;
}
const twikoo: {
init: (options: {
envId: string;
el: string;
region?: string;
path?: string;
lang?: string;
onCommentLoaded?: () => void;
}) => Promise<void>;
getCommentsCount: (options: {
envId: string;
urls: string[];
includeReply?: boolean;
}) => Promise<{ url: string; count: number }[]>;
getRecentComments: (options: {
envId: string;
urls?: string[];
pageSize?: number;
includeReply?: boolean;
}) => Promise<
{
id: string;
url: string;
nick: string;
mailMd5: string;
link: string;
comment: string;
commentText: string;
created: number;
avatar: string;
relativeTime: string;
}[]
>;
};
}