From a4314ee59087512269669e661b41fdc53e3f12a7 Mon Sep 17 00:00:00 2001 From: Ad-closeNN <1709301095@qq.com> Date: Sat, 2 May 2026 14:11:36 +0800 Subject: [PATCH] =?UTF-8?q?revert(viewSource):=20=E8=BF=98=E5=8E=9F?= =?UTF-8?q?=E2=80=9C=E5=9C=A8=20GitHub=20=E6=9F=A5=E7=9C=8B=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/posts/[...slug].astro | 49 +++++++++++---------------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/src/pages/posts/[...slug].astro b/src/pages/posts/[...slug].astro index 16d7a3e..59f2e15 100644 --- a/src/pages/posts/[...slug].astro +++ b/src/pages/posts/[...slug].astro @@ -65,15 +65,10 @@ function getPostSourcePath(sourceKey: string | undefined) { function getGitHubPostSourceUrl(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 repoUrl = repo.includes("://") ? repo : `https://github.com/${repo}`; + const normalizedRepo = repoUrl.replace(/\.git$/, "").replace(/\/+$/, ""); const encodedSourcePath = sourcePath.split("/").map(encodeURIComponent).join("/"); - return `https://raw.githubusercontent.com/${encodeURIComponent(owner)}/${encodeURIComponent(repository)}/refs/heads/main/${encodedSourcePath}`; + return `${normalizedRepo}/blob/main/${encodedSourcePath}?plain=1`; } function parseAiSummaryValue(value: string) { @@ -130,7 +125,6 @@ const aiSummaryMeta = getAiSummaryMeta(entry.id); const postSourceKey = getPostSourceKey(entry.id); const postSourcePath = getPostSourcePath(postSourceKey); const postSourceUrl = getGitHubPostSourceUrl(siteConfig.githubRepo, postSourcePath); -const copyPageText = postSourceKey ? postSources[postSourceKey] : ""; const aiPrompt = `Read from ${postSourceUrl} so I can ask questions about it.`; const encodedAiPrompt = encodeURIComponent(aiPrompt); const copyPageAiLinks = [ @@ -214,10 +208,17 @@ const isOutdated = entry.data.outdated;