一言句子包 · 动画 / 漫画 / 游戏 / 文学 / 诗词 / 网易云 / 哲学 / 抖机灵 等 12 类语录
本项目是一个静态 JSON 数据集,可直接部署到任意静态托管服务(GitHub Pages、Vercel、Cloudflare Pages 等)。
sentences-bundle/
├── categories.json # 分类列表
├── sentences/
│ ├── a.json # 动画
│ ├── b.json # 漫画
│ ├── c.json # 游戏
│ ├── d.json # 文学
│ ├── e.json # 原创
│ ├── f.json # 网络
│ ├── g.json # 其他
│ ├── h.json # 影视
│ ├── i.json # 诗词
│ ├── j.json # 网易云
│ ├── k.json # 哲学
│ └── l.json # 抖机灵
└── index.html # 本页面
通过 categories.json 获取所有分类信息:
GET /categories.json
// 返回值示例
[
{
"id": 1,
"name": "动画",
"desc": "Anime - 动画",
"key": "a",
"path": "./sentences/a.json"
}
]
根据 categories.json 中的 path 字段,直接请求对应 JSON 文件:
GET /sentences/a.json
// 返回值示例(数组)
[
{
"id": 1,
"uuid": "9818ecda-9cbf-4f2a-9af8-8136ef39cfcd",
"hitokoto": "句子内容",
"type": "a",
"from": "作品名",
"from_who": "作者",
"creator": "提交者",
"created_at": "1468605909",
"length": 22
}
]
由于本项目是纯静态 JSON,没有后端随机接口。抽取随机句子的逻辑需要在客户端实现:
async function randomHitokoto() {
// 1. 获取分类列表
const cats = await (await fetch('categories.json')).json();
// 2. 随机选一个分类
const cat = cats[Math.floor(Math.random() * cats.length)];
// 3. 加载该分类全部句子
const list = await (await fetch(cat.path)).json();
// 4. 随机抽一句
const sentence = list[Math.floor(Math.random() * list.length)];
console.log(sentence.hitokoto);
console.log('出自:' + sentence.from);
}
randomHitokoto();
在你的网页中直接引用本仓库的数据:
<!-- 获取动画分类随机一句 -->
<script>
fetch('https://你的域名/sentences/a.json')
.then(r => r.json())
.then(data => {
const s = data[Math.floor(Math.random() * data.length)];
document.body.innerText = s.hitokoto;
});
</script>
如果你部署在 GitHub Pages,地址类似:
https://用户名.github.io/sentences-bundle/sentences/a.json