docs: update zh-tw (#197)

Signed-off-by: appleboy <appleboy.tw@gmail.com>
Reviewed-on: https://gitea.com/gitea/docs/pulls/197
Co-authored-by: appleboy <appleboy.tw@gmail.com>
Co-committed-by: appleboy <appleboy.tw@gmail.com>
This commit is contained in:
appleboy
2025-04-05 00:57:20 +00:00
committed by Bo-Yi Wu (吳柏毅)
parent dbfa0ba454
commit ac801c4790
6 changed files with 238 additions and 256 deletions

View File

@@ -6,21 +6,20 @@ aliases:
- /zh-tw/external-renderers
---
# External renderers
# 外部渲染器
Gitea supports custom file renderings (i.e., Jupyter notebooks, asciidoc, etc.) through external binaries,
it is just a matter of:
Gitea 支援透過外部二進位檔案進行自訂檔案渲染(例如 Jupyter 筆記本、asciidoc 等),只需:
- installing external binaries
- add some configuration to your `app.ini` file
- restart your Gitea instance
- 安裝外部二進位檔案
- `app.ini` 檔案中添加一些配置
- 重新啟動你的 Gitea 實例
This supports rendering of whole files. If you want to render code blocks in markdown you would need to do something with javascript. See some examples on the [Customizing Gitea](../administration/customizing-gitea.md) page.
這支援整個檔案的渲染。如果你想在 markdown 中渲染程式碼區塊,你需要使用 JavaScript。請參閱 [自訂 Gitea](../administration/customizing-gitea.md) 頁面上的一些範例。
## Installing external binaries
## 安裝外部二進位檔案
In order to get file rendering through external binaries, their associated packages must be installed.
If you're using a Docker image, your `Dockerfile` should contain something along this lines:
為了透過外部二進位檔案進行檔案渲染,必須安裝其相關的套件。
如果你使用 Docker 映像檔,你的 `Dockerfile` 應該包含如下內容:
```docker
FROM docker.gitea.com/gitea:@dockerVersion@
@@ -30,22 +29,22 @@ COPY custom/app.ini /data/gitea/conf/app.ini
[...]
RUN apk --no-cache add asciidoctor freetype freetype-dev gcc g++ libpng libffi-dev pandoc python3-dev py3-pyzmq pipx
# install any other package you need for your external renderers
# 安裝任何其他你需要的外部渲染器套件
RUN pipx install jupyter docutils --include-deps --global
# add above any other python package you may need to install
# 添加任何其他你可能需要安裝的 Python 套件
```
## `app.ini` file configuration
## `app.ini` 檔案配置
add one `[markup.XXXXX]` section per external renderer on your custom `app.ini`:
在你的自訂 `app.ini` 中為每個外部渲染器添加一個 `[markup.XXXXX]` 部分:
```ini
[markup.asciidoc]
ENABLED = true
FILE_EXTENSIONS = .adoc,.asciidoc
RENDER_COMMAND = "asciidoctor -s -a showtitle --out-file=- -"
; Input is not a standard input but a file
; 輸入不是標準輸入而是檔案
IS_INPUT_FILE = false
[markup.jupyter]
@@ -61,13 +60,12 @@ RENDER_COMMAND = "timeout 30s pandoc +RTS -M512M -RTS -f rst"
IS_INPUT_FILE = false
```
If your external markup relies on additional classes and attributes on the generated HTML elements, you might need to enable custom sanitizer policies. Gitea uses the [`bluemonday`](https://godoc.org/github.com/microcosm-cc/bluemonday) package as our HTML sanitizer. The example below could be used to support server-side [KaTeX](https://katex.org/) rendering output from [`pandoc`](https://pandoc.org/).
如果你的外部標記依賴於生成的 HTML 元素上的額外類和屬性你可能需要啟用自訂的清理策略。Gitea 使用 [`bluemonday`](https://godoc.org/github.com/microcosm-cc/bluemonday) 套件作為我們的 HTML 清理器。下面的範例可以用來支援來自 [`pandoc`](https://pandoc.org/) 的伺服器端 [KaTeX](https://katex.org/) 渲染輸出。
```ini
[markup.sanitizer.TeX]
; Pandoc renders TeX segments as <span>s with the "math" class, optionally
; with "inline" or "display" classes depending on context.
; - note this is different from the built-in math support in our markdown parser which uses <code>
; Pandoc 將 TeX 段落渲染為帶有 "math" 類的 <span>,根據上下文可選地帶有 "inline" 或 "display" 類。
; - 注意這與我們的 markdown 解析器內建的數學支援不同,後者使用 <code>
ELEMENT = span
ALLOW_ATTR = class
REGEXP = ^\s*((math(\s+|$)|inline(\s+|$)|display(\s+|$)))+
@@ -78,29 +76,28 @@ FILE_EXTENSIONS = .md,.markdown
RENDER_COMMAND = pandoc -f markdown -t html --katex
```
You must define `ELEMENT` and `ALLOW_ATTR` in each section.
你必須在每個部分中定義 `ELEMENT` `ALLOW_ATTR`
To define multiple entries, add a unique alphanumeric suffix (e.g., `[markup.sanitizer.1]` and `[markup.sanitizer.something]`).
要定義多個條目,請添加唯一的字母數字後綴(例如 `[markup.sanitizer.1]` `[markup.sanitizer.something]`)。
To apply a sanitisation rules only for a specify external renderer they must use the renderer name, e.g. `[markup.sanitizer.asciidoc.rule-1]`, `[markup.sanitizer.<renderer>.rule-1]`.
要僅對特定外部渲染器應用清理規則,它們必須使用渲染器名稱,例如 `[markup.sanitizer.asciidoc.rule-1]``[markup.sanitizer.<renderer>.rule-1]`
**Note**: If the rule is defined above the renderer ini section or the name does not match a renderer it is applied to every renderer.
**注意**:如果規則定義在渲染器 ini 部分之上或名稱不匹配渲染器,則應用於每個渲染器。
Once your configuration changes have been made, restart Gitea to have changes take effect.
一旦你的配置更改完成,重新啟動 Gitea 以使更改生效。
**Note**: Prior to Gitea 1.12 there was a single `markup.sanitiser` section with keys that were redefined for multiple rules, however,
there were significant problems with this method of configuration necessitating configuration through multiple sections.
**注意**:在 Gitea 1.12 之前,有一個單一的 `markup.sanitiser` 部分,具有為多個規則重新定義的鍵,但這種配置方法存在重大問題,因此需要通過多個部分進行配置。
### Example: HTML
### 範例:HTML
Render HTML files directly:
直接渲染 HTML 檔案:
```ini
[markup.html]
ENABLED = true
FILE_EXTENSIONS = .html,.htm
RENDER_COMMAND = cat
; Input is not a standard input but a file
; 輸入不是標準輸入而是檔案
IS_INPUT_FILE = true
[markup.sanitizer.html.1]
@@ -112,9 +109,9 @@ ELEMENT = a
ALLOW_ATTR = class
```
### Example: Office DOCX
### 範例:Office DOCX
Display Office DOCX files with [`pandoc`](https://pandoc.org/):
使用 [`pandoc`](https://pandoc.org/) 顯示 Office DOCX 檔案:
```ini
[markup.docx]
@@ -126,15 +123,15 @@ RENDER_COMMAND = "pandoc --from docx --to html --self-contained --template /path
ALLOW_DATA_URI_IMAGES = true
```
The template file has the following content:
模板檔案具有以下內容:
```
$body$
```
### Example: Jupyter Notebook
### 範例:Jupyter Notebook
Display Jupyter Notebook files with [`nbconvert`](https://github.com/jupyter/nbconvert):
使用 [`nbconvert`](https://github.com/jupyter/nbconvert) 顯示 Jupyter Notebook 檔案:
```ini
[markup.jupyter]
@@ -146,11 +143,11 @@ RENDER_COMMAND = "jupyter-nbconvert --stdin --stdout --to html --template basic"
ALLOW_DATA_URI_IMAGES = true
```
## Customizing CSS
## 自訂 CSS
The external renderer is specified in the .ini in the format `[markup.XXXXX]` and the HTML supplied by your external renderer will be wrapped in a `<div>` with classes `markup` and `XXXXX`. The `markup` class provides out of the box styling (as does `markdown` if `XXXXX` is `markdown`). Otherwise you can use these classes to specifically target the contents of your rendered HTML.
外部渲染器在 .ini 中以 `[markup.XXXXX]` 格式指定,外部渲染器提供的 HTML 將包裹在帶有 `markup` `XXXXX` 類的 `<div>` 中。`markup` 類提供了開箱即用的樣式(如果 `XXXXX` `markdown`,則 `markdown` 也提供樣式)。否則,你可以使用這些類來專門針對渲染的 HTML 內容。
And so you could write some CSS:
因此,你可以寫一些 CSS
```css
.markup.XXXXX html {
@@ -177,7 +174,7 @@ And so you could write some CSS:
}
```
Add your stylesheet to your custom directory e.g `custom/public/assets/css/my-style-XXXXX.css` and import it using a custom header file `custom/templates/custom/header.tmpl`:
將你的樣式表添加到自訂目錄,例如 `custom/public/assets/css/my-style-XXXXX.css`,並使用自訂標頭檔案 `custom/templates/custom/header.tmpl` 導入它:
```html
<link rel="stylesheet" href="{{AppSubUrl}}/assets/css/my-style-XXXXX.css" />

View File

@@ -6,60 +6,57 @@ aliases:
- /zh-tw/fail2ban-setup
---
# Fail2ban Setup
# Fail2ban 設定
**Remember that fail2ban is powerful and can cause lots of issues if you do it incorrectly, so make
sure to test this before relying on it so you don't lock yourself out.**
**記住fail2ban 很強大,如果你設定錯誤,可能會造成很多問題,所以在依賴它之前,務必先測試,避免把自己鎖在外面。**
Gitea returns an HTTP 200 for bad logins in the web logs, but if you have logging options on in
`app.ini`, then you should be able to go off of `log/gitea.log`, which gives you something like this
on a bad authentication from the web or CLI using SSH or HTTP respectively:
Gitea 在網頁日誌中對於錯誤登入會返回 HTTP 200但如果你在 `app.ini` 中開啟了日誌選項,那麼你應該可以從 `log/gitea.log` 中看到類似這樣的錯誤認證記錄,無論是從網頁還是使用 SSH 或 HTTP 的 CLI
```log
2018/04/26 18:15:54 [I] Failed authentication attempt for user from xxx.xxx.xxx.xxx
2018/04/26 18:15:54 [I] 使用者從 xxx.xxx.xxx.xxx 嘗試認證失敗
```
```log
2020/10/15 16:05:09 modules/ssh/ssh.go:143:publicKeyHandler() [W] Failed authentication attempt from xxx.xxx.xxx.xxx
2020/10/15 16:05:09 modules/ssh/ssh.go:143:publicKeyHandler() [W] 使用者從 xxx.xxx.xxx.xxx 嘗試認證失敗
```
(DEPRECATED: This may be a false positive as the user may still go on to correctly authenticate.)
(已棄用:這可能是誤報,因為使用者可能會繼續正確認證。)
```log
2020/10/15 16:05:09 modules/ssh/ssh.go:155:publicKeyHandler() [W] Failed authentication attempt from xxx.xxx.xxx.xxx
2020/10/15 16:05:09 modules/ssh/ssh.go:155:publicKeyHandler() [W] 使用者從 xxx.xxx.xxx.xxx 嘗試認證失敗
```
(DEPRECATED: This may be a false positive as the user may still go on to correctly authenticate.)
(已棄用:這可能是誤報,因為使用者可能會繼續正確認證。)
```log
2020/10/15 16:05:09 modules/ssh/ssh.go:198:publicKeyHandler() [W] Failed authentication attempt from xxx.xxx.xxx.xxx
2020/10/15 16:05:09 modules/ssh/ssh.go:198:publicKeyHandler() [W] 使用者從 xxx.xxx.xxx.xxx 嘗試認證失敗
```
(DEPRECATED: This may be a false positive as the user may still go on to correctly authenticate.)
(已棄用:這可能是誤報,因為使用者可能會繼續正確認證。)
```log
2020/10/15 16:05:09 modules/ssh/ssh.go:213:publicKeyHandler() [W] Failed authentication attempt from xxx.xxx.xxx.xxx
2020/10/15 16:05:09 modules/ssh/ssh.go:213:publicKeyHandler() [W] 使用者從 xxx.xxx.xxx.xxx 嘗試認證失敗
```
(DEPRECATED: This may be a false positive as the user may still go on to correctly authenticate.)
(已棄用:這可能是誤報,因為使用者可能會繼續正確認證。)
```log
2020/10/15 16:05:09 modules/ssh/ssh.go:227:publicKeyHandler() [W] Failed authentication attempt from xxx.xxx.xxx.xxx
2020/10/15 16:05:09 modules/ssh/ssh.go:227:publicKeyHandler() [W] 使用者從 xxx.xxx.xxx.xxx 嘗試認證失敗
```
(DEPRECATED: This may be a false positive as the user may still go on to correctly authenticate.)
(已棄用:這可能是誤報,因為使用者可能會繼續正確認證。)
```log
2020/10/15 16:05:09 modules/ssh/ssh.go:249:sshConnectionFailed() [W] Failed authentication attempt from xxx.xxx.xxx.xxx
2020/10/15 16:05:09 modules/ssh/ssh.go:249:sshConnectionFailed() [W] 使用者從 xxx.xxx.xxx.xxx 嘗試認證失敗
```
(From 1.15 this new message will available and doesn't have any of the false positive results that above messages from publicKeyHandler do. This will only be logged if the user has completely failed authentication.)
(從 1.15 版本開始,這個新訊息將可用,且不會有上述 publicKeyHandler 訊息中的誤報。只有當使用者完全認證失敗時,才會記錄這個訊息。)
```log
2020/10/15 16:08:44 ...s/context/context.go:204:HandleText() [E] invalid credentials from xxx.xxx.xxx.xxx
2020/10/15 16:08:44 ...s/context/context.go:204:HandleText() [E] 無效的憑證來自 xxx.xxx.xxx.xxx
```
Add our filter in `/etc/fail2ban/filter.d/gitea.local`:
`/etc/fail2ban/filter.d/gitea.local` 中新增我們的過濾器:
```ini
# gitea.local
@@ -68,7 +65,7 @@ failregex = .*(Failed authentication attempt|invalid credentials|Attempted acce
ignoreregex =
```
Add our jail in `/etc/fail2ban/jail.d/gitea.local`:
`/etc/fail2ban/jail.d/gitea.local` 中新增我們的 jail
```ini
[gitea]
@@ -81,8 +78,7 @@ bantime = 900
action = iptables-allports
```
If you're using Docker, you'll also need to add an additional jail to handle the **FORWARD**
chain in **iptables**. Configure it in `/etc/fail2ban/jail.d/gitea-docker.local`:
如果你使用 Docker你還需要新增一個 jail 來處理 **iptables** 中的 **FORWARD** 鏈。將其配置在 `/etc/fail2ban/jail.d/gitea-docker.local`
```ini
[gitea-docker]
@@ -95,22 +91,17 @@ bantime = 900
action = iptables-allports[chain="FORWARD"]
```
Then simply run `service fail2ban restart` to apply your changes. You can check to see if
fail2ban has accepted your configuration using `service fail2ban status`.
然後只需運行 `service fail2ban restart` 來應用你的更改。你可以使用 `service fail2ban status` 檢查 fail2ban 是否接受了你的配置。
Make sure and read up on fail2ban and configure it to your needs, this bans someone
for **15 minutes** (from all ports) when they fail authentication 10 times in an hour.
務必閱讀 fail2ban 並根據你的需求進行配置,這會在一小時內認證失敗 10 次時,將某人從所有端口禁止 **15 分鐘**
If you run Gitea behind a reverse proxy with Nginx (for example with Docker), you need to add
this to your Nginx configuration so that IPs don't show up as 127.0.0.1:
如果你在 Nginx 反向代理後運行 Gitea例如使用 Docker你需要在 Nginx 配置中添加這一行,這樣 IP 不會顯示為 127.0.0.1
```
proxy_set_header X-Real-IP $remote_addr;
```
The security options in `app.ini` need to be adjusted to allow the interpretation of the headers
as well as the list of IP addresses and networks that describe trusted proxy servers
(See the [configuration cheat sheet](../administration/config-cheat-sheet.md#security-security) for more information).
`app.ini` 中的安全選項需要調整,以允許解釋標頭以及描述受信任代理伺服器的 IP 地址和網絡列表(更多信息請參見 [配置速查表](../administration/config-cheat-sheet.md#security-security))。
```
REVERSE_PROXY_LIMIT = 1

View File

@@ -6,131 +6,129 @@ aliases:
- /zh-tw/guidelines-frontend
---
# Guidelines for Frontend Development
# 前端開發指南
## Background
## 背景
Gitea uses [Fomantic-UI](https://fomantic-ui.com/introduction/getting-started.html) (based on [jQuery](https://api.jquery.com)) and [Vue3](https://vuejs.org/) for its frontend.
Gitea 使用 [Fomantic-UI](https://fomantic-ui.com/introduction/getting-started.html)(基於 [jQuery](https://api.jquery.com))和 [Vue3](https://vuejs.org/) 作為前端框架。
The HTML pages are rendered by [Go HTML Template](https://pkg.go.dev/html/template).
HTML 頁面由 [Go HTML Template](https://pkg.go.dev/html/template) 渲染。
The source files can be found in the following directories:
源文件可以在以下目錄中找到:
- **CSS styles:** `web_src/css/`
- **JavaScript files:** `web_src/js/`
- **Vue components:** `web_src/js/components/`
- **Go HTML templates:** `templates/`
- **CSS 樣式:** `web_src/css/`
- **JavaScript 文件:** `web_src/js/`
- **Vue 組件:** `web_src/js/components/`
- **Go HTML 模板:** `templates/`
## General Guidelines
## 一般指南
We recommend [Google HTML/CSS Style Guide](https://google.github.io/styleguide/htmlcssguide.html) and [Google JavaScript Style Guide](https://google.github.io/styleguide/jsguide.html)
我們推薦 [Google HTML/CSS Style Guide](https://google.github.io/styleguide/htmlcssguide.html) [Google JavaScript Style Guide](https://google.github.io/styleguide/jsguide.html)
### Gitea specific guidelines
### Gitea 特定指南
1. Every feature (Fomantic-UI/jQuery module) should be put in separate files/directories.
2. HTML ids and classes should use kebab-case, it's preferred to contain 2-3 feature related keywords.
3. HTML ids and classes used in JavaScript should be unique for the whole project, and should contain 2-3 feature related keywords. We recommend to use the `js-` prefix for classes that are only used in JavaScript.
4. CSS styling for classes provided by frameworks should not be overwritten. Always use new class names with 2-3 feature related keywords to overwrite framework styles. Gitea's helper CSS classes in `helpers.less` could be helpful.
5. The backend can pass complex data to the frontend by using `ctx.PageData["myModuleData"] = map[]{}`, but do not expose whole models to the frontend to avoid leaking sensitive data.
6. Simple pages and SEO-related pages use Go HTML Template render to generate static Fomantic-UI HTML output. Complex pages can use Vue3.
7. Clarify variable types, prefer `elem.disabled = true` instead of `elem.setAttribute('disabled', 'anything')`, prefer `$el.prop('checked', var === 'yes')` instead of `$el.prop('checked', var)`.
8. Use semantic elements, prefer `<button class="ui button">` instead of `<div class="ui button">`.
9. Avoid unnecessary `!important` in CSS, add comments to explain why it's necessary if it can't be avoided.
10. Avoid mixing different events in one event listener, prefer to use individual event listeners for every event.
11. Custom event names are recommended to use `ce-` prefix.
12. Prefer using Tailwind CSS which is available via `tw-` prefix, e.g. `tw-relative`. Gitea's helper CSS classes use `gt-` prefix (`gt-ellipsis`), while Gitea's own private framework-level CSS classes use `g-` prefix (`g-modal-confirm`).
13. Avoid inline scripts & styles as much as possible, it's recommended to put JS code into JS files and use CSS classes. If inline scripts & styles are unavoidable, explain the reason why it can't be avoided.
1. 每個功能(Fomantic-UI/jQuery 模塊)應該放在單獨的文件/目錄中。
2. HTML id class 應該使用 kebab-case最好包含 2-3 個與功能相關的關鍵詞。
3. 在 JavaScript 中使用的 HTML id class 應該在整個項目中是唯一的,並且應該包含 2-3 個與功能相關的關鍵詞。我們建議對僅在 JavaScript 中使用的 class 使用 `js-` 前綴。
4. 不應覆蓋框架提供的 class 的 CSS 樣式。始終使用包含 2-3 個與功能相關的關鍵詞的新 class 名稱來覆蓋框架樣式。Gitea 的 `helpers.less` 中的輔助 CSS class 可能會有所幫助。
5. 後端可以使用 `ctx.PageData["myModuleData"] = map[]{}` 將複雜數據傳遞給前端,但不要將整個模型暴露給前端,以避免洩露敏感數據。
6. 簡單頁面和與 SEO 相關的頁面使用 Go HTML Template 渲染生成靜態 Fomantic-UI HTML 輸出。複雜頁面可以使用 Vue3
7. 明確變量類型,優先使用 `elem.disabled = true` 而不是 `elem.setAttribute('disabled', 'anything')`,優先使用 `$el.prop('checked', var === 'yes')` 而不是 `$el.prop('checked', var)`
8. 使用語義化元素,優先使用 `<button class="ui button">` 而不是 `<div class="ui button">`
9. 避免在 CSS 中不必要的 `!important`,如果無法避免,請添加註釋解釋為什麼是必要的。
10. 避免在一個事件監聽器中混合不同的事件,優先為每個事件使用單獨的事件監聽器。
11. 自定義事件名稱建議使用 `ce-` 前綴。
12. 優先使用 Tailwind CSS,通過 `tw-` 前綴可用,例如 `tw-relative`Gitea 的輔助 CSS class 使用 `gt-` 前綴(`gt-ellipsis`),而 Gitea 自己的私有框架級 CSS class 使用 `g-` 前綴(`g-modal-confirm`)。
13. 盡可能避免內聯腳本和樣式,建議將 JS 代碼放入 JS 文件並使用 CSS class。如果內聯腳本和樣式是不可避免的請解釋為什麼無法避免。
### Accessibility / ARIA
### 無障礙 / ARIA
In history, Gitea heavily uses Fomantic UI which is not an accessibility-friendly framework.
Gitea uses some patches to make Fomantic UI more accessible (see `aria.md` and related JS files),
but there are still many problems which need a lot of work and time to fix.
歷史上Gitea 大量使用 Fomantic UI這不是一個無障礙友好的框架。
Gitea 使用一些補丁使 Fomantic UI 更加無障礙(見 `aria.md` 和相關的 JS 文件),
但仍然存在許多問題,需要大量工作和時間來修復。
### Framework Usage
### 框架使用
Mixing different frameworks together is discouraged, it makes the code difficult to be maintained.
A JavaScript module should follow one major framework and follow the framework's best practice.
不建議混合使用不同的框架,這會使代碼難以維護。
JavaScript 模塊應該遵循一個主要框架並遵循該框架的最佳實踐。
Recommended implementations:
推薦的實現:
- Vue + Vanilla JS
- Vue + 原生 JS
- Fomantic-UI (jQuery)
- htmx (partial page reloads for otherwise static components)
- Vanilla JS
- htmx(部分頁面重新加載,適用於靜態組件)
- 原生 JS
Discouraged implementations:
不推薦的實現:
- Vue + Fomantic-UI (jQuery)
- jQuery + Vanilla JS
- htmx + any other framework which requires heavy JS code, or unnecessary features like htmx scripting (`hx-on`)
- jQuery + 原生 JS
- htmx + 任何需要大量 JS 代碼的框架,或不必要的功能如 htmx 腳本(`hx-on`
To make UI consistent, Vue components can use Fomantic-UI CSS classes.
We use htmx for simple interactions. You can see an example for simple interactions where htmx should be used in this [PR](https://github.com/go-gitea/gitea/pull/28908). Do not use htmx if you require more advanced reactivity, use another framework (Vue/Vanilla JS).
Although mixing different frameworks is discouraged,
it should also work if the mixing is necessary and the code is well-designed and maintainable.
為了使 UI 一致Vue 組件可以使用 Fomantic-UI CSS class
我們使用 htmx 進行簡單的交互。你可以在這個 [PR](https://github.com/go-gitea/gitea/pull/28908) 中看到一個使用 htmx 進行簡單交互的示例。如果你需要更高級的反應性請使用其他框架Vue/原生 JS)。
雖然不建議混合使用不同的框架,
但如果混合是必要的並且代碼設計良好且可維護,應該也是可行的。
### Typescript
Gitea is in the process of migrating to type-safe Typescript. Here are some specific guidelines regarding Typescript in the codebase:
Gitea 正在遷移到類型安全的 Typescript。以下是一些關於 Typescript 在代碼庫中的具體指南:
#### Use type aliases instead of interfaces
#### 使用類型別名而不是接口
Prefer to use type aliases because they can represent any type and are generally more flexible to use than interfaces.
優先使用類型別名,因為它們可以表示任何類型,並且通常比接口更靈活。
#### Use separate type imports
#### 使用單獨的類型導入
We use `verbatimModuleSyntax` so type and non-type imports from the same file must be split into two `import type` statements. This enables the typescript compiler to completely eliminate the type import statements during compilation.
我們使用 `verbatimModuleSyntax`,因此來自同一文件的類型和非類型導入必須分成兩個 `import type` 語句。這使得 typescript 編譯器在編譯過程中可以完全消除類型導入語句。
#### Use `@ts-expect-error` instead of `@ts-ignore`
#### 使用 `@ts-expect-error` 而不是 `@ts-ignore`
Both annotations should be avoided, but if you have to use them, use `@ts-expect-error` because it will not leave ineffective statements after the issue is fixed.
應避免使用這兩個註釋,但如果必須使用,請使用 `@ts-expect-error`,因為在問題修復後它不會留下無效的語句。
### `async` Functions
### `async` 函數
Only mark a function as `async` if and only if there are `await` calls
or `Promise` returns inside the function.
只有在函數內部有 `await` 調用或返回 `Promise` 時,才將函數標記為 `async`
It's not recommended to use `async` event listeners, which may lead to problems.
The reason is that the code after await is executed outside the event dispatch.
Reference: https://github.com/github/eslint-plugin-github/blob/main/docs/rules/async-preventdefault.md
不建議使用 `async` 事件監聽器,這可能會導致問題。
原因是 `await` 之後的代碼在事件分派之外執行。
參考:https://github.com/github/eslint-plugin-github/blob/main/docs/rules/async-preventdefault.md
If an event listener must be `async`, the `e.preventDefault()` should be before any `await`,
it's recommended to put it at the beginning of the function.
如果事件監聽器必須是 `async`,則 `e.preventDefault()` 應在任何 `await` 之前,
建議將其放在函數的開頭。
If we want to call an `async` function in a non-async context,
it's recommended to use `const _promise = asyncFoo()` to tell readers
that this is done by purpose, we want to call the async function and ignore the Promise.
Some lint rules and IDEs also have warnings if the returned Promise is not handled.
如果我們想在非 `async` 上下文中調用 `async` 函數,
建議使用 `const _promise = asyncFoo()` 來告訴讀者
這是故意這樣做的,我們想調用 `async` 函數並忽略 Promise
一些 lint 規則和 IDE 也會在未處理返回的 Promise 時發出警告。
### Fetching data
### 獲取數據
To fetch data, use the wrapper functions `GET`, `POST` etc. from `modules/fetch.js`. They
accept a `data` option for the content, will automatically set CSRF token and return a
Promise for a [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response).
要獲取數據,請使用 `modules/fetch.js` 中的包裝函數 `GET``POST` 等。
它們接受一個 `data` 選項作為內容,會自動設置 CSRF 令牌並返回一個 [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) 的 Promise。
### HTML Attributes and `dataset`
### HTML 屬性和 `dataset`
The usage of `dataset` is forbidden, its camel-casing behaviour makes it hard to grep for attributes.
However, there are still some special cases, so the current guideline is:
禁止使用 `dataset`,其駝峰命名行為使得很難 grep 屬性。
然而,仍然存在一些特殊情況,所以目前的指南是:
- For legacy code:
- 對於遺留代碼:
- `$.data()` should be refactored to `$.attr()`.
- `$.data()` can be used to bind some non-string data to elements in rare cases, but it is highly discouraged.
- `$.data()` 應重構為 `$.attr()`
- `$.data()` 可以在罕見情況下用於將一些非字符串數據綁定到元素,但這是高度不建議的。
- For new code:
- `node.dataset` should not be used, use `node.getAttribute` instead.
- never bind any user data to a DOM node, use a suitable design pattern to describe the relation between node and data.
- 對於新代碼:
- 不應使用 `node.dataset`,應使用 `node.getAttribute`
- 永遠不要將任何用戶數據綁定到 DOM 節點,應使用合適的設計模式來描述節點和數據之間的關係。
### Show/Hide Elements
### 顯示/隱藏元素
- Vue components are recommended to use `v-if` and `v-show` to show/hide elements.
- Go template code should use `.tw-hidden` and `showElem()/hideElem()/toggleElem()`, see more details in `.tw-hidden`'s comment.
- Vue 組件建議使用 `v-if` `v-show` 來顯示/隱藏元素。
- Go 模板代碼應使用 `.tw-hidden` `showElem()/hideElem()/toggleElem()`,詳情見 `.tw-hidden` 的註釋。
### Styles and Attributes in Go HTML Template
### Go HTML 模板中的樣式和屬性
It's recommended to use:
建議使用:
```html
<div
@@ -140,7 +138,7 @@ It's recommended to use:
></div>
```
instead of:
而不是:
```html
<div
@@ -151,16 +149,16 @@ instead of:
></div>
```
to make the code more readable.
以使代碼更具可讀性。
### Legacy Code
### 遺留代碼
A lot of legacy code already existed before this document's written. It's recommended to refactor legacy code to follow the guidelines.
在撰寫本文檔之前,已經存在許多遺留代碼。建議重構遺留代碼以遵循這些指南。
### Vue3 and JSX
### Vue3 JSX
Gitea is using Vue3 now. We decided not to introduce JSX to keep the HTML and the JavaScript code separated.
Gitea 現在使用 Vue3。我們決定不引入 JSX以保持 HTML 和 JavaScript 代碼分離。
### UI Examples
### UI 示例
Gitea uses some self-made UI elements and customizes others to integrate them better into the general UI approach. When running Gitea in development mode (`RUN_MODE=dev`), a page with some standardized UI examples is available under `http(s)://your-gitea-url:port/devtest`.
Gitea 使用一些自製的 UI 元素並自定義其他元素,以更好地將它們集成到整體 UI 方法中。當 Gitea 在開發模式下運行時(`RUN_MODE=dev`),可以在 `http(s)://your-gitea-url:port/devtest` 下訪問一些標準化的 UI 示例頁面。

View File

@@ -4,39 +4,39 @@ slug: "overview"
sidebar_position: 1
---
# Overview
# 概述
Starting with Gitea **1.19**, Gitea Actions are available as a built-in CI/CD solution.
Gitea **1.19** 開始,Gitea Actions 作為內建的 CI/CD 解決方案可用。
## Name
## 名稱
It is similar and compatible to [GitHub Actions](https://github.com/features/actions), and its name is inspired by it too.
To avoid confusion, we have clarified the spelling here:
它類似並兼容於 [GitHub Actions](https://github.com/features/actions),其名稱也受其啟發。
為了避免混淆,我們在這裡澄清拼寫:
- "Gitea Actions" (with an "s", both words capitalized) is the name of the Gitea feature.
- "GitHub Actions" is the name of the GitHub feature.
- "Actions" could refer to either of the above, depending on the context. So it refers to "Gitea Actions" in this document.
- "action" or "actions" refer to some scripts/plugins to be used, like "actions/checkout@v4" or "actions/cache@v3".
- "Gitea Actions"(帶有 "s",兩個詞首字母大寫)是 Gitea 功能的名稱。
- "GitHub Actions" 是 GitHub 功能的名稱。
- "Actions" 可能指上述任何一個,取決於上下文。在本文檔中,它指的是 "Gitea Actions"。
- "action" "actions" 指的是一些腳本/插件,如 "actions/checkout@v4" "actions/cache@v3"
## Runners
Just like other CI/CD solutions, Gitea doesn't run the jobs itself, but delegates the jobs to runners.
The runner of Gitea Actions is called [act runner](https://gitea.com/gitea/act_runner), it is a standalone program and also written in Go.
It is based on a [fork](https://gitea.com/gitea/act) of [nektos/act](http://github.com/nektos/act).
就像其他 CI/CD 解決方案一樣Gitea 不會自己運行作業,而是將作業委派給 runners
Gitea Actions 的 runner 稱為 [act runner](https://gitea.com/gitea/act_runner),它是一個獨立的程序,也是用 Go 編寫的。
它基於 [nektos/act](http://github.com/nektos/act) [fork](https://gitea.com/gitea/act)
Because the runner is deployed independently, there could be potential security issues.
To avoid them, please follow two simple rules:
由於 runner 是獨立部署的,可能會有潛在的安全問題。
為了避免這些問題,請遵循兩個簡單的規則:
- Don't use a runner you don't trust for your repository, organization or instance.
- Don't provide a runner to a repository, organization or instance you don't trust.
- 不要為你不信任的倉庫、組織或實例使用你不信任的 runner。
- 不要為你不信任的倉庫、組織或實例提供 runner。
For Gitea instances used internally, such as instances used by enterprises or individuals, neither of these two rules is a problem, they are naturally so.
However, for public Gitea instances, such as [gitea.com](https://gitea.com), these two rules should be kept in mind when adding or using runners.
對於內部使用的 Gitea 實例,如企業或個人使用的實例,這兩個規則都不是問題,它們自然如此。
然而,對於公共 Gitea 實例,如 [gitea.com](https://gitea.com),在添加或使用 runners 時應記住這兩個規則。
## Status
## 狀態
Gitea Actions is still under development, so there may be some bugs and missing features.
And breaking changes may be made before it's stable (v1.20 or later).
Gitea Actions 仍在開發中,因此可能會有一些錯誤和缺失的功能。
在穩定之前v1.20 或更高版本),可能會進行重大更改。
If the situation changes, we will update it here.
So please refer to the content here when you find outdated articles elsewhere.
如果情況發生變化,我們會在這裡更新。
因此,當你在其他地方找到過時的文章時,請參考這裡的內容。

View File

@@ -4,92 +4,92 @@ slug: "quickstart"
sidebar_position: 10
---
# Quick Start
# 快速開始
This page will guide you through the process of using Gitea Actions.
本頁將引導你使用 Gitea Actions 的過程。
## Set up Gitea
## 設置 Gitea
First of all, you need a Gitea instance.
You can follow the [documentation](installation/from-package.md) to set up a new instance or upgrade your existing one.
It doesn't matter how you install or run Gitea, as long as its version is 1.19.0 or higher.
首先,你需要一個 Gitea 實例。
你可以按照 [文檔](installation/from-package.md) 設置一個新實例或升級現有實例。
無論你如何安裝或運行 Gitea只要其版本是 1.19.0 或更高版本即可。
Since 1.21.0, Actions are enabled by default. If you are using versions before 1.21.0, you need to add the following to the configuration file to enable it:
1.21.0 開始,Actions 默認啟用。如果你使用的是 1.21.0 之前的版本,你需要在配置文件中添加以下內容以啟用它:
```ini
[actions]
ENABLED=true
```
If you want to learn more or encounter any problems while configuring it, please refer to the [Configuration Cheat Sheet](../../administration/config-cheat-sheet.md#actions-actions).
如果你想了解更多或在配置過程中遇到任何問題,請參考 [配置備忘單](../../administration/config-cheat-sheet.md#actions-actions)
### Set up runner
### 設置 runner
Gitea Actions requires [act runner](https://gitea.com/gitea/act_runner) to run the jobs.
In order to avoid consuming too many resources and affecting the Gitea instance, it is recommended to start runners on separate machines from the Gitea instance.
Gitea Actions 需要 [act runner](https://gitea.com/gitea/act_runner) 來運行作業。
為了避免消耗過多資源並影響 Gitea 實例,建議在與 Gitea 實例不同的機器上啟動 runners。
You can use the [pre-built binaries](http://dl.gitea.com/act_runner) or the [docker images](https://hub.docker.com/r/gitea/act_runner/tags) to set up the runner.
你可以使用 [預構建的二進位文件](http://dl.gitea.com/act_runner) [docker 映像](https://hub.docker.com/r/gitea/act_runner/tags) 設置 runner
Before proceeding any further, we suggest running it as a command line with pre-built binaries to ensure that it works with your environment, especially if you are running a runner on your local host.
And it could be easier to debug if something goes wrong.
在進一步操作之前,我們建議使用預構建的二進位文件作為命令行運行它,以確保它適用於你的環境,特別是如果你在本地主機上運行 runner。
如果出現問題,這樣也更容易調試。
The runner can run the jobs in isolated Docker containers, so you need to make sure that the Docker has been installed and Docker daemon is running.
While it is not strictly necessary, because the runner can also run the jobs directly on the host, it depends on how you configure it.
However, it is recommended to use Docker to run the jobs, because it is more secure and easier to manage.
runner 可以在隔離的 Docker 容器中運行作業,因此你需要確保已安裝 Docker 並且 Docker 守護進程正在運行。
雖然這不是絕對必要的,因為 runner 也可以直接在主機上運行作業,這取決於你如何配置它。
然而,建議使用 Docker 來運行作業,因為這樣更安全且更易於管理。
Before running a runner, you should first register it to your Gitea instance using the following command:
在運行 runner 之前,你應該首先使用以下命令將其註冊到你的 Gitea 實例:
```bash
./act_runner register --no-interactive --instance <instance> --token <token>
```
There are two arguments required, `instance` and `token`.
需要兩個參數,`instance` `token`
`instance` refers to the address of your Gitea instance, like `http://192.168.8.8:3000` or `https://gitea.com`.
The runner and job containers (which are started by the runner to execute jobs) will connect to this address.
This means that it could be different from the `ROOT_URL` of your Gitea instance, which is configured for web access.
It is always a bad idea to use a loopback address such as `127.0.0.1` or `localhost`.
If you are unsure which address to use, the LAN address is usually the right choice.
`instance` 指的是你的 Gitea 實例的地址,如 `http://192.168.8.8:3000` `https://gitea.com`
runner 和作業容器(由 runner 啟動以執行作業)將連接到此地址。
這意味著它可能與你的 Gitea 實例的 `ROOT_URL` 不同,後者是為網頁訪問配置的。
使用回環地址如 `127.0.0.1` `localhost` 總是個壞主意。
如果你不確定使用哪個地址,通常 LAN 地址是正確的選擇。
`token` is used for authentication and identification, such as `P2U1U0oB4XaRCi8azcngmPCLbRpUGapalhmddh23`.
Each token can be used to create multiple runners, until it is replaced with a new token using the reset link.
You can obtain different levels of 'tokens' from the following places to create the corresponding level of 'runners':
`token` 用於身份驗證和識別,如 `P2U1U0oB4XaRCi8azcngmPCLbRpUGapalhmddh23`
每個令牌可以用來創建多個 runners直到使用重置鏈接替換為新令牌。
你可以從以下位置獲取不同級別的令牌來創建相應級別的 runners
- Instance level: The admin settings page, like `<your_gitea.com>/admin/actions/runners`.
- Organization level: The organization settings page, like `<your_gitea.com>/<org>/settings/actions/runners`.
- Repository level: The repository settings page, like `<your_gitea.com>/<owner>/<repo>/settings/actions/runners`.
- 實例級別:管理員設置頁面,如 `<your_gitea.com>/admin/actions/runners`
- 組織級別:組織設置頁面,如 `<your_gitea.com>/<org>/settings/actions/runners`
- 倉庫級別:倉庫設置頁面,如 `<your_gitea.com>/<owner>/<repo>/settings/actions/runners`
![register runner](/images/usage/actions/register-runner.png)
After registering, a new file named `.runner` will appear in the current directory.
This file stores the registration information.
Please do not edit it manually.
If this file is missing or corrupted, you can simply remove it and register again.
註冊後,一個名為 `.runner` 的新文件將出現在當前目錄中。
該文件存儲註冊信息。
請不要手動編輯它。
如果該文件丟失或損壞,你可以簡單地刪除它並重新註冊。
Finally, it's time to start the runner:
最後,是時候啟動 runner 了:
```bash
./act_runner daemon
```
And you can see the new runner in the management page:
你可以在管理頁面中看到新的 runner
![view runner](/images/usage/actions/view-runner.png)
You can find more information by visiting [Act runner](usage/actions/act-runner.md).
你可以訪問 [Act runner](usage/actions/act-runner.md) 獲取更多信息。
### Use Actions
### 使用 Actions
Even if Actions is enabled for the Gitea instance, repositories still disable Actions by default.
即使 Gitea 實例啟用了 Actions倉庫仍然默認禁用 Actions。
To enable it, go to the settings page of your repository like `your_gitea.com/<owner>/repo/settings` and enable `Enable Repository Actions`.
要啟用它,請轉到倉庫的設置頁面,如 `your_gitea.com/<owner>/repo/settings` 並啟用 `Enable Repository Actions`
![enable actions](/images/usage/actions/enable-actions.png)
The next steps may be rather complicated.
You will need to study [the workflow syntax](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions) for Actions and write the workflow files you want.
接下來的步驟可能相當複雜。
你需要學習 [工作流程語法](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions) 並編寫你想要的工作流程文件。
However, we can just start from a simple demo:
然而,我們可以從一個簡單的示例開始:
```yaml
name: Gitea Actions Demo
@@ -115,24 +115,24 @@ jobs:
:::warning
Certain actions may not function correctly within SHA256 repositories or when Gitea runs on subpath. This includes [actions/checkout](https://github.com/actions/checkout/issues/1843).
某些 actions 可能無法在 SHA256 倉庫中正常運行,或者當 Gitea 在子路徑上運行時。這包括 [actions/checkout](https://github.com/actions/checkout/issues/1843)
:::
You can upload it as a file with the extension `.yaml` in the directory `.gitea/workflows/` of the repository, for example `.gitea/workflows/demo.yaml`.
You might notice that this is fairly similar from the [Quickstart for GitHub Actions](https://docs.github.com/en/actions/quickstart).
That is because Gitea Actions is designed to be compatible with GitHub Actions wherever possible.
你可以將其作為擴展名為 `.yaml` 的文件上傳到倉庫的 `.gitea/workflows/` 目錄中,例如 `.gitea/workflows/demo.yaml`
你可能會注意到這與 [GitHub Actions 快速入門](https://docs.github.com/en/actions/quickstart) 非常相似。
那是因為 Gitea Actions 設計上盡可能與 GitHub Actions 兼容。
Be careful, the demo file contains some emojis.
Please make sure your database supports them, especially when using MySQL.
If the charset is not `utf8mb4`, errors will occur, such as `Error 1366 (HY000): Incorrect string value: '\\xF0\\x9F\\x8E\\x89 T...' for column 'name' at row 1`.
See [Database Preparation](../../installation/database-preparation.md#mysqlmariadb) for more information.
請注意,示例文件中包含一些表情符號。
請確保你的數據庫支持它們,特別是當使用 MySQL 時。
如果字符集不是 `utf8mb4`,將會出現錯誤,如 `Error 1366 (HY000): Incorrect string value: '\\xF0\\x9F\\x8E\\x89 T...' for column 'name' at row 1`
有關更多信息,請參見 [數據庫準備](../../installation/database-preparation.md#mysqlmariadb)
Alternatively, you can remove all emojis from the demo file and try again.
或者,你可以刪除示例文件中的所有表情符號並重試。
The line `on: [push]` indicates that the workflow will be triggered when you push commits to this repository.
However, when you upload the YAML file, it also pushes a commit, so you should see a new task in the Actions tab.
`on: [push]` 表示當你向此倉庫推送提交時,工作流程將被觸發。
然而,當你上傳 YAML 文件時,它也會推送一個提交,因此你應該在 Actions 標籤中看到一個新任務。
![view job](/images/usage/actions/view-job.png)
Great job! You have successfully started working with Actions.
幹得好!你已經成功開始使用 Actions

View File

@@ -6,30 +6,26 @@ sidebar_position: 50
# Secrets
Secrets allow you to store sensitive information in your user, organization or repository.
Secrets are available on Gitea 1.19+ and are only visible in 1.20+ when ACTIONS are enabled.
Secrets 允許你在用戶、組織或倉庫中存儲敏感信息。
Secrets 在 Gitea 1.19+ 可用,並且在 1.20+ 啟用 ACTIONS 時可見。
# Naming your secrets
## 命名你的 secrets
The following rules apply to secret names:
以下規則適用於 secret 名稱:
- Secret names can only contain alphanumeric characters (`[a-z]`, `[A-Z]`, `[0-9]`) or underscores (`_`). Spaces are not allowed.
- Secret 名稱只能包含字母數字字符 (`[a-z]`, `[A-Z]`, `[0-9]`) 或下劃線 (`_`)。不允許使用空格。
- Secret 名稱不得以 `GITHUB_``GITEA_` 前綴開頭。
- Secret 名稱不得以數字開頭。
- Secret 名稱不區分大小寫。
- Secret 名稱在創建它們的級別上必須是唯一的。
- Secret names must not start with the `GITHUB_` and `GITEA_` prefix.
例如,在倉庫級別創建的 secret 必須在該倉庫中具有唯一名稱,而在組織級別創建的 secret 必須在該級別上具有唯一名稱。
- Secret names must not start with a number.
### 使用 secrets
- Secret names are not case-sensitive.
創建配置變數後,它們將自動填充到 `secrets` 上下文中。
可以通過表達式 `${{ secrets.SECRET_NAME }}` 在工作流程中訪問它們。
- Secret names must be unique at the level they are created at.
### 優先級
For example, a secret created at the repository level must have a unique name in that repository, and a secret created at the organization level must have a unique name at that level.
### Using secrets
After creating configuration variables, they will be automatically filled in the `secrets` context.
They can be accessed through expressions like `${{ secrets.SECRET_NAME }}` in the workflow.
### Precedence
If a secret with the same name exists at multiple levels, the secret at the lowest level takes precedence. For example, if an organization-level secret has the same name as a repository-level secret, then the repository-level secret takes precedence.
如果在多個級別存在同名 secret則最低級別的 secret 優先。例如,如果組織級別的 secret 與倉庫級別的 secret 同名,則倉庫級別的 secret 優先。