From 82d6341c0081ba6c9cc5aa09ee12397642e783a6 Mon Sep 17 00:00:00 2001 From: rbetree Date: Sun, 4 Jan 2026 21:07:07 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E4=BD=BF=E7=94=A8=20Prettier=20?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E4=BB=A3=E7=A0=81=E9=A3=8E=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 45 +- config/README.md | 100 +- config/_default/pages/articles.yml | 4 +- config/_default/pages/common.yml | 10 +- config/_default/pages/projects.yml | 12 +- config/_default/site.yml | 28 +- config/update-instructions-20251227.md | 11 + scripts/clean.js | 6 +- scripts/sync-articles.js | 159 +- scripts/sync-projects.js | 83 +- src/bookmark-processor.js | 276 +- src/generator.js | 897 ++-- src/helpers/conditions.js | 42 +- src/helpers/formatters.js | 28 +- src/helpers/index.js | 28 +- src/helpers/utils.js | 70 +- src/script.js | 3953 +++++++++-------- test/bookmark-processor.node-test.js | 46 +- test/favicon-url-field-render.node-test.js | 11 +- test/home-page-profile-override.node-test.js | 21 +- test/icons-mode-from-site-yml.node-test.js | 1 - ...-level-sites-external-default.node-test.js | 3 +- test/template-diff-phase1.node-test.js | 100 +- 23 files changed, 3129 insertions(+), 2805 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e4c1b19..4258a0c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,12 +2,12 @@ name: Build and Deploy Site on: push: - branches: [ main ] + branches: [main] workflow_dispatch: schedule: # 定时刷新 RSS / projects 仓库元信息(GitHub Actions 的 cron 使用 UTC 时区) - cron: '0 2 * * *' - + # 设置GITHUB_TOKEN的权限 permissions: contents: write @@ -16,9 +16,9 @@ permissions: # 允许一个并发部署 concurrency: - group: "pages" + group: 'pages' cancel-in-progress: true - + jobs: build_and_deploy: runs-on: ubuntu-latest @@ -27,19 +27,19 @@ jobs: uses: actions/checkout@v4 # 使用persist-credentials: false,以便后续步骤可以使用自定义的提交者 with: - persist-credentials: false + persist-credentials: false fetch-depth: 0 # 获取所有历史记录以进行diff检查 - + - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '18' cache: 'npm' - + - name: Install dependencies run: npm ci - - # --- 书签处理步骤 --- + + # --- 书签处理步骤 --- - name: Check for bookmark HTML files id: check_bookmark_files run: | @@ -50,7 +50,7 @@ jobs: echo "found=false" >> $GITHUB_OUTPUT echo "No bookmark HTML files found, skipping bookmark processing." fi - + - name: Process bookmark files if: steps.check_bookmark_files.outputs.found == 'true' env: @@ -58,7 +58,7 @@ jobs: run: | echo "Processing bookmark files..." node src/bookmark-processor.js - + - name: Debug directory contents if: steps.check_bookmark_files.outputs.found == 'true' run: | @@ -77,13 +77,13 @@ jobs: else echo "✗ config/user/pages directory does not exist" fi - + - name: Commit bookmark configuration changes if: steps.check_bookmark_files.outputs.found == 'true' run: | git config --local user.email "action@github.com" git config --local user.name "GitHub Action (Bookmarks)" - + # Check if config/user/pages/bookmarks.yml exists if [ -f config/user/pages/bookmarks.yml ]; then # Check if this is a new file or it has changes @@ -117,7 +117,7 @@ jobs: echo "Current directory contents:" ls -la config/user/pages/ || echo "Directory does not exist" fi - + - name: Clean up processed bookmark files if: steps.check_bookmark_files.outputs.found == 'true' run: | @@ -153,7 +153,6 @@ jobs: echo "No HTML files found to clean up." fi # --- 书签处理步骤结束 --- - - name: Push configuration changes (if any) # 只有在书签处理步骤修改了文件时才推送 # 使用 GITHUB_TOKEN 推送 @@ -161,7 +160,7 @@ jobs: run: | echo "Checking git status before pushing..." git status - + echo "Checking config/user/pages directory before pushing..." if [ -d config/user/pages ]; then echo "✓ config/user/pages directory exists" @@ -169,11 +168,11 @@ jobs: else echo "✗ WARNING: config/user/pages directory does not exist before pushing!" fi - + echo "Pushing changes to repository..." git push "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" HEAD:${{ github.ref_name }} env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # --- 网站构建和部署步骤 --- # 同步时效性数据(best-effort):projects 仓库信息、articles RSS 聚合 @@ -188,7 +187,7 @@ jobs: - name: Build site (clean dist + generate) run: npm run build - + - name: Check favicon run: | if [ -f dist/favicon.ico ]; then @@ -199,15 +198,15 @@ jobs: # 暂时改为警告,避免因为图标问题阻止部署 # exit 1 fi - + - name: Setup Pages uses: actions/configure-pages@v4 - + - name: Upload artifact uses: actions/upload-pages-artifact@v3 with: path: 'dist' - + - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@v4 + uses: actions/deploy-pages@v4 diff --git a/config/README.md b/config/README.md index 366cf21..426766c 100644 --- a/config/README.md +++ b/config/README.md @@ -117,13 +117,13 @@ MeNav 配置系统采用“完全替换”策略(不合并),按以下优 - 示例: ```yml sites: - - name: "Ant Design" - url: "https://ant.design/" - icon: "fas fa-th" - forceIconMode: manual # 强制使用手动图标,绕过 favicon 默认"地球"图标 - - name: "Example" - url: "https://example.com/" - faviconUrl: "https://example.com/favicon.png" # 单站点自定义 favicon + - name: 'Ant Design' + url: 'https://ant.design/' + icon: 'fas fa-th' + forceIconMode: manual # 强制使用手动图标,绕过 favicon 默认"地球"图标 + - name: 'Example' + url: 'https://example.com/' + faviconUrl: 'https://example.com/favicon.png' # 单站点自定义 favicon ``` 3. **安全策略(链接白名单)** @@ -254,46 +254,46 @@ MeNav 配置系统采用“完全替换”策略:只会选择一套目录加 ```yaml # 网站基本信息 -title: "我的个人导航" -description: "个人收藏的网站导航页" -keywords: "导航,网址,书签,个人主页" +title: '我的个人导航' +description: '个人收藏的网站导航页' +keywords: '导航,网址,书签,个人主页' # 个人资料配置 profile: - title: "个人导航站" - subtitle: "我收藏的精选网站" + title: '个人导航站' + subtitle: '我收藏的精选网站' # 字体:全站基础字体 fonts: source: css - cssUrl: "https://fontsapi.zeoseven.com/292/main/result.css" + cssUrl: 'https://fontsapi.zeoseven.com/292/main/result.css' preload: true - family: "LXGW WenKai" + family: 'LXGW WenKai' weight: normal - + # 社交媒体链接 social: - - name: "GitHub" - url: "https://github.com/username" - icon: "fab fa-github" - - name: "Twitter" - url: "https://twitter.com/username" - icon: "fab fa-twitter" + - name: 'GitHub' + url: 'https://github.com/username' + icon: 'fab fa-github' + - name: 'Twitter' + url: 'https://twitter.com/username' + icon: 'fab fa-twitter' # 导航配置 navigation: - - name: "常用" - icon: "fas fa-star" - id: "common" - - name: "项目" - icon: "fas fa-project-diagram" - id: "projects" - - name: "文章" - icon: "fas fa-book" - id: "articles" - - name: "书签" - icon: "fas fa-bookmark" - id: "bookmarks" + - name: '常用' + icon: 'fas fa-star' + id: 'common' + - name: '项目' + icon: 'fas fa-project-diagram' + id: 'projects' + - name: '文章' + icon: 'fas fa-book' + id: 'articles' + - name: '书签' + icon: 'fas fa-bookmark' + id: 'bookmarks' ``` ### 通用页面配置示例(例如 common.yml) @@ -301,25 +301,25 @@ navigation: ```yaml # 页面分类配置 categories: - - name: "常用工具" - icon: "fas fa-tools" + - name: '常用工具' + icon: 'fas fa-tools' sites: - - name: "Google" - url: "https://www.google.com" - description: "全球最大的搜索引擎" - icon: "fab fa-google" - - name: "GitHub" - url: "https://github.com" - description: "代码托管平台" - icon: "fab fa-github" - - - name: "学习资源" - icon: "fas fa-graduation-cap" + - name: 'Google' + url: 'https://www.google.com' + description: '全球最大的搜索引擎' + icon: 'fab fa-google' + - name: 'GitHub' + url: 'https://github.com' + description: '代码托管平台' + icon: 'fab fa-github' + + - name: '学习资源' + icon: 'fas fa-graduation-cap' sites: - - name: "MDN Web Docs" - url: "https://developer.mozilla.org" - description: "Web开发技术文档" - icon: "fab fa-firefox-browser" + - name: 'MDN Web Docs' + url: 'https://developer.mozilla.org' + description: 'Web开发技术文档' + icon: 'fab fa-firefox-browser' ``` ## 最佳实践 diff --git a/config/_default/pages/articles.yml b/config/_default/pages/articles.yml index 88cff92..de15291 100644 --- a/config/_default/pages/articles.yml +++ b/config/_default/pages/articles.yml @@ -1,7 +1,7 @@ # 默认页面配置(请勿直接修改)。 # 建议复制到 config/user/pages/articles.yml 并按需调整。 -title: 技术文章 # 页面标题 -subtitle: RSS 聚合文章列表 # 页面副标题 +title: 技术文章 # 页面标题 +subtitle: RSS 聚合文章列表 # 页面副标题 # 指定使用的模板文件名,现有页面模板可见 templates/pages(不含 .hbs) template: articles diff --git a/config/_default/pages/common.yml b/config/_default/pages/common.yml index bbb96d0..53da6c3 100644 --- a/config/_default/pages/common.yml +++ b/config/_default/pages/common.yml @@ -1,7 +1,7 @@ # 默认页面配置(请勿直接修改)。 # 建议复制到 config/user/pages/common.yml 并按需调整。 -title: 常用网站 # 页面标题 -subtitle: Common website # 页面副标题 +title: 常用网站 # 页面标题 +subtitle: Common website # 页面副标题 # 指定使用的模板文件名,现有页面模板可见 templates/pages(不含 .hbs) # 说明:推荐使用通用模板 page;首页由“导航第一项”决定 @@ -12,9 +12,9 @@ categories: - name: 置顶 icon: fas fa-star # 分类图标 sites: - - name: Linux.do # 站点名称 - url: https://linux.do/ # http/https URL(favicon 模式将尝试加载站点图标) - icon: fab fa-linux # 手动图标:manual 模式使用;favicon 模式下作为回退 + - name: Linux.do # 站点名称 + url: https://linux.do/ # http/https URL(favicon 模式将尝试加载站点图标) + icon: fab fa-linux # 手动图标:manual 模式使用;favicon 模式下作为回退 description: 新的理想型社区 # 站点描述 - name: Menav url: https://rbetree.github.io/menav diff --git a/config/_default/pages/projects.yml b/config/_default/pages/projects.yml index dafc8c4..0791d07 100644 --- a/config/_default/pages/projects.yml +++ b/config/_default/pages/projects.yml @@ -1,7 +1,7 @@ # 默认页面配置(请勿直接修改)。 # 建议复制到 config/user/pages/projects.yml 并按需调整。 -title: 项目 # 页面标题 -subtitle: 项目展示 # 页面副标题 +title: 项目 # 页面标题 +subtitle: 项目展示 # 页面副标题 # 指定使用的模板文件名,现有页面模板可见 templates/pages(不含 .hbs) template: projects @@ -14,20 +14,20 @@ template: projects # - `npm run build` 默认不联网;缓存缺失时卡片仅展示标题与描述 categories: - name: 个人项目 - icon: fas fa-code # 分类图标(Font Awesome) + icon: fas fa-code # 分类图标(Font Awesome) sites: - name: MeNav - icon: fab fa-github # 手动图标(manual 模式显示;favicon 模式下作为回退) + icon: fab fa-github # 手动图标(manual 模式显示;favicon 模式下作为回退) description: 一键部署的个人导航站生成器,支持书签导入与自动构建,轻松整理展示您的网络收藏 # 站点描述 url: https://github.com/rbetree/menav - name: MarksVault icon: fab fa-github description: 一个强大的浏览器扩展,用于智能管理、整理和安全备份您的书签数据 - url: "https://github.com/rbetree/MarksVault" + url: 'https://github.com/rbetree/MarksVault' - name: star icon: fas fa-star sites: - name: CLIProxyAPI icon: fab fa-github description: Wrap Gemini CLI, Antigravity, ChatGPT Codex, Claude Code, Qwen Code, iFlow as an OpenAI/Gemini/Claude/Codex compatible API service, allowing you to enjoy the free Gemini 2.5 Pro, GPT 5, Claude, Qwen model through API - url: "https://github.com/router-for-me/CLIProxyAPI" + url: 'https://github.com/router-for-me/CLIProxyAPI' diff --git a/config/_default/site.yml b/config/_default/site.yml index 1bfa508..cfa0658 100644 --- a/config/_default/site.yml +++ b/config/_default/site.yml @@ -41,7 +41,7 @@ security: # - system: 只使用本地/系统字体,不额外发起请求 fonts: source: css - cssUrl: "https://fontsapi.zeoseven.com/292/main/result.css" + cssUrl: 'https://fontsapi.zeoseven.com/292/main/result.css' preload: true # 可选:使用 preload+onload 的方式非阻塞加载字体 CSS(更利于首屏性能) family: LXGW WenKai weight: normal @@ -67,23 +67,23 @@ rss: enabled: true cacheDir: dev fetch: - timeoutMs: 10000 # 单请求超时(毫秒) - totalTimeoutMs: 60000 # 全流程总超时(毫秒) - concurrency: 5 # 并发抓取站点数 - maxRetries: 1 # 单站点重试次数(best-effort) - maxRedirects: 3 # 最大重定向次数 + timeoutMs: 10000 # 单请求超时(毫秒) + totalTimeoutMs: 60000 # 全流程总超时(毫秒) + concurrency: 5 # 并发抓取站点数 + maxRetries: 1 # 单站点重试次数(best-effort) + maxRedirects: 3 # 最大重定向次数 articles: - perSite: 8 # 单站点最多抓取条数 - total: 50 # 全站聚合上限 - summaryMaxLength: 200 # 摘要最大长度(字符) + perSite: 8 # 单站点最多抓取条数 + total: 50 # 全站聚合上限 + summaryMaxLength: 200 # 摘要最大长度(字符) # GitHub:用于 projects 页面右侧“贡献热力图”(可选) # - username:你的 GitHub 用户名(例如 torvalds) # - heatmapColor:热力图主题色(不带 #,例如 339af0) github: - username: "rbetree" # 你的 GitHub 用户名(例如 torvalds;为空则 projects 页不展示热力图) + username: 'rbetree' # 你的 GitHub 用户名(例如 torvalds;为空则 projects 页不展示热力图) heatmapColor: 339af0 - cacheDir: dev # projects 仓库元信息缓存目录(默认 dev,仓库默认 gitignore) + cacheDir: dev # projects 仓库元信息缓存目录(默认 dev,仓库默认 gitignore) # 社交媒体链接:显示在侧边栏底部;可按需增删 social: @@ -102,9 +102,9 @@ social: # 导航配置(顺序第一项即首页/默认打开页) navigation: - - name: 常用 # 菜单名称 - icon: fas fa-star # Font Awesome 图标类 - id: common # 页面标识符(唯一,需与 pages/.yml 对应) + - name: 常用 # 菜单名称 + icon: fas fa-star # Font Awesome 图标类 + id: common # 页面标识符(唯一,需与 pages/.yml 对应) - name: 项目 icon: fas fa-project-diagram id: projects diff --git a/config/update-instructions-20251227.md b/config/update-instructions-20251227.md index 6f9bc84..f4d6598 100644 --- a/config/update-instructions-20251227.md +++ b/config/update-instructions-20251227.md @@ -13,12 +13,14 @@ 用途:为 `articles` 页面提供 RSS/Atom 文章聚合数据,供 `npm run sync-articles` 联网抓取并写入缓存;`npm run build` 默认不联网,只读取缓存渲染。 关键字段(默认示例见 `config/_default/site.yml`): + - `site.rss.enabled`:是否启用 RSS 抓取能力 - `site.rss.cacheDir`:缓存目录(建议 `dev/`,仓库默认 gitignore) - `site.rss.fetch.*`:抓取参数(超时、并发、重试、重定向等) - `site.rss.articles.*`:抓取条数与摘要长度(例如每站点最多 8 篇) 说明: + - RSS 抓取只影响 `articles` Phase 2(文章条目只读展示),不会影响扩展对“来源站点(sites)”的写回能力(构建会保留影子写回结构)。 --- @@ -26,15 +28,18 @@ ### 1.2 `site.github.*`(projects 仓库元信息 + 热力图) 用途: + - projects 卡片可展示仓库元信息(language/stars/forks 等,只读),由 `npm run sync-projects` 联网抓取并写入缓存。 - projects 标题区右侧可选展示 GitHub 贡献热力图。 关键字段(默认示例见 `config/_default/site.yml`): + - `site.github.username`:GitHub 用户名;为空则不展示热力图 - `site.github.heatmapColor`:热力图主题色(不带 `#`,如 `339af0`) - `site.github.cacheDir`:仓库元信息缓存目录(建议 `dev/`) 说明: + - 仓库元信息来自 GitHub API,属于“时效性数据”,不会写回到 `pages/projects.yml`。 --- @@ -44,6 +49,7 @@ 用途:指定页面使用的模板(对应 `templates/pages/