docs: 替换 GitHub 图片资源链接为代理链接

This commit is contained in:
涵曦 2024-12-13 16:23:27 +08:00
parent 1e0949703f
commit 1015736635
2 changed files with 126 additions and 116 deletions

View File

@ -62,6 +62,7 @@ export default async ({ mode }) => {
targetUrl: '/issues',
},
],
githubProxy: 'https://cloudflare-github-proxy.hanxi-info.workers.dev/proxy',
}),
],
}

View File

@ -14,6 +14,7 @@ interface GitHubIssuesPluginOptions {
repo: string; // GitHub repository info in the format 'owner/repo'
token: string;
replaceRules: ReplaceRule[];
githubProxy: string;
}
async function fetchAllIssues(repo: string, token: string): Promise<any[]> {
@ -135,7 +136,7 @@ function copyReadmeFile(source: string, destination: string) {
}
export default function GitHubIssuesPlugin(options: GitHubIssuesPluginOptions): Plugin {
const { repo, token, replaceRules } = options;
const { repo, token, replaceRules, githubProxy } = options;
return {
name: 'vitepress-plugin-github-issues',
@ -207,6 +208,14 @@ ${comment.body}
content = content.replace(pattern, `${targetUrl}$1.html`);
});
content = content.replace(
/(https:\/\/github\.com\/([^\/]+\/[^\/]+\/assets\/[^\s]+)/g,
(match, p1) => {
const proxyUrl = `${githubProxy}/${p1}`; // 使用传入的 base URL
return proxyUrl;
}
);
content += `[链接到 GitHub Issue](${issue.html_url})\n`
const filePath = path.join(docsDir, fileName);