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;
{postSourceUrl && (
- + + + 在 GitHub 查看 +
-