本篇文章属于Hugo学习路线Li.028一部分

1. Hugo中Markdown图片资源放在哪? 一直是个问题

引用其他资源担心其他网站改动路径, 就没了, 建立自己的网络图片资源库就显得很重要了.

存放Hugo的静态网站中, 引用起来不方便, 而且更新图片时必须更新网站, 强依赖.

所以一个独立的图片库就显示有必要了.

图片压缩也少不了.

2. 常用几种存放图片资源方式. Github 使用Nginx做为静态资源 自建私有云 自建图床 使用云存储服务.

2.1 Github或Gitee(国内理论理论速度更快) 公共项目存放图片资源. 这种方式只需要更新图片即可, 不需要更新静态博客, 管理更方便. 免费.

免费, 会使用git就可以. 也可使用图形界面PicGo上传图片到Github

示例, 复制文件下载链接即可在markdown使用

复制文件下载链接即可在markdown使用

复制文件下载链接即可在markdown使用

![number1](https://github.com/leezicai/share/raw/master/icon/number/1.png)

2.2 静态博客存放在Github, 图片也存放在同一项目下. 免费.

免费, 会使用Git

如果存放在Hugo文件夹中static中, 虽然文件生成在项目根目录下, 但在Github上地址从baseUrl开始的

# 图片存放在static文件夹下

https://github.com/adityatelange/hugo-PaperMod/tree/exampleSite/static 



# 图片地址起始https://adityatelange.github.io/hugo-PaperMod/
![papermod-cover.png](https://adityatelange.github.io/hugo-PaperMod/papermod-cover.png)
单个图片,如果有文件夹则添加

单个图片,如果有文件夹则添加

2.3 使用Nginx或其他服务器做静态资源. Nginx安装参考地址 , 付费, 需要服务器.

Nginx default.conf配置

使用sftp上传图片到服务器的s.lizicai.com文件夹下即可

server {
    listen       80;
    server_name  s.lizicai.com;
    return 301 https://s.lizicai.com$request_uri;
}
server {
    listen       443 ssl;
    server_name  s.lizicai.com;
    charset utf-8;
    ssl_certificate /root/cert/s.lizicai.com/fullchain.pem;
    ssl_certificate_key /root/cert/s.lizicai.com/private.key;
    location / {
        root   /root/s.lizicai.com/;
        index  index.html index.htm;
        autoindex on;
        autoindex_localtime on;
        autoindex_exact_size off;
    }
    error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /root/s.lizicai.com/;
        autoindex_localtime on;
        autoindex_exact_size off;
    }
}

示例地址 https://s.lizicai.com/icon/tags/ , 右键复制blue.png的链接

![tagblue](https://s.lizicai.com/icon/tags/blue.png)

2.4 搭建私有云盘, 图片和视频资源. Hugo中想使用个人视频服务的推荐, 付费, 需要服务器.

如NextCloud

2.5 部署一个图片服务, 开源图床服务ImgURL, 付费, 需要服务器.

官方安装文档地址

2.6 使用阿里腾讯云存储平台, 付费.

阿里云参考

3. 上传前的图片压缩软件.

ImageOptim 支持Mac

图压 支持Mac Windows

squoosh.app Chrome 浏览器应用 支持Mac Windows Linux

pinga 支持Windows