自定义前端与外链作品卡片
想要独立域名、完全按自己审美定制排版与视觉,同时不想维护任何数据库?或者想在现有的 Hugo、Astro、Hexo、WordPress 个人博客里直接嵌入清爽的跨媒介作品卡片?
1. 一键部署零数据库 Vercel 模板(touched-frontend)
touched-page/touched-frontend(MIT 协议)是官方开源的零数据库前端模板,通过服务端作用域密钥拉取数据——同时兼容 https://touched.page 主站与你自建的 touched-node。
部署步骤
- 准备作用域密钥:
- 对接
touched.page主站:打开https://touched.page/settings→ 扩展与密钥 → 生成一把包含read:self权限的tp_live_...API Key。 - 对接自建
touched-node:直接使用节点.env中的OWNER_KEY(tp_live_...)。
- 对接
- Fork 或直接导入 Vercel:
- 前往
touched-page/touched-frontend,点击 Use this template(或 README 内的一键 Deploy with Vercel 按钮)。
- 前往
- 配置服务端环境变量(严禁添加
NEXT_PUBLIC_等客户端公开前缀):
| 变量名 | 说明 |
|---|---|
TOUCHED_API_KEY | 你的 tp_live_... 密钥或 OWNER_KEY(绝不泄露给浏览器) |
TOUCHED_API_BASE_URL | 主站填 https://touched.page,自建节点填你的节点域名 |
TOUCHED_CACHE_TTL_SECONDS | 可选缓存秒数,默认 30(附带 300s stale-while-revalidate 降级保护) |
部署完成后即可访问 /(我)、/?tab=blog(随笔)、/?tab=library(库)、/posts/:id(单篇阅读)与 /rss.xml,你可以随意魔改每一行模板与样式。
2. 在任意外部博客嵌入 <touched-work-card>
touched-frontend(以及 @touched/widgets 包)内置零依赖浏览器脚本 widgets.browser.js,通过 Shadow DOM 隔离样式注册标准 Web Component <touched-work-card>,不会污染你原有博客的 CSS。
使用示例(Hugo / Astro / Hexo / WordPress / 原生 HTML)
html
<script src="https://your-site.example/widgets.browser.js" defer></script>
<touched-work-card
work-title="极乐迪斯科"
category="game"
rating="5"
tier-label="夯"
status="二周目通关"
note="每段内心的声音都在替你保留一点不肯妥协的尊严。"
cover-url="https://shared.fastly.steamstatic.com/store_item_assets/steam/apps/632470/library_600x900_2x.jpg"
work-url="https://store.steampowered.com/app/632470/"
discuss-url="https://touched.page/works/k7m4p9x2"
></touched-work-card>支持属性一览
| 属性 | 说明 |
|---|---|
work-title | 作品标题 |
category | game · screen · book · audio · other |
rating | 主观五档评分 1–5(可选) |
tier-label | 自定义档位文字(例如 夯、S) |
status | 自由状态文本(例如 二周目通关、追更中 · 卷五) |
note | 代表性短评摘录 |
cover-url | 封面图片地址(默认直接由浏览器加载并带 referrerpolicy="no-referrer") |
work-url | 原平台作品页链接(Steam、豆瓣、Bangumi 等) |
discuss-url | 指向主站或自建节点的作品聚合讨论页链接 |
本地运行与构建
bash
git clone https://github.com/touched-page/touched-frontend.git
cd touched-frontend
cp .env.example .env
pnpm install
pnpm run build:widgets
pnpm dev