> ## Documentation Index
> Fetch the complete documentation index at: https://ayakaleaf-pro.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 範本

> 在 Kubernetes 部署中執行範本庫。

範本庫在每個 Ayakaleaf Pro Pod 的 **web** 服務（`template-gallery` 模組）中執行；同一個 Pod 中的 **filestore** 服務則負責儲存範本檔案並產生其預覽。分類、權限與發布方式請參閱[範本](https://ayakaleaf-pro.mintlify.site/zh-TW/on-premises/configuration/overleaf-toolkit/templates.md)。

| | |
| - | - |
| 服務 | web（`template-gallery` 模組）、filestore（檔案與預覽圖片） |
| 儲存的資料 | 範本中繼資料儲存在 MongoDB 中；ZIP、PDF 與預覽圖片儲存在 filestore 的範本儲存區：資料磁碟區上的 `/var/lib/overleaf/data/template_files`，或 S3 儲存貯體 `OVERLEAF_FILESTORE_TEMPLATE_FILES_BUCKET_NAME` |
| Pod → 外部 | 無（若使用 S3 則連線至 S3） |
| 定期工作 | 無：預覽會在第一次檢視時產生 |

### 設定

**1. ConfigMap**

```yaml title="30-config.yaml (additions)" wrap theme={null}
  OVERLEAF_TEMPLATE_GALLERY: "true"
  ENABLE_CONVERSIONS: "true"
  OVERLEAF_TEMPLATE_CATEGORIES: academic-journal book presentation poster cv report thesis
  TEMPLATE_ACADEMIC_JOURNAL_NAME: Journal articles
  TEMPLATE_ACADEMIC_JOURNAL_DESCRIPTION: Templates for academic journal submissions.
  # ... one _NAME and _DESCRIPTION per category, see the Toolkit page
```

**2. 範本使用者（選用）**

管理員一律可以發布。若要讓非管理員使用者管理範本庫，請建立該使用者，從 MongoDB 讀取其 ID，並放入 ConfigMap：

```bash wrap theme={null}
kubectl -n overleaf exec mongo-0 -- mongosh --quiet \
  'mongodb://mongo-0.mongo:27017,mongo-1.mongo:27017,mongo-2.mongo:27017/sharelatex?replicaSet=overleaf' \
  --eval 'db.users.findOne({ email: "templates@example.com" })._id.toString()'
```

```yaml theme={null}
  OVERLEAF_TEMPLATES_USER_ID: "<the ID printed above>"
```

**3. 套用並重新啟動**

```bash theme={null}
kubectl apply -f 30-config.yaml
kubectl -n overleaf rollout restart deployment/overleaf     # or statefulset/overleaf
```

### 多個副本

* 範本檔案必須存放在 S3 中：若檔案位於各副本自己的磁碟上，每個節點顯示的範本庫都會不同。[水平擴展](https://ayakaleaf-pro.mintlify.site/zh-TW/on-premises/configuration/kubernetes/horizontal-scaling.md)的設定已使用儲存貯體 `overleaf-template-files`。
* 發布時會取用專案最後一次編譯的 PDF，而該 PDF 只存在於執行編譯的副本上。負載平衡器的黏性 Cookie 會讓使用者停留在該副本上，因此請從執行編譯的同一個瀏覽器工作階段進行發布。

### 在 Kubernetes 上的測試

在 Kubernetes 1.37 上以三個副本置於 HAProxy 之後，並將範本檔案存放在 S3 儲存貯體 `overleaf-template-files`（Garage）中，範本庫的端對端測試全數通過（41 個案例）：從「檔案」選單發布已編譯的專案，並由儲存貯體提供 PDF、預覽圖片與原始碼 ZIP；從範本建立專案；範本庫的分類、搜尋、排序與分頁；編輯、覆寫與刪除範本；管理員、一般使用者以及來自 `OVERLEAF_TEMPLATES_USER_ID` 之範本使用者（其 ID 依上述方式從 MongoDB 讀取）的權限；以及格式錯誤的請求。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.