mirror of
https://github.com/Ad-closeNN/blog-fuwari.git
synced 2026-05-31 01:20:06 -04:00
chore: format & feedback beautification
This commit is contained in:
@@ -62,16 +62,25 @@ function getPostSourcePath(sourceKey: string | undefined) {
|
||||
return sourceKey?.replace("../../content/posts/", "src/content/posts/");
|
||||
}
|
||||
|
||||
function getGitHubPostSourceUrl(repo: string | undefined, sourcePath: string | undefined) {
|
||||
function getGitHubPostSourceUrl(
|
||||
repo: string | undefined,
|
||||
sourcePath: string | undefined,
|
||||
) {
|
||||
if (!repo || !sourcePath) return "";
|
||||
|
||||
const repoUrl = repo.includes("://") ? repo : `https://github.com/${repo}`;
|
||||
const normalizedRepo = repoUrl.replace(/\.git$/, "").replace(/\/+$/, "");
|
||||
const encodedSourcePath = sourcePath.split("/").map(encodeURIComponent).join("/");
|
||||
const encodedSourcePath = sourcePath
|
||||
.split("/")
|
||||
.map(encodeURIComponent)
|
||||
.join("/");
|
||||
return `${normalizedRepo}/blob/main/${encodedSourcePath}?plain=1`;
|
||||
}
|
||||
|
||||
function getGitHubRawSourceUrl(repo: string | undefined, sourcePath: string | undefined) {
|
||||
function getGitHubRawSourceUrl(
|
||||
repo: string | undefined,
|
||||
sourcePath: string | undefined,
|
||||
) {
|
||||
if (!repo || !sourcePath) return "";
|
||||
|
||||
const normalizedRepo = repo.replace(/\.git$/, "").replace(/\/+$/, "");
|
||||
@@ -81,11 +90,18 @@ function getGitHubRawSourceUrl(repo: string | undefined, sourcePath: string | un
|
||||
const [owner, repository] = repoPath.split("/");
|
||||
if (!owner || !repository) return "";
|
||||
|
||||
const encodedSourcePath = sourcePath.split("/").map(encodeURIComponent).join("/");
|
||||
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) {
|
||||
function getGiteaRawSourceUrl(
|
||||
repo: string | undefined,
|
||||
sourcePath: string | undefined,
|
||||
giteaHost: string,
|
||||
) {
|
||||
if (!repo || !sourcePath) return "";
|
||||
|
||||
const normalizedRepo = repo.replace(/\.git$/, "").replace(/\/+$/, "");
|
||||
@@ -95,7 +111,10 @@ function getGiteaRawSourceUrl(repo: string | undefined, sourcePath: string | und
|
||||
const [owner, repository] = repoPath.split("/");
|
||||
if (!owner || !repository) return "";
|
||||
|
||||
const encodedSourcePath = sourcePath.split("/").map(encodeURIComponent).join("/");
|
||||
const encodedSourcePath = sourcePath
|
||||
.split("/")
|
||||
.map(encodeURIComponent)
|
||||
.join("/");
|
||||
return `https://${giteaHost}/${encodeURIComponent(owner)}/${encodeURIComponent(repository)}/src/branch/main/${encodedSourcePath}?display=source`;
|
||||
}
|
||||
|
||||
@@ -103,7 +122,10 @@ function getCnbsSourceUrl(baseUrl: string, sourcePath: string | undefined) {
|
||||
if (!sourcePath) return "";
|
||||
|
||||
const normalizedUrl = baseUrl.replace(/\.git$/, "").replace(/\/+$/, "");
|
||||
const encodedSourcePath = sourcePath.split("/").map(encodeURIComponent).join("/");
|
||||
const encodedSourcePath = sourcePath
|
||||
.split("/")
|
||||
.map(encodeURIComponent)
|
||||
.join("/");
|
||||
return `${normalizedUrl}/-/blob/main/${encodedSourcePath}`;
|
||||
}
|
||||
|
||||
@@ -160,10 +182,23 @@ function getAiSummaryMeta(entryId: string) {
|
||||
const aiSummaryMeta = getAiSummaryMeta(entry.id);
|
||||
const postSourceKey = getPostSourceKey(entry.id);
|
||||
const postSourcePath = getPostSourcePath(postSourceKey);
|
||||
const postSourceUrl = getGitHubPostSourceUrl(siteConfig.githubRepo, postSourcePath);
|
||||
const postRawSourceUrl = getGitHubRawSourceUrl(siteConfig.githubRepo, postSourcePath);
|
||||
const postGiteaRawSourceUrl = getGiteaRawSourceUrl(siteConfig.githubRepo, postSourcePath, "git.adclosenn.top");
|
||||
const postCnbsSourceUrl = getCnbsSourceUrl("https://cnb.cool/CLN-Grated/blog-fuwari", postSourcePath);
|
||||
const postSourceUrl = getGitHubPostSourceUrl(
|
||||
siteConfig.githubRepo,
|
||||
postSourcePath,
|
||||
);
|
||||
const postRawSourceUrl = getGitHubRawSourceUrl(
|
||||
siteConfig.githubRepo,
|
||||
postSourcePath,
|
||||
);
|
||||
const postGiteaRawSourceUrl = getGiteaRawSourceUrl(
|
||||
siteConfig.githubRepo,
|
||||
postSourcePath,
|
||||
"git.adclosenn.top",
|
||||
);
|
||||
const postCnbsSourceUrl = getCnbsSourceUrl(
|
||||
"https://cnb.cool/CLN-Grated/blog-fuwari",
|
||||
postSourcePath,
|
||||
);
|
||||
const aiPrompt = `Read from ${postRawSourceUrl} so I can ask questions about it.`;
|
||||
const encodedAiPrompt = encodeURIComponent(aiPrompt);
|
||||
const copyPageAiLinks = [
|
||||
|
||||
Reference in New Issue
Block a user