// src/htmlGenerators.js import { escapeHtml, formatDateToChinese, convertEnglishQuotesToChinese} from './helpers.js'; import { dataSources } from './dataFetchers.js'; // Import dataSources function generateHtmlListForContentPage(items, dateStr) { let listHtml = ''; if (!Array.isArray(items) || items.length === 0) { listHtml += `

此日期无可用数据。抓取/筛选过程可能没有为此日期生成任何结果。

`; return listHtml; } listHtml += ''; return listHtml; } export function generateContentSelectionPageHtml(env, dateStr, allData, dataCategories) { // Ensure allData is an object and dataCategories is an array const data = allData || {}; const categories = Array.isArray(dataCategories) ? dataCategories : []; // Generate tab buttons and content dynamically const tabButtonsHtml = categories.map((category, index) => `
`).join(''); const tabContentsHtml = categories.map((category, index) => `
${generateHtmlListForContentPage(data[category.id], dateStr)}
`).join(''); return ` ${formatDateToChinese(escapeHtml(dateStr))} ${env.FOLO_FILTER_DAYS}天内的数据

${formatDateToChinese(escapeHtml(dateStr))} ${env.FOLO_FILTER_DAYS}天内的数据

${tabButtonsHtml}
${tabContentsHtml}
`; } function generatePromptSectionHtmlForGenAI(systemPrompt, userPrompt, promptTitle, promptIdSuffix) { if (!systemPrompt && !userPrompt) return ''; let fullPromptTextForCopy = ""; if (systemPrompt) fullPromptTextForCopy += `系统指令:\n${systemPrompt}\n\n`; if (userPrompt) fullPromptTextForCopy += `用户输入:\n${userPrompt}`; fullPromptTextForCopy = fullPromptTextForCopy.trim(); return `

${escapeHtml(promptTitle)}

`; } export function generateGenAiPageHtml(title, bodyContent, pageDate, isErrorPage = false, selectedItemsForAction = null, systemP1 = null, userP1 = null, systemP2 = null, userP2 = null, promptsMd = null, dailyMd = null, podcastMd = null) { let actionButtonHtml = ''; // Regenerate button for AI Content Summary page if (title.includes('AI日报') && selectedItemsForAction && Array.isArray(selectedItemsForAction) && selectedItemsForAction.length > 0) { actionButtonHtml = `
${selectedItemsForAction.map(item => ``).join('')}
`; } // Regenerate button for AI Podcast Script page else if (title.includes('AI播客') && selectedItemsForAction && Array.isArray(selectedItemsForAction) && selectedItemsForAction.length > 0) { actionButtonHtml = `
${selectedItemsForAction.map(item => ``).join('')}
`; } let githubSaveFormHtml = ''; let generatePodcastButtonHtml = ''; let aiDailyAnalysisButtonHtml = ''; // Since commitToGitHub and genAIPodcastScript are now API calls, // these forms should be handled by JavaScript on the client side. // We will provide the data as hidden inputs for potential client-side use, // but the submission will be via JS fetch, not direct form POST. if (!isErrorPage) { if (title === 'AI日报' && promptsMd && dailyMd) { githubSaveFormHtml = ` `; } else if (title === 'AI播客脚本' && promptsMd && podcastMd) { githubSaveFormHtml = ` `; } } if (title === 'AI日报' && !isErrorPage && podcastMd === null) { // podcastMd === null indicates it's the Call 1 page generatePodcastButtonHtml = `
${selectedItemsForAction.map(item => ``).join('')}
`; aiDailyAnalysisButtonHtml = ` `; } let promptDisplayHtml = ''; if (title === 'AI日报') { if (systemP1 || userP1) { promptDisplayHtml = `

API 调用详情

${generatePromptSectionHtmlForGenAI(convertEnglishQuotesToChinese(systemP1), convertEnglishQuotesToChinese(userP1), '调用 1: 日报', 'call1')}
`; } } else if (title === 'AI播客脚本') { if (systemP2 || userP2) { promptDisplayHtml = `

API 调用详情

${generatePromptSectionHtmlForGenAI(convertEnglishQuotesToChinese(systemP2), convertEnglishQuotesToChinese(userP2), '调用 2: 播客格式化', 'call2')}
`; } } return ` ${escapeHtml(title)}

${escapeHtml(title)}

${generatePodcastButtonHtml} ${aiDailyAnalysisButtonHtml}

所选内容日期: ${formatDateToChinese(escapeHtml(pageDate))}

${bodyContent}
${promptDisplayHtml}
`; }