4.6 KiB
4.6 KiB
Facebook 页面 JSON 契约
源文件必须是一个 JSON 对象,并包含以下七个顶层模块。字段可增加,但不能删除顶层模块。
site
brand、pageTitle、description、searchPlaceholder、feedTitle、feedSort:字符串。currentUser:当前页面账号,包含name、handle、initial、colors(两个#RRGGBB)、composerPrompt、composerPlaceholder。currentUser.stats:数组,每项{ "value": "286", "label": "好友" }。
navigation
top:顶部导航项{label, icon}。primary:左侧主导航项{label, icon, href};个人主页项可设置profile: true。shortcutsTitle、footer:字符串。shortcuts:快捷入口{label, badge, href, colors}。mobile:移动端导航{label, icon},可选action: "composer"或drawer: "messages|notifications"。href只使用页面内锚点,例如#feed、#friends。
可用图标:i-home、i-users、i-video、i-grid、i-message、i-bell、i-bookmark、i-calendar、i-store、i-clock、i-globe、i-circle。
stories
createLabel:创建动态按钮文字。items:0–20 项,每项{name, initial, colors, background}。background只能是story-1至story-5。
posts
items:1–30 条动态;id必须唯一。- 可选
commentUI控制预置评论区:defaultSort:hot(按点赞数、子回复数降序)或latest(保持 JSON 顺序,约定最新在前)。initialVisible、pageSize:1–100 的整数;建议均为10。hotLabel、latestLabel、showMoreLabel、showAllLabel:界面中文文案。
- 每项核心字段:
id、author、initial、colors、verified、time、privacyIcon、text、tags。 metrics:{likes, comments, shares},均为非负数字。comments:0–100 条预置评论。每项至少包含{author, text},建议完整填写id(同一动态内唯一)、author、handle、initial、colors、verified、time、text、likes、replyCount。likes和replyCount为非负数字。- 当预置 50 条热评时,数组必须实际包含 50 个对象,且
metrics.comments >= 50;不能用一条摘要冒充 50 条评论。 - 可选
commentsExpanded:布尔值;需要页面打开后直接展示热评时设为true。 - 可选
sourceUrl:已核验原帖的http(s)链接。不再生成或展示disclosure;旧 JSON 中的该字段会被兼容忽略。 - 可选
media:{ "type": "river", "label": "...", "alt": "..." }{ "type": "market", "label": "...", "alt": "..." }{ "type": "quote", "quote": "...", "attribution": "..." }- 图片:
{ "type": "image", "mediaUrl": "https://.../image.jpg", "alt": "图片说明", "pageUrl": "https://..." }。 - 视频:
{ "type": "video", "mediaUrl": "https://.../video.mp4", "posterUrl": "https://.../cover.jpg", "alt": "视频说明", "pageUrl": "https://..." }。 - 网页:
{ "type": "webpage", "pageUrl": "https://...", "title": "网页标题", "description": "网页摘要", "mediaUrl": "https://.../cover.jpg", "embed": false }。embed: true会尝试在卡片内嵌网页;目标网站拒绝 iframe 时仍可点击链接在新窗口打开。
远程媒体 URL 只接受 http:// 或 https://;图片和视频的 mediaUrl 也可使用对应的 data:image/...、data:video/...。页面会过滤其他协议,所有外链使用 noopener noreferrer。
单帖 + 热评模式
用户要求“某账号发布一条动态,配图,下方 N 条热评”时,posts.items 只放这一条动态;将图片写入该动态的 media,将 N 条评论逐条写入 comments,并设置 commentsExpanded: true。页面默认先显示 commentUI.initialVisible 条,可切换热门/最新、分批查看更多或查看全部。
sidebar
birthday:{title, text}。sponsor:{heading, title, domain, href}。模板只接受安全的页面内锚点;没有赞助内容时写成演示推荐卡,不伪造真实广告。
contacts
title:区块标题。items:0–30 项,每项{name, initial, colors, online}。
inbox
notifications、messages:各 0–30 项。- 每项包含
{name, initial, colors, text, time, unread}。
示例边界
assets/default-data.json是结构起点,不是事实来源。- 合成热评不得写成真实用户原话,也不在帖子内添加情景模拟说明条。
- 颜色必须是完整六位十六进制;无效颜色会被模板回退。
- 所有 JSON 使用双引号,不允许注释、Markdown 围栏或尾逗号。