一种从Trello API获取数据并将其作为静态JSON 文件存储在本地的工具。
借助Tresor,您可以将 Trello 用作编辑 UI 和内容管理系统。它将 Trello 列表转换为一组静态 JSON 文件,准备用作静态网站的 API。
这是构建您的下一个 JAMstack 项目的工具,允许您的代码库完全静态且无服务器,而且还具有内容管理系统的优势,因为您的网站将在内容更改时自动更新。静态文件代码库可以完全托管在 CDN 上,从而降低基础设施成本并提高性能和可用性。
Trello 提供了一个非常简单的UI 和一个设计良好的 API,具有管理小型静态网站、博客或单页应用程序背后的内容所需的所有功能:
Tresor 读取 Trello API 并将结果本地保存为静态 JSON 文件,保存在允许将数据作为 HTTP API 端点使用的文件夹结构中。静态文件可以复制到客户端构建文件夹中,也可以托管在其他地方(CDN、Github Pages、Netlify 等),以便客户端可以以 RESTful 方式使用数据。
设置持续交付后,就可以配置 Webhook 以在 API 提供的内容发生更改时触发新的构建。
(使用 npx 跳过此步)
要求:
跑步:
npm install tresor要求:
{"name":"Public","id":"5b193b1a8a23ebb893ab7a02"}您可以将 API 密钥、API 令牌、列表 ID 和任何其他选项传递为:
config.json文件的属性运行以下命令下载 JSON 文件:
tresor将配置选项作为环境变量传递:
API__KEY=asenoiuwqeWNEUfnewoeFNWQetr3295023rer API__TOKEN=ASnqoiwqenmNEWOIWNrffnklef3io2r032rnewfoid3T439543 API__LIST=124f9hue2983232rj32052s tresor或作为命令行参数:
tresor --api.key=asenoiuwqeWNEUfnewoeFNWQetr3295023rer --api.token=ASnqoiwqenmNEWOIWNrffnklef3io2r032rnewfoid3T439543 --api.list=124f9hue2983232rj32052s您可以添加到config.json文件或通过命令行/环境变量传递的选项有:
| 姓名 | 描述 | 默认 |
|---|---|---|
| api.url | 基本 API 网址 | "https://api.trello.com/1/" |
| api.key | API 密钥(必需) | |
| api.token | API 令牌(必需) | |
| api.list | 要观看的 trello 列表的 ID(作为数组)(必需) | |
| 目标根 | 保存所有JSON文件的文件夹 | "static/" |
| 目的地全部 | 包含所有条目的 JSON 文件名 | "all.json" |
| 目标标签 | 包含所有标签的 JSON 文件名 | "tags.json" |
| 目的地邮局 | 保存所有单个帖子的文件夹名称 | "post" |
| 目的地标签 | 保存所有单个标签的文件夹名称 | "tag" |
| 目标图像 | 将存储所有图像的文件夹名称 | false (不下载图像) |
| 字段.字段 | 要显示的帖子字段 | ["id", "name", "dateLastActivity", "desc", "idList", "labels"] |
| 字段.成员 | 显示或不显示用户信息(真或假) | true |
| fields.member_fields | 要显示的用户字段 | ["fullName", "bio"] |
| 字段.附件 | 显示或不显示附件信息(真或假) | true |
| fields.attachment_fields | 要显示的附件字段 | ["previews", "url"] |
| pagination.entriesPerPage | 单个 JSON 中的条目数 | 20 |
默认的config.json文件如下所示:
{
"api" : {
"url" : " https://api.trello.com/1/ "
},
"dest" : {
"root" : " static " ,
"all" : " pages " ,
"tags" : " tags " ,
"tagList" : " tags.json " ,
"post" : " post " ,
"tag" : " tag " ,
"images" : false
},
"fields" : {
"fields" : [ " id " , " name " , " dateLastActivity " , " desc " , " idList " , " labels " ],
"members" : true ,
"member_fields" : [ " fullName " , " bio " ],
"attachments" : true ,
"attachment_fields" : [ " previews " , " url " ]
},
"pagination" : {
"entriesPerPage" : 20
}
}要获取有关您可以选择的字段的更多信息,请参阅卡、附件和用户文档。
该模块适合与npx一起使用,这样您就不需要安装该模块并将其添加到包依赖项中。只需将npx tresor添加到模块的package.json中的prebuild挂钩中即可:
{
[ ... ]
"scripts" : {
"prebuild" : " npx tresor " ,
[ ... ]
}
}完毕!
运行tresor --help将打印以下使用手册:
$ tresor --help
A tool to fetch remote API data and store them locally as static JSON files
Usage
$ tresor
Run tresor
$ tresor --help
Print this help message
$ tresor --version
Print the current version
Examples
$ tresor --api.key=XXX --api.token=XXX --api.list=XXX
Run the script to request the remote JSON files and save
them locally.
You can alternatively pass the configuration options as
environment variables or writing them to config.json.
See the online documentation for further information