在使用Markdown编辑器(如Typora)撰写技术文档、博客文章时,本地图片的引用存在明显局限性:文档分享时图片无法显示、占用存储空间、加载速度慢。通过搭建Gitee图床配合自定义域名代理,可实现:
projects权限1. 下载安装PicGo(支持Windows/macOS/Linux)
2. 安装Gitee插件:
`
PicGo设置 → 插件设置 → 搜索gitee-uploader
`
3. 图床配置:
`json
{
"repo": "用户名/仓库名",
"branch": "master",
"token": "你的私人令牌",
"path": "img/",
"customUrl": "https://gitee.com/用户名/仓库名/raw/master"
}
`
Gitee原始链接存在:
方案A:CloudFlare Workers代理(推荐)`javascript
// worker.js 代码示例
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const url = new URL(request.url)
const giteeUrl = https://gitee.com/你的用户名/仓库名/raw/master${url.pathname}
return fetch(giteeUrl, {
headers: {
'User-Agent': 'Mozilla/5.0'
}
})
}`
方案B:Nginx反向代理`nginx
server {
listen 80;
servername img.yourdomain.com;
location / {
proxypass https://gitee.com/你的用户名/仓库名/raw/master/;
proxysetheader Referer "https://gitee.com";
proxysslserver_name on;
}
}`
- 在PicGo中安装picgo-plugin-compress插件
- 配置自动压缩参数:
`
最大宽度:1920px
质量:85%
保留EXIF信息:否
`
对于已有文档的图片迁移:`python
# Python脚本示例
import re
import requests
from pathlib import Path
def replaceimagelinks(mdfile):
with open(mdfile, 'r', encoding='utf-8') as f:
content = f.read()
# 匹配本地图片链接并替换
pattern = r'!\[.?\]\((.?\.(?:jpg|png|gif))\)'
# 此处添加你的上传逻辑
`
通过Typora+PicGo+Gitee+域名代理的组合方案,我们成功构建了一个稳定、高效、可控的图文工作流。这套方案不仅解决了Markdown写作中的图片管理痛点,还通过自定义代理服务提升了访问体验和可控性。随着需求的增长,可进一步扩展为多CDN分发、智能压缩等高级功能,打造专属的云端图文管理系统。
提示:技术方案需要根据实际使用场景调整,建议先在测试环境验证完整流程。
如若转载,请注明出处:http://www.dianditaoquan.com/product/74.html
更新时间:2026-03-27 07:12:01
PRODUCT