一種從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