From 3671044837df6b707421725b3d630d187157c611 Mon Sep 17 00:00:00 2001 From: Ad-closeNN <1709301095@qq.com> Date: Sat, 16 May 2026 21:12:26 +0800 Subject: [PATCH] =?UTF-8?q?feat(viewSource):=20AI=20=E9=93=BE=E6=8E=A5?= =?UTF-8?q?=E6=94=B9=E7=94=A8=20raw=20URL=EF=BC=8C=E6=96=B0=E5=A2=9E=20Git?= =?UTF-8?q?ea=20=E6=BA=90=E7=A0=81=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - AI prompt 改用 raw.githubusercontent.com 纯文本链接 - 新增 Gitea 网页版源码链接,置顶显示 Co-Authored-By: Claude Code --- src/pages/posts/[...slug].astro | 40 ++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/pages/posts/[...slug].astro b/src/pages/posts/[...slug].astro index 59f2e15..7503a44 100644 --- a/src/pages/posts/[...slug].astro +++ b/src/pages/posts/[...slug].astro @@ -71,6 +71,34 @@ function getGitHubPostSourceUrl(repo: string | undefined, sourcePath: string | u return `${normalizedRepo}/blob/main/${encodedSourcePath}?plain=1`; } +function getGitHubRawSourceUrl(repo: string | undefined, sourcePath: string | undefined) { + if (!repo || !sourcePath) return ""; + + const normalizedRepo = repo.replace(/\.git$/, "").replace(/\/+$/, ""); + const repoPath = normalizedRepo.includes("://") + ? new URL(normalizedRepo).pathname.replace(/^\/+|\/+$/g, "") + : normalizedRepo.replace(/^\/+|\/+$/g, ""); + const [owner, repository] = repoPath.split("/"); + if (!owner || !repository) return ""; + + const encodedSourcePath = sourcePath.split("/").map(encodeURIComponent).join("/"); + return `https://raw.githubusercontent.com/${encodeURIComponent(owner)}/${encodeURIComponent(repository)}/refs/heads/main/${encodedSourcePath}`; +} + +function getGiteaRawSourceUrl(repo: string | undefined, sourcePath: string | undefined, giteaHost: string) { + if (!repo || !sourcePath) return ""; + + const normalizedRepo = repo.replace(/\.git$/, "").replace(/\/+$/, ""); + const repoPath = normalizedRepo.includes("://") + ? new URL(normalizedRepo).pathname.replace(/^\/+|\/+$/g, "") + : normalizedRepo.replace(/^\/+|\/+$/g, ""); + const [owner, repository] = repoPath.split("/"); + if (!owner || !repository) return ""; + + const encodedSourcePath = sourcePath.split("/").map(encodeURIComponent).join("/"); + return `https://${giteaHost}/${encodeURIComponent(owner)}/${encodeURIComponent(repository)}/src/branch/main/${encodedSourcePath}?display=source`; +} + function parseAiSummaryValue(value: string) { const trimmed = value.trim(); if (!trimmed) return ""; @@ -125,9 +153,16 @@ const aiSummaryMeta = getAiSummaryMeta(entry.id); const postSourceKey = getPostSourceKey(entry.id); const postSourcePath = getPostSourcePath(postSourceKey); const postSourceUrl = getGitHubPostSourceUrl(siteConfig.githubRepo, postSourcePath); -const aiPrompt = `Read from ${postSourceUrl} so I can ask questions about it.`; +const postRawSourceUrl = getGitHubRawSourceUrl(siteConfig.githubRepo, postSourcePath); +const postGiteaRawSourceUrl = getGiteaRawSourceUrl(siteConfig.githubRepo, postSourcePath, "git.adclosenn.top"); +const aiPrompt = `Read from ${postRawSourceUrl} so I can ask questions about it.`; const encodedAiPrompt = encodeURIComponent(aiPrompt); const copyPageAiLinks = [ + { + label: "Gitea", + icon: "cln-gitea", + href: postGiteaRawSourceUrl, + }, { label: "ChatGPT", icon: "gpt", @@ -260,6 +295,9 @@ const isOutdated = entry.data.outdated; )} + {link.icon === "cln-gitea" && ( + + )} 在 {link.label} 中打开