给 Hexo 增加完整相册体验:网页一键上传照片/视频、密码删除、首页相册前 9 张预览 + 查看全部进独立相册页、空相册自动剔除。
代码与本站(https://Entropyqwe.github.io/gallery)一致,照片/视频上传、删除、独立相册页均实测通过。
| 部分 | 说明 |
|---|---|
| tools/gen_gallery.py | 扫描 source/images/gallery/* 生成 site.data.gallery(含 folder/video;0媒体自动不显示) |
| theme-files/layout/gallery.ejs | 相册首页:每相册前9张预览 + “查看全部” |
| theme-files/layout/album.ejs | 相册独立详情页(全部媒体,灯箱+视频浮层) |
| theme-files/layout/_partials/media-player.ejs | 视频播放浮层 |
| theme-files/scripts/generators/albums.js | 为每个相册生成 /gallery// 详情页 |
| cloudflare-pages/functions/upload.js | /upload 图片/视频入库(校验口令+魔数) |
| cloudflare-pages/functions/delete.js | /delete 按口令删除媒体 |
| install.sh | 一键安装 |
git clone https://github.com/Entropyqwe/hexo-gallery-plugin.git gallery-plugin
cd gallery-plugin
./install.sh /path/to/你的hexo工程 themes/firefly
cp .env.example .env && vi .env # REPO/口令等
./deploy.sh # 部署 /upload /delete 到 Cloudflare Pages
python3 tools/gen_gallery.py # 生成相册数据(可放进你的CI)媒体放置:source/images/gallery/<相册名>/(jpg/png/webp/gif + mp4/webm),可配 _album.yml(下划线开头不会被Hexo复制)写显示名/描述/日期;数据由脚本生成。
主题配置加:
pages: { gallery: true }
upload: { enabled: true, endpoint: "https://<项目>.pages.dev", max_files: 10 }
gallery: { column_width: 240 }页面:source/gallery/index.md(layout: gallery)。
函数运行时环境变量:REPO(源码仓库) / BRANCH / UPLOAD_KEY / GITHUB_TOKEN。
- 上传文件上限:图片≤8MB、视频≤40MB(可在 upload.js 调整)
- 上传后仓库推送触发你的 CI → 相册自动更新;空相册不展示
- 删除/上传口令同一把;PAT 用最小权限