博客搭建(二)使用GitHub作为图床

使用 GitHub + jsDelivr 搭建免费图床

本文将介绍如何使用 GitHub 仓库作为图床,并通过 jsDelivr CDN 加速访问,实现免费且稳定的图片托管服务。

为什么选择 GitHub + jsDelivr?

  1. 完全免费
  2. 无容量限制
  3. 全球 CDN 加速
  4. 可靠的文件存储
  5. 方便的版本控制

配置步骤

1. 创建 GitHub 仓库

  1. 登录 GitHub 账号
  2. 创建新的公开仓库,例如 blog-images
  3. 初始化仓库,添加 README.md

2. 生成访问令牌

  1. 进入 GitHub 设置页面
  2. 选择 Developer settings -> Personal access tokens
  3. 生成新的令牌,勾选 repo 权限
  4. 保存生成的令牌字符串

3. 配置 PicGo

  1. 下载并安装 PicGo
  2. 在图床设置中选择 GitHub 图床
  3. 填写配置信息:
    • 仓库名:用户名/仓库名
    • 分支名:main
    • Token:之前生成的访问令牌
    • 存储路径:images/
    • 自定义域名:https://cdn.jsdelivr.net/gh/用户名/仓库名@main

使用方法

1. 使用 PicGo 上传

  1. 复制图片或选择文件
  2. 使用 PicGo 上传
  3. 自动获取 CDN 链接

2. 在 Markdown 中使用

![图片描述](https://cdn.jsdelivr.net/gh/用户名/仓库名@main/images/文件名)

3. 调整图片大小

使用 HTML 标签:

<img src="图片地址" width="300" alt="图片描述">

或使用 jsDelivr 参数:

![图片描述](图片地址?w=300)

注意事项

  1. 仓库必须是公开的
  2. 图片大小建议控制在 5MB 以内
  3. 使用有意义的文件名
  4. 定期清理不用的图片
  5. 备份重要图片

常见问题

  1. 上传失败:检查 Token 权限
  2. 图片无法显示:确认仓库是公开的
  3. CDN 缓存:等待刷新或使用不同的文件名

希望这篇教程能帮助你搭建自己的图床服务!

picgo 配置:
macOS系统安装完PicGo显示「文件已损坏」或者安装完打开没有反应
因为 PicGo 没有签名,所以会被 macOS 的安全检查所拦下。

安装后打开遇到「文件已损坏」的情况,请按如下方式操作:
信任开发者,会要求输入密码:

sudo spctl --master-disable

然后放行 PicGo :

xattr -cr /Applications/PicGo.app

然后就能正常打开。

如果提示以下内容

option -r not recognized

usage: xattr [-slz] file [file ...]
xattr -p [-slz] attr_name file [file ...]
xattr -w [-sz] attr_name attr_value file [file ...]
xattr -d [-s] attr_name file [file ...]
xattr -c [-s] file [file ...]

option -r not recognized

usage: xattr [-slz] file [file ...]
xattr -p [-slz] attr_name file [file ...]
xattr -w [-sz] attr_name attr_value file [file ...]
xattr -d [-s] attr_name file [file ...]
xattr -c [-s] file [file ...]

The first form lists the names of all xattrs on the given file(s).
The second form (-p) prints the value of the xattr attr_name.
The third form (-w) sets the value of the xattr attr_name to attr_value.
The fourth form (-d) deletes the xattr attr_name.
The fifth form (-c) deletes (clears) all xattrs.

options:
-h: print this help
-s: act on symbolic links themselves rather than their targets
-l: print long format (attr_name: attr_value)
-z: compress or decompress (if compressed) attribute value in zip format

执行命令

xattr -c /Applications/PicGo.app/*

如果上述命令依然没有效果,可以尝试下面的命令:

sudo xattr -d com.apple.quarantine /Applications/PicGo.app/

如果安装打开后没有反应,请按下方顺序排查:
macOS安装好之后,PicGo 是不会弹出主窗口的,因为 PicGo 在 macOS 系统里设计是个顶部栏应用。注意看你顶部栏的图标,如果有 PicGo 的图标,说明安装成功了,点击图标即可打开顶部栏窗口。参考上述第八点。
如果你是 M1 的系统,此前装过 PicGo 的 x64 版本,但是后来更新了 arm64 的版本发现打开后没反应,请重启电脑即可。

图片描述

图片描述