Global “Like / Stomp” Widget—GitHub ISSUE + Vercel Func
Real-Time Reactions
对于任何 hexo blog, 基于 Github+Vercel 实现 global 计数同步小组件!!
这里,Github Issue 作为我们的轻量级数据库,正文以 {}
开头,我们在其中存储一个小的 JSON 对象,
将每个 widget 的 Key(例如 "wb-p1"
)映射到它的总计数
而 Vercel 作用是什么呢? 我们使用 Vercel 在 /api/vote
处托管了一个微小的无服务器功能,该功能面向 GitHub Issue。
将 GitHub PAT 作为环境变量输入,处理 CORS "跨域资源共享 (Cross-origin resource sharing)",当浏览器调用 GET /api/vote?key=…
时,Vercel 就会获取并返回 JSON 更新 ISSUE (即计数总量)。
Setup in 3 Steps ▼
- GitHub — create Issue
__VOTES__
, body{}
, note its number.
Generate a PAT withpublic_repo
scope. - Backend repo + Vercel — import, add env var
GH_TOKEN
, dropapi/vote.js
. - Hexo page — paste the vote widget (below) into any post.
hexo clean && hexo g -d
→ counts sync globally.
Demo Widget
Click 👍 or 👎 — open this page in two tabs to prove global sync.
0
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.