mirror of
https://github.com/Ad-closeNN/blog-fuwari.git
synced 2026-05-31 01:20:06 -04:00
fix(summary): 修复 AI 摘要脚本删除 ::: 标记和换行符不一致
- bodyContent 不再写回文件,避免 ::: admonition 被 strip - 写文件时检测原文换行符(CRLF/LF),避免混用 - 换用 deepseek-v4-flash-free 免费模型 Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
+8
-8
@@ -6,7 +6,7 @@ import https from "https"
|
|||||||
import readline from "readline"
|
import readline from "readline"
|
||||||
|
|
||||||
const targetDir = "./src/content/posts/"
|
const targetDir = "./src/content/posts/"
|
||||||
const summaryModel = "gpt-5-nano"
|
const summaryModel = "deepseek-v4-flash-free"
|
||||||
const batchDelayMs = 1500
|
const batchDelayMs = 1500
|
||||||
const frontmatterRegex = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/
|
const frontmatterRegex = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/
|
||||||
|
|
||||||
@@ -274,11 +274,11 @@ async function generateSummary(fileName) {
|
|||||||
const fullPath = path.join(targetDir, fileName)
|
const fullPath = path.join(targetDir, fileName)
|
||||||
const fileContent = fs.readFileSync(fullPath, "utf-8")
|
const fileContent = fs.readFileSync(fullPath, "utf-8")
|
||||||
const frontmatterMatch = fileContent.match(frontmatterRegex)
|
const frontmatterMatch = fileContent.match(frontmatterRegex)
|
||||||
const bodyContent = stripAdmonitionMarkers(
|
const bodyOriginal = frontmatterMatch
|
||||||
frontmatterMatch
|
|
||||||
? fileContent.slice(frontmatterMatch[0].length).trimStart()
|
? fileContent.slice(frontmatterMatch[0].length).trimStart()
|
||||||
: fileContent,
|
: fileContent;
|
||||||
)
|
const bodyForAI = stripAdmonitionMarkers(bodyOriginal)
|
||||||
|
const eol = fileContent.includes("\r\n") ? "\r\n" : "\n"
|
||||||
|
|
||||||
console.log("\n生成 AI 摘要中...\n")
|
console.log("\n生成 AI 摘要中...\n")
|
||||||
|
|
||||||
@@ -293,7 +293,7 @@ async function generateSummary(fileName) {
|
|||||||
- 不要输出 Markdown 语法、admonition 标记或提示框类型,例如 :::warning、:::caution、[!warning]、警告、注意。
|
- 不要输出 Markdown 语法、admonition 标记或提示框类型,例如 :::warning、:::caution、[!warning]、警告、注意。
|
||||||
|
|
||||||
文章内容:
|
文章内容:
|
||||||
${bodyContent}`
|
${bodyForAI}`
|
||||||
|
|
||||||
const requestBody = JSON.stringify({
|
const requestBody = JSON.stringify({
|
||||||
model: summaryModel,
|
model: summaryModel,
|
||||||
@@ -349,9 +349,9 @@ ${bodyContent}`
|
|||||||
summaryModel,
|
summaryModel,
|
||||||
)
|
)
|
||||||
|
|
||||||
newContent = `---\n${newFrontmatter}\n---\n${bodyContent}`
|
newContent = `---${eol}${newFrontmatter}${eol}---${eol}${bodyOriginal}`
|
||||||
} else {
|
} else {
|
||||||
newContent = `---\n${formatFrontmatterField("aiSummary", summary)}\n${formatFrontmatterField("aiSummaryModel", summaryModel)}\n---\n${bodyContent}`
|
newContent = `---${eol}${formatFrontmatterField("aiSummary", summary)}${eol}${formatFrontmatterField("aiSummaryModel", summaryModel)}${eol}---${eol}${bodyOriginal}`
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.writeFileSync(fullPath, newContent)
|
fs.writeFileSync(fullPath, newContent)
|
||||||
|
|||||||
Reference in New Issue
Block a user