chore(gitea): markdown 渲染子命令與文件、manifest 同步
What:gitea.sh 新增 markdown 子命令與可切換的 Content-Type,README 補上新工具、新技能與 HTML 範本說明,三份 manifest 同步升版到 0.1.3。 Why:markdown 轉 HTML 要交給 Gitea 自己渲染,排版才跟 wiki、議題頁一致;但 /markdown 端點在 Gitea 1.27 回 200 卻是空內容,看起來像成功。 How:改走吃純文字的 /markdown/raw,req 送出的 Content-Type 改由 REQ_CONTENT_TYPE 決定,預設仍是 application/json。代價寫進註解:raw 端點不吃 wiki 情境,[[頁名]] 要由呼叫端先換成絕對網址。 Who:所有透過 jsc-gitea 產生文件的技能。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
+15
-2
@@ -19,6 +19,7 @@
|
||||
# gitea.sh pr-depend <owner>/<repo> <pr-index> <dep-owner>/<dep-repo> <dep-index>
|
||||
# 把 PR 掛上前置 PR 依賴;依賴未關閉前 Gitea 會阻擋合併
|
||||
# gitea.sh repo-set <owner>/<repo> <description> [website] # 設定 repo 描述與網頁
|
||||
# gitea.sh markdown <file> # markdown 檔渲染成 HTML 片段(走 /markdown/raw)
|
||||
# gitea.sh api <METHOD> <path> [json-file] # 原始 API 呼叫(path 以 /repos/... 起始)
|
||||
# 環境變數: GITEA_HOST(例 https://gitea.jsc.idv.tw)、GITEA_TOKEN
|
||||
# GITEA_TOKEN 未設定,或請求遇 401/403 時,自動退回 tea CLI 的登入 token
|
||||
@@ -95,13 +96,16 @@ fi
|
||||
case "$GITEA_HOST" in http://*|https://*) HOST="$GITEA_HOST" ;; *) HOST="https://$GITEA_HOST" ;; esac
|
||||
API="${HOST%/}/api/v1"
|
||||
|
||||
req() { # METHOD path [json-file] -> body(HTTP >= 400 時 exit 4;401/403 以 tea token 重試一次)
|
||||
req() { # METHOD path [body-file] -> body(HTTP >= 400 時 exit 4;401/403 以 tea token 重試一次)
|
||||
# 送出的 Content-Type 由 REQ_CONTENT_TYPE 決定,預設 application/json;
|
||||
# /markdown/raw 這種吃純文字的端點要先改成 text/plain 再呼叫。
|
||||
method="$1"; path="$2"; body_file="${3:-}"
|
||||
ctype="${REQ_CONTENT_TYPE:-application/json}"
|
||||
retried=0
|
||||
while :; do
|
||||
if [ -n "$body_file" ]; then
|
||||
out=$(curl -sS -w '\n%{http_code}' -X "$method" \
|
||||
-H "Authorization: token $GITEA_TOKEN" -H "Content-Type: application/json" \
|
||||
-H "Authorization: token $GITEA_TOKEN" -H "Content-Type: $ctype" \
|
||||
--data-binary "@$body_file" "$API$path")
|
||||
else
|
||||
out=$(curl -sS -w '\n%{http_code}' -X "$method" \
|
||||
@@ -279,6 +283,15 @@ print(json.dumps(b))
|
||||
fi
|
||||
rm -f "$tmp"
|
||||
echo "OK $or" ;;
|
||||
markdown)
|
||||
# markdown 檔 -> HTML 片段。走 /markdown/raw(吃純文字)而不是 /markdown:
|
||||
# 後者在 Gitea 1.27 回 200 但內容是空的,看起來像成功,其實什麼都沒渲染。
|
||||
# 代價:raw 端點不吃 context,wiki 的 [[頁名]] 內部連結不會變成連結,
|
||||
# 呼叫端要先把它換成絕對網址。
|
||||
file="${1:?markdown file}"
|
||||
[ -f "$file" ] || { echo "找不到 markdown 檔: $file" >&2; exit 2; }
|
||||
REQ_CONTENT_TYPE='text/plain'
|
||||
req POST "/markdown/raw" "$file" ;;
|
||||
api)
|
||||
method="${1:?METHOD}"; path="${2:?path}"; body="${3:-}"
|
||||
req "$method" "$path" $body ;;
|
||||
|
||||
Reference in New Issue
Block a user