From db9dc5cc717ace0c3dec4dd9a39d6accfec29ac9 Mon Sep 17 00:00:00 2001 From: Vaica <94612053+zqlit@users.noreply.github.com> Date: Sun, 1 Mar 2026 09:42:39 +0800 Subject: [PATCH] 2026.3.1 --- .github/workflows/deploy.yml | 28 +---- scripts/generate_notification_report.js | 135 ++++++++++++++++++++++++ 2 files changed, 140 insertions(+), 23 deletions(-) create mode 100644 scripts/generate_notification_report.js diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 39b9e487..101ed03d 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -127,6 +127,9 @@ jobs: id: date run: echo "::set-output name=date::$(date +'%Y-%m-%d %H:%M:%S')" + - name: Generate Notification Report + run: node scripts/generate_notification_report.js + - name: Send deployment success notification if: success() uses: dawidd6/action-send-mail@v3 @@ -136,29 +139,8 @@ jobs: secure: true username: ${{ secrets.MAIL_USERNAME }} password: ${{ secrets.MAIL_PASSWORD }} - subject: 部署成功通知 - ${{ github.repository }} + subject: 部署报告 - ${{ steps.date.outputs.date }} to: ${{ secrets.MAIL_USERNAME }} from: GitHub Actions <${{ secrets.MAIL_USERNAME }}> body: | - 🎉 部署已成功完成! - - 📦 仓库信息 - ---------------------------------- - 仓库: ${{ github.repository }} - 分支: ${{ github.ref_name }} - 提交: ${{ github.sha }} - 信息: ${{ github.event.head_commit.message }} - - 👤 触发信息 - ---------------------------------- - 触发人: ${{ github.actor }} - 事件: ${{ github.event_name }} - 工作流: ${{ github.workflow }} - 时间: ${{ steps.date.outputs.date }} - - 🔗 详情链接 - https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} - - 📊 友链监测报告 - ---------------------------------- - ${{ env.LINK_SUMMARY }} + ${{ env.DEPLOY_REPORT }} diff --git a/scripts/generate_notification_report.js b/scripts/generate_notification_report.js new file mode 100644 index 00000000..f6ee8c49 --- /dev/null +++ b/scripts/generate_notification_report.js @@ -0,0 +1,135 @@ +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();