const fs = require('fs'); const path = require('path'); const matter = require('gray-matter'); const FRIEND_CIRCLE_PATH = path.join(__dirname, '../themes/Ying/static/json/friend_circle_data.json'); const LINK_SUMMARY_PATH = path.join(__dirname, '../failed_links_summary.txt'); const POSTS_DIR = path.join(__dirname, '../content/post'); const BASE_URL = "https://usj.cc"; // Helper to format date as YYYYMMDD function formatDateYYYYMMDD(date) { const y = date.getFullYear(); const m = String(date.getMonth() + 1).padStart(2, '0'); const d = String(date.getDate()).padStart(2, '0'); return `${y}${m}${d}`; } // Helper to get latest post from content/post function getLatestPost() { try { if (!fs.existsSync(POSTS_DIR)) return null; let latestFile = null; let latestDate = new Date(0); function scanDir(dir) { const files = fs.readdirSync(dir); for (const file of files) { const fullPath = path.join(dir, file); const stat = fs.statSync(fullPath); if (stat.isDirectory()) { scanDir(fullPath); } else if (file.endsWith('.md')) { // Try to read frontmatter date try { const content = fs.readFileSync(fullPath, 'utf8'); const parsed = matter(content); if (parsed.data.date) { const date = new Date(parsed.data.date); // Only consider posts that are NOT hidden if (parsed.data.status !== 'hidden' && parsed.data.draft !== true) { if (date > latestDate) { latestDate = date; latestFile = { title: parsed.data.title || file.replace('.md', ''), date: date, // Construct URL based on hugo.toml: /:year:month:day.html url: `${BASE_URL}/${formatDateYYYYMMDD(date)}.html` }; } } } } catch (e) { // Ignore parsing errors } } } } scanDir(POSTS_DIR); return latestFile; } catch (e) { console.error('Error finding latest post:', e); return null; } } async function main() { let report = ""; // 1. ζœ€ζ–°ζ–‡η«  const latestPost = getLatestPost(); if (latestPost) { report += `### πŸ“ ζœ€ζ–°ζ–‡η« \n`; const dateStr = latestPost.date.toLocaleDateString(); report += `- [${latestPost.title}](${latestPost.url}) (${dateStr})\n`; report += `\n`; } else { report += `### πŸ“ ζœ€ζ–°ζ–‡η« \n(ζœͺζ‰Ύεˆ°ε…¬εΌ€ζ–‡η« )\n\n`; } // 2. 友链检桋 try { if (fs.existsSync(LINK_SUMMARY_PATH)) { const linkSummary = fs.readFileSync(LINK_SUMMARY_PATH, 'utf8').trim(); report += `### πŸ”— 友链检桋\n`; report += `${linkSummary}\n\n`; } else { report += `### πŸ”— 友链检桋\n(ζ— ζ£€ζ΅‹η»“ζžœ)\n\n`; } } catch (e) { console.error("Error reading link summary:", e); } // 3. θΏ‘δΈ‰ε€©ζœ‹ε‹εœˆ try { if (fs.existsSync(FRIEND_CIRCLE_PATH)) { const data = JSON.parse(fs.readFileSync(FRIEND_CIRCLE_PATH, 'utf8')); const threeDaysAgo = new Date(); threeDaysAgo.setDate(threeDaysAgo.getDate() - 3); const recentPosts = data.posts.filter(post => new Date(post.date) > threeDaysAgo); report += `### πŸ‘₯ ζœ‹ε‹εœˆθΏ‘ε†΅ (θΏ‘3倩)\n`; if (recentPosts.length > 0) { // Limit to top 10 to avoid too long email const limitedPosts = recentPosts.slice(0, 10); limitedPosts.forEach(post => { const dateStr = new Date(post.date).toLocaleDateString(); report += `- [${post.author}] [${post.title}](${post.link}) (${dateStr})\n`; }); if (recentPosts.length > 10) { report += `... δ»₯εŠε…Άδ»– ${recentPosts.length - 10} η―‡\n`; } } else { report += `ζ— ζ›΄ζ–°\n`; } report += `\n`; } } catch (e) { console.error("Error reading friend circle data:", e); } // Output to stdout for debugging console.log(report); // Output to GITHUB_ENV if running in Actions if (process.env.GITHUB_ENV) { const delimiter = `EOF_${Math.random().toString(36).substr(2, 9)}`; fs.appendFileSync(process.env.GITHUB_ENV, `DEPLOY_REPORT<<${delimiter}\n${report}\n${delimiter}\n`); } } main();