From 09793ceab93ef0aa1f2760cc64a1ea6ef8af1b5f Mon Sep 17 00:00:00 2001 From: justlovemaki <274166795@qq.com> Date: Sun, 29 Jun 2025 13:25:33 +0800 Subject: [PATCH] =?UTF-8?q?feat(helpers):=20=E6=B7=BB=E5=8A=A0=E4=B8=9C12?= =?UTF-8?q?=E6=97=B6=E5=8C=BA=E6=97=A5=E6=9C=9F=E6=A0=BC=E5=BC=8F=E5=8C=96?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E5=B9=B6=E6=9B=B4=E6=96=B0=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refactor(handlers): 修改文章链接格式为年/月/日结构并统一使用东12时区时间 docs: 更新Markdown标题级别和收听语音版标题 --- src/foot.js | 2 +- src/handlers/commitToGitHub.js | 8 +++++--- src/handlers/genAIContent.js | 4 ++-- src/handlers/writeRssData.js | 10 ++++++---- src/helpers.js | 17 +++++++++++++++++ 5 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/foot.js b/src/foot.js index de6bf20..b010820 100644 --- a/src/foot.js +++ b/src/foot.js @@ -3,7 +3,7 @@ export function insertFoot() { --- -#### **收听语音版** +## **收听语音版AI日报** | 🎙️ **小宇宙** | 📹 **抖音** | | --- | --- | diff --git a/src/handlers/commitToGitHub.js b/src/handlers/commitToGitHub.js index 6f113c7..c231df7 100644 --- a/src/handlers/commitToGitHub.js +++ b/src/handlers/commitToGitHub.js @@ -1,5 +1,5 @@ // src/handlers/commitToGitHub.js -import { getISODate, formatMarkdownText, replaceImageProxy,formatDateToGMT0WithTime, sleep } from '../helpers.js'; +import { getISODate, formatMarkdownText, replaceImageProxy,formatDateToGMT12WithTime } from '../helpers.js'; import { getGitHubFileSha, createOrUpdateGitHubFile } from '../github.js'; import { storeInKV } from '../kv.js'; import { marked } from '../marked.esm.js'; @@ -13,13 +13,15 @@ export async function handleCommitToGitHub(request, env) { const dateStr = formData.get('date') || getISODate(); const dailyMd = formData.get('daily_summary_markdown'); const podcastMd = formData.get('podcast_script_markdown'); + // 从 "YYYY-MM-DD" 格式的 dateStr 中提取 "YYYY-MM" + const yearMonth = dateStr.substring(0, 7); const report = { report_date: dateStr, title: dateStr+'日刊', - link: '/daily/'+dateStr+'.html', + link: '/'+yearMonth+'/'+dateStr+'/', content_html: null, // 可以添加其他相關欄位,例如作者、來源等 - published_date: formatDateToGMT0WithTime(new Date()) // 記錄保存時間 + published_date: formatDateToGMT12WithTime(new Date()) // 記錄保存時間 } const filesToCommit = []; diff --git a/src/handlers/genAIContent.js b/src/handlers/genAIContent.js index ee1d6c2..1ba9646 100644 --- a/src/handlers/genAIContent.js +++ b/src/handlers/genAIContent.js @@ -253,7 +253,7 @@ export async function handleGenAIContent(request, env) { if (fullPromptForCall2_System) promptsMarkdownContent += `### System Instruction\n\`\`\`\n${fullPromptForCall2_System}\n\`\`\`\n\n`; if (fullPromptForCall2_User) promptsMarkdownContent += `### User Input (Output of Call 1)\n\`\`\`\n${fullPromptForCall2_User}\n\`\`\`\n\n`; - let dailySummaryMarkdownContent = `# ${env.DAILY_TITLE} ${formatDateToChinese(dateStr)}` + '\n\n'; + let dailySummaryMarkdownContent = `## ${env.DAILY_TITLE} ${formatDateToChinese(dateStr)}` + '\n\n'; dailySummaryMarkdownContent += '> '+ env.DAILY_TITLE_MIN + '\n\n'; let outputOfCall3 = null; console.log("Call 3 to Chat (Processing Call 2 Output): User prompt length:", outputOfCall2.length); @@ -271,7 +271,7 @@ export async function handleGenAIContent(request, env) { const errorHtml = generateGenAiPageHtml(env, '生成AI日报出错(摘要)', `

Failed during processing of summarized content: ${escapeHtml(error.message)}

${error.stack ? `
${escapeHtml(error.stack)}
` : ''}`, dateStr, true, selectedItemsParams, fullPromptForCall1_System, fullPromptForCall1_User, fullPromptForCall2_System, fullPromptForCall2_User); return new Response(errorHtml, { status: 500, headers: { 'Content-Type': 'text/html; charset=utf-8' } }); } - dailySummaryMarkdownContent += '\n\n#### **AI内容摘要**\n\n```\n' + outputOfCall3 + '\n```\n\n'; + dailySummaryMarkdownContent += '\n\n### **AI内容摘要**\n\n```\n' + outputOfCall3 + '\n```\n\n'; dailySummaryMarkdownContent += `\n\n${removeMarkdownCodeBlock(outputOfCall2)}`; if (env.INSERT_FOOT=='true') dailySummaryMarkdownContent += insertFoot() +`\n\n`; diff --git a/src/handlers/writeRssData.js b/src/handlers/writeRssData.js index 5729ad1..5678847 100644 --- a/src/handlers/writeRssData.js +++ b/src/handlers/writeRssData.js @@ -1,4 +1,4 @@ -import { replaceImageProxy, formatDateToGMT0WithTime } from '../helpers.js'; +import { replaceImageProxy, formatMarkdownText, formatDateToGMT12WithTime } from '../helpers.js'; import { getDailyReportContent } from '../github.js'; import { storeInKV } from '../kv.js'; import { marked } from '../marked.esm.js'; @@ -18,15 +18,17 @@ export async function handleWriteRssData(request, env) { return new Response(`No content found for ${path}`, { status: 404 }); } + // 从 "YYYY-MM-DD" 格式的 dateStr 中提取 "YYYY-MM" + const yearMonth = dateStr.substring(0, 7); const report = { report_date: dateStr, title: dateStr+'日刊', - link: '/daily/'+dateStr+'.html', + link: '/'+yearMonth+'/'+dateStr+'/', content_html: null, // 可以添加其他相關欄位,例如作者、來源等 - published_date: formatDateToGMT0WithTime(new Date()) // 記錄保存時間 + published_date: formatDateToGMT12WithTime(new Date()) // 記錄保存時間 } - report.content_html = marked.parse(replaceImageProxy(env.IMG_PROXY, content)); + report.content_html = marked.parse(formatMarkdownText(replaceImageProxy(env.IMG_PROXY, content))); storeInKV(env.DATA_KV, `${dateStr}-report`, report); return new Response(JSON.stringify(report), { diff --git a/src/helpers.js b/src/helpers.js index e47c306..ca9445e 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -257,6 +257,23 @@ export function formatRssDate(date) { return new Intl.DateTimeFormat('zh-CN', options).format(date); } + export function formatDateToGMT12WithTime(isoDateString) { + if (!isoDateString) return ''; + const date = new Date(isoDateString); + const options = { + year: 'numeric', + month: 'numeric', + day: 'numeric', + hour: '2-digit', + minute: '2-digit', + second: '2-digit', + hour12: false, // 使用24小时制 + timeZone: 'Asia/Kamchatka'// 指定东12时区 + }; + // 使用 'zh-CN' 语言环境以确保中文格式 + return new Intl.DateTimeFormat('zh-CN', options).format(date); +} + /** * Converts English double quotes (") to Chinese double quotes (“”). * @param {string} text - The input string.