Compare commits

..
44 Commits
Author SHA1 Message Date
thanhtl 58256842e0 upload image(s) from Typora: 2026-04-23 16:47:43 2026-04-23 16:47:43 +07:00
thanhtl eeb86603bb upload image(s) from Typora: 2026-04-23 16:47:10 2026-04-23 16:47:10 +07:00
thanhtl 8da07a26d3 upload image(s) from Typora: 2026-04-23 16:46:27 2026-04-23 16:46:27 +07:00
thanhtl 191496ec14 upload image(s) from Typora: 2026-04-23 16:44:32 2026-04-23 16:44:32 +07:00
thanhtl 7ac856cd8b upload image(s) from Typora: 2026-04-23 16:43:32 2026-04-23 16:43:32 +07:00
thanhtl aae451291d upload image(s) from Typora: 2026-04-23 16:42:37 2026-04-23 16:42:37 +07:00
thanhtl bea467dc40 upload image(s) from Typora: 2026-04-23 16:41:29 2026-04-23 16:41:29 +07:00
thanhtl 138b3470d3 upload image(s) from Typora: 2026-04-23 16:39:09 2026-04-23 16:39:09 +07:00
thanhtl f3b345a4e3 upload image(s) from Typora: 2026-04-23 16:38:17 2026-04-23 16:38:17 +07:00
thanhtl 9d84a1e311 upload image(s) from Typora: 2026-04-23 16:37:21 2026-04-23 16:37:21 +07:00
thanhtl 217dc65195 upload image(s) from Typora: 2026-04-23 16:34:28 2026-04-23 16:34:28 +07:00
thanhtl a057a184c9 upload image(s) from Typora: 2026-04-23 16:33:06 2026-04-23 16:33:06 +07:00
thanhtl 791ee1a033 upload image(s) from Typora: 2026-04-23 16:32:22 2026-04-23 16:32:22 +07:00
thanhtl 72f79a1237 upload image(s) from Typora: 2026-04-23 16:31:12 2026-04-23 16:31:12 +07:00
thanhtl 9edc7424a9 upload image(s) from Typora: 2026-04-23 16:29:18 2026-04-23 16:29:18 +07:00
thanhtl 983ce55f2f upload image(s) from Typora: 2026-04-23 16:27:40 2026-04-23 16:27:40 +07:00
thanhtl 32a8b54891 upload image(s) from Typora: 2026-04-23 16:26:00 2026-04-23 16:26:00 +07:00
thanhtl 8a68d226fd upload image(s) from Typora: 2026-04-23 16:23:25 2026-04-23 16:23:25 +07:00
thanhtl 74cb8b3110 upload image(s) from Typora: 2026-04-23 16:19:08 2026-04-23 16:19:08 +07:00
thanhtl d1945680f5 upload image(s) from Typora: 2026-04-23 16:18:48 2026-04-23 16:18:48 +07:00
thanhtl 6da2b5caf6 upload image(s) from Typora: 2026-04-23 16:18:17 2026-04-23 16:18:17 +07:00
thanhtl 2b5bc2969e upload image(s) from Typora: 2026-04-23 16:17:59 2026-04-23 16:17:59 +07:00
thanhtl e378f4df56 upload image(s) from Typora: 2026-04-23 16:17:28 2026-04-23 16:17:28 +07:00
thanhtl af8e2931ca upload image(s) from Typora: 2026-04-23 16:14:27 2026-04-23 16:14:27 +07:00
thanhtl 7350c143c7 upload image(s) from Typora: 2026-04-23 16:14:03 2026-04-23 16:14:03 +07:00
thanhtl e74161583e upload image(s) from Typora: 2026-04-23 16:13:01 2026-04-23 16:13:01 +07:00
thanhtl afab583aa2 upload image(s) from Typora: 2026-04-23 16:12:35 2026-04-23 16:12:35 +07:00
thanhtl 5506d0f385 upload image(s) from Typora: 2026-04-23 16:12:26 2026-04-23 16:12:26 +07:00
thanhtl 52b1f2e1dc upload image(s) from Typora: 2026-04-23 16:12:07 2026-04-23 16:12:07 +07:00
thanhtl 60e735a9b7 upload image(s) from Typora: 2026-04-23 16:11:33 2026-04-23 16:11:33 +07:00
thanhtl 44619fc09a upload image(s) from Typora: 2026-04-23 16:11:14 2026-04-23 16:11:14 +07:00
thanhtl 4209c7d248 upload image(s) from Typora: 2026-04-23 16:10:50 2026-04-23 16:10:50 +07:00
thanhtl db7fa386ae upload image(s) from Typora: 2026-04-23 16:10:37 2026-04-23 16:10:37 +07:00
thanhtl c909125fc3 upload image(s) from Typora: 2026-04-23 16:09:02 2026-04-23 16:09:02 +07:00
thanhtl 764d0b4ed6 upload image(s) from Typora: 2026-04-23 16:08:26 2026-04-23 16:08:26 +07:00
thanhtl c893e2f130 upload image(s) from Typora: 2026-04-23 16:04:31 2026-04-23 16:04:31 +07:00
thanhtl 77f3598cd6 upload image(s) from Typora: 2026-04-23 15:57:18 2026-04-23 15:57:18 +07:00
thanhtl 8219029764 init: first commit 2026-04-23 15:56:21 +07:00
thanhtl cda0930013 Update README.md 2026-04-23 15:46:26 +07:00
thanhtl d23754990b Update README.md 2026-04-09 01:29:22 +07:00
ds ef310980eb upload image(s) from Typora: 2026-04-09 01:27:28 2026-04-09 01:27:28 +07:00
ds 64451a0fe3 upload image(s) from Typora: 2026-04-09 01:26:52 2026-04-09 01:26:52 +07:00
ds 6f222287b0 Merge local and remote histories 2026-04-09 01:26:18 +07:00
ds 34be5eff9f init: first commit 2026-04-09 01:22:18 +07:00
42 changed files with 1 additions and 368 deletions
+1 -368
View File
@@ -1,368 +1 @@
Dưới đây là bản hướng dẫn đầy đủ để dùng **Typora + self-hosted Gitea** làm nơi lưu ảnh. # Typora Uploads
## Mục tiêu
Khi bạn dán ảnh vào Typora, Typora sẽ gọi một script tùy chỉnh. Script đó sẽ:
1. nhận đường dẫn ảnh từ Typora
2. copy ảnh vào repo Git local
3. `git add` + `git commit` + `git push` lên Gitea
4. in ra **URL ảnh dạng raw**
5. Typora lấy URL đó để thay thế ảnh local trong file Markdown
------
## Cách hoạt động của Typora
Ở chế độ **Custom Command**, Typora sẽ gọi script kiểu như:
```bash
/path/to/upload-image.sh "image-path-1" "image-path-2"
```
Script của bạn phải in ra **đúng số dòng URL cuối cùng**, mỗi ảnh một dòng. Ví dụ:
```text
https://git.tltdb.com/Typora/Uploads/raw/branch/main/uploads/2026/04/a.png
https://git.tltdb.com/Typora/Uploads/raw/branch/main/uploads/2026/04/b.png
```
Typora sẽ lấy các dòng đó để thay ảnh local trong Markdown.
------
## Phần 1 — Tạo repo trên Gitea
Bạn đã có repo này:
```text
https://git.tltdb.com/Typora/Uploads.git
```
Repo này sẽ dùng để chứa ảnh.
### Khuyến nghị
- Nên để repo là **public** nếu bạn muốn ảnh hiển thị ở mọi nơi.
- Nếu repo là **private**, link ảnh raw thường sẽ không hiện với người chưa đăng nhập.
------
## Phần 2 — Chuẩn bị repo local trên máy
Mở Terminal và chạy:
```bash
mkdir -p ~/typora-uploads
cd ~/typora-uploads
git init -b main
echo "# Typora Uploads" > README.md
git add .
git commit -m "init: first commit"
git remote add origin https://git.tltdb.com/Typora/Uploads.git
git push -u origin main
```
Nếu repo đã có sẵn local rồi thì chỉ cần:
```bash
cd ~/typora-uploads
git remote remove origin 2>/dev/null || true
git remote add origin https://git.tltdb.com/Typora/Uploads.git
git branch -M main
git push -u origin main
```
------
## Phần 3 — Thiết lập đăng nhập Gitea cho Git
Bạn có username là `tltdb` và có token. Cách tốt nhất là **không nhét token trực tiếp vào URL remote**.
### Cách khuyên dùng: dùng `~/.netrc`
Tạo file:
```bash
nano ~/.netrc
```
Dán nội dung:
```text
machine git.tltdb.com
login tltdb
password YOUR_TOKEN_HERE
```
Lưu lại, rồi chạy:
```bash
chmod 600 ~/.netrc
```
Sau đó giữ remote sạch như sau:
```bash
git remote set-url origin https://git.tltdb.com/Typora/Uploads.git
```
### Vì sao nên dùng `.netrc`
- không lộ token trong lệnh
- không lộ trong `.git/config`
- hợp với script tự động của Typora
------
## Phần 4 — Tạo script upload cho Typora
Tạo file script:
```bash
mkdir -p ~/bin
nano ~/bin/typora-gitea-upload.sh
```
Dán toàn bộ nội dung này:
```bash
#!/usr/bin/env bash
set -euo pipefail
# ===== CONFIG =====
REPO_DIR="$HOME/typora-uploads"
BASE_URL="https://git.tltdb.com/Typora/Uploads/raw/branch/main"
UPLOAD_ROOT="uploads/$(date +%Y/%m)"
# ===== CHECK =====
if [ ! -d "$REPO_DIR/.git" ]; then
echo "ERROR: Repo not found at $REPO_DIR" >&2
exit 1
fi
cd "$REPO_DIR"
# Ensure repo is on main
git checkout main >/dev/null 2>&1 || git checkout -b main >/dev/null 2>&1
urls=()
for src in "$@"; do
if [ ! -f "$src" ]; then
echo "ERROR: File not found: $src" >&2
exit 1
fi
filename="$(basename "$src")"
ext="${filename##*.}"
stem="${filename%.*}"
# sanitize name
safe_stem="$(echo "$stem" | tr ' ' '-' | tr -cd '[:alnum:]._-' )"
unique_name="${safe_stem}-$(date +%s)-$RANDOM.${ext}"
target_dir="$REPO_DIR/$UPLOAD_ROOT"
target_rel="$UPLOAD_ROOT/$unique_name"
target_abs="$REPO_DIR/$target_rel"
mkdir -p "$target_dir"
cp "$src" "$target_abs"
git add "$target_rel"
urls+=("$BASE_URL/$target_rel")
done
git commit -m "upload image(s) from Typora: $(date '+%Y-%m-%d %H:%M:%S')" >/dev/null 2>&1 || true
git push origin main >/dev/null
for url in "${urls[@]}"; do
echo "$url"
done
```
Lưu lại, rồi cấp quyền chạy:
```bash
chmod +x ~/bin/typora-gitea-upload.sh
```
------
## Phần 5 — Cấu hình Typora
Trong Typora:
**Preferences / Settings → Image**
Chọn:
- **When Insert Local Images** → `Upload Image`
- **Image Uploader** → `Custom Command`
Ô command nhập:
```bash
/Users/YOUR_MAC_USERNAME/bin/typora-gitea-upload.sh
```
Ví dụ nếu user macOS của bạn là `z`:
```bash
/Users/z/bin/typora-gitea-upload.sh
```
Sau đó bấm **Test Uploader**.
------
## Phần 6 — URL ảnh sẽ có dạng gì
Sau khi upload, ảnh sẽ có link kiểu:
```text
https://git.tltdb.com/Typora/Uploads/raw/branch/main/uploads/2026/04/ten-anh-123456.png
```
Typora sẽ thay ảnh local trong Markdown bằng link đó.
------
## Phần 7 — Cách test thủ công
Bạn có thể test script trước khi dùng trong Typora:
```bash
~/bin/typora-gitea-upload.sh "/path/to/test-image.png"
```
Nếu thành công, script sẽ in ra 1 dòng URL ảnh.
Sau đó bạn mở URL đó trên browser để kiểm tra ảnh có hiện không.
------
## Phần 8 — Những lỗi hay gặp
### 1. `Authentication failed`
Nguyên nhân:
- token sai
- `.netrc` sai format
- quyền token không đủ
Cách xử lý:
- kiểm tra lại `~/.netrc`
- kiểm tra lại token
- thử push tay:
```bash
cd ~/typora-uploads
git push origin main
```
------
### 2. `remote contains work that you do not have locally`
Chạy:
```bash
cd ~/typora-uploads
git pull --rebase origin main
git push origin main
```
------
### 3. Repo đang ở `master` thay vì `main`
Chạy:
```bash
cd ~/typora-uploads
git branch -M main
git push -u origin main
```
------
### 4. Ảnh không hiện trên website / Markdown viewer
Nguyên nhân thường là repo đang **private**.
Cách xử lý:
- đổi repo sang **public**
- hoặc dùng một host raw/static khác
------
### 5. Typora test không chạy
Kiểm tra:
- script có quyền chạy chưa
- đường dẫn script có đúng không
- thử chạy tay ngoài terminal trước
------
## Phần 9 — Cấu trúc repo khuyên dùng
Repo sẽ trông như sau:
```text
Uploads/
├── README.md
└── uploads/
└── 2026/
└── 04/
├── image-a.png
├── image-b.jpg
└── image-c.webp
```
Cách này gọn, dễ quản lý theo tháng.
------
## Phần 10 — Khuyến nghị bảo mật
Không nên dùng kiểu này lâu dài:
```bash
https://username:token@git.tltdb.com/Typora/Uploads.git
```
Vì token dễ lộ trong:
- shell history
- screenshot
- file config git
Nên dùng `.netrc` như hướng dẫn ở trên.
Nếu token hiện tại đã từng bị dán công khai, nên tạo token mới và thu hồi token cũ.
------
## Tóm tắt ngắn gọn
Bạn cần làm đúng 5 việc:
1. tạo repo Gitea `Typora/Uploads`
2. clone hoặc tạo repo local tại `~/typora-uploads`
3. cấu hình đăng nhập bằng `~/.netrc`
4. tạo script `~/bin/typora-gitea-upload.sh`
5. trỏ Typora sang script đó bằng **Custom Command**
Sau khi xong, mỗi lần dán ảnh vào Typora:
- ảnh sẽ được copy vào repo local
- git tự commit + push lên Gitea
- Typora tự thay bằng URL ảnh raw
Nếu bạn muốn, tôi có thể viết tiếp cho bạn bản **đã điền sẵn toàn bộ path theo đúng máy Mac của bạn**, chỉ để copy-paste chạy luôn.
Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 617 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 540 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 398 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 325 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 525 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 392 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 243 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 510 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 614 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 294 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 303 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 266 KiB