# website

> Agent 用來維護專案網站清單的指令，也就是 AirBuild App「網站」分頁中顯示的清單。

Source: https://air.build/tw/docs/cli/website/

`website` 用來維護專案所屬的網站清單：也就是使用者在 AirBuild App 中專案的**網站**分頁看到的網站。Agent 以標題與網址加入網站後，AirBuild 會讀取該頁面，取得其圖示與主題色。此清單與專案一起存放在 AirBuild 中；專案的檔案裡沒有任何關於它的描述。

## 執行位置

雲端團隊與 Mac 團隊中的 Agent 都能使用同一個指令。登入資訊來自 Agent 的環境，因此無須任何設定。此指令需要 `curl` 與 `jq`，環境已提供。兩種團隊的差異請參閱[選擇 Agent 的執行位置](https://air.build/tw/docs/get-started/where-agents-run/)。

## 語法

```text
website [--project <project-id>] list
website [--project <project-id>] add --title T --url U [--source PATH] [--worker NAME] [--color #RRGGBB]
website [--project <project-id>] edit <id|url> [--title T] [--url U] [--source PATH] [--worker NAME] [--color #RRGGBB]
website [--project <project-id>] move <id|url> --to N
website [--project <project-id>] refresh <id|url>
website [--project <project-id>] remove <id|url> --confirm
website --help
```

`--project` 可以放在指令列的任何位置。所有選項也接受 `--option=value` 的寫法。

## 指定專案

在專案資料夾中執行時，`website` 會自行判斷是哪個專案。在其他位置時，請以 `--project` 傳入專案的 id（UUID）。兩者皆無時，會停止並顯示：

```text
Error: cannot tell which Project this is. Run website from inside a Project directory, or pass --project <project-id> (the uuid from list_projects).
```

## 指定網站

`edit`、`move`、`refresh` 與 `remove` 可依 id（取自 `website list`）或網址指定網站。網址結尾有無斜線都能比對。

## 指令

| 指令 | 作用 | 輸出 |
| --- | --- | --- |
| `list` | 依序顯示專案的網站。不接受引數。 | 每個網站一行（請參閱[輸出](https://air.build/tw/docs/cli/website/#output)），或 `No websites listed for this Project yet. Add one with website add --title … --url ….` |
| `add` | 在清單末端加入網站。`--title` 與 `--url` 為必填。加入後會讀取頁面的圖示與主題色。 | `Added <title> — <url> (id <id>). The page is being read for its icon and colour.` |
| `edit` | 只變更你傳入的欄位；至少需要一個。傳入空值（`""`）可清除 `--source`、`--worker` 或 `--color`。變更網址後會重新讀取頁面。 | `Updated <title> — <url>.` |
| `move` | 將網站移到第 N 個位置；`0` 為第一個。超出末端的位置會將它放到最後。 | 以新順序列出整個清單。 |
| `refresh` | 重新讀取頁面的圖示與主題色。 | `Reading the page again; website list shows the result in a moment.` |
| `remove` | 從清單移除網站。需要 `--confirm`。 | `Removed.` |

## 欄位

| 選項 | 值 | 意義 |
| --- | --- | --- |
| `--title` | 1–80 個字元 | 網站在清單中的名稱。 |
| `--url` | 絕對的 `http://` 或 `https://` 網址 | 網站的網址。每個網址在專案清單中只會出現一次。 |
| `--source` | 從專案根目錄起算的路徑，最多 512 個字元 | 網站程式碼在專案中的位置。 |
| `--worker` | Worker 名稱 | 提供此網站的 AirHost Worker。網站託管在其他地方時請省略。 |
| `--color` | `#RRGGBB` | 網站的主題色。以此方式設定的顏色在重新讀取頁面時會保留；以 `""` 清除後，改用從頁面 `theme-color` 讀取的顏色。 |
| `--to` | 整數，`0` 以上 | 僅限 `move`：新位置。 |
| `--confirm` | — | 僅限 `remove`：確認移除。 |
| `--project` | 專案 id（UUID） | 要操作的專案。在專案資料夾中可省略。 |

一個專案最多列出 50 個網站。

## 輸出

`list` 與 `move` 會依序為每個網站印出一行：

```text
<id>  <title> — <url>  worker=<name>  source=<path>  color=<#RRGGBB>  icon
```

`worker=`、`source=` 與 `color=` 只在已知時出現。AirBuild 已取得頁面圖示時，該行以 `icon` 結尾；否則以 `no-icon` 結尾。

## 結束代碼

| 代碼 | 意義 |
| --- | --- |
| `0` | 成功。 |
| `2` | 任何錯誤。stderr 上的訊息以 `Error:` 開頭。 |

## 錯誤

| 訊息 | 處理方式 |
| --- | --- |
| `Error: cannot tell which Project this is. …` | 在專案資料夾中執行，或傳入 `--project`。 |
| `Error: --project expects a Project id (uuid), got: …` | 傳入專案的 UUID，而非其名稱。 |
| `Error: no website with the address '…' in this Project. Run website list.` | 對照 `website list` 檢查網址，或改用網站的 id。 |
| `Error: website add needs --url.` | 加上 `--url`。缺少 `--title` 時會印出 `add` 的用法說明。 |
| `Error: website edit needs at least one of --title, --url, --source, --worker, --color.` | 傳入要變更的欄位。 |
| `Error: usage: website move … --to N` | `--to` 需要整數。 |
| `Error: removing a site from the list needs --confirm.` | 加上 `--confirm`。 |
| `Error: unknown option '…' for website <command>. Run website --help.` | 對照上方表格檢查選項。 |
| `Error: could not reach the Airbuild service.` | 再試一次。 |
| `Error: <reason>` | AirBuild 拒絕了請求：例如標題不在 1–80 個字元內、網址不是絕對的 `http(s)` 網址、專案清單中已有此網址、顏色不是 `#RRGGBB`，或清單已有 50 個網站。原因會說明是哪一項；修正後再執行一次指令。 |

## 範例

加入 App 的支援頁面並設定顏色：

```bash
website add --title "Support" --url https://example.com/support --color "#1E88E5"
```

記錄網站由某個 Worker 提供，並由專案中的某個資料夾建置：

```bash
website edit https://example.com --worker example-site --source web/
```

將網站移到第一個並查看清單：

```bash
website move https://example.com/privacy --to 0
website list
```

移除網站：

```bash
website remove 6f1c2d3e-0000-4000-8000-000000000000 --confirm
```
