hugo-fixit / FixIt

🔧 A clean, elegant but advanced blog theme for Hugo 一个简洁、优雅且高效的 Hugo 主题
https://fixit.lruihao.cn
MIT License
769 stars 106 forks source link

Add option to cache remote image locally #362

Closed Lruihao closed 1 year ago

Lruihao commented 1 year ago

Why

With the GetRemote function provided by hugo and some robust matching methods, FixIt now can cache remote images locally. This feature mainly focus on adding height and width to remote images in markdown to prevent layout shifts, caching these images locally is more like an added benefit. The advantages and disadvantages of this feature are relatively obvious, so it will be offered as an option(off by default) to the user.

Fixes #348

Pros

Cons

Reference

vercel[bot] commented 1 year ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
fixit ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 26, 2023 8:52am
Lruihao commented 1 year ago

处理思路

  1. 缓存图床图片到本地
  2. 获取图片的宽高并设置
  3. 可选择是否使用本地图片覆盖图床图片地址

配置

0.3.0 迁移到 params.page.cacheRemoteImages

目前的思路虽然解决了图床图片无法获取高度导致懒加载时锚点跳转错位的问题,但是又带来了不少弊端,所以该配置为试验性功能,需要的自行开启:

# FixIt 0.3.0 | NEW [Experimental] cache remote images locally, see: https://github.com/hugo-fixit/FixIt/pull/362
# FixIt 0.3.0 | 新增 [试验性功能] 缓存图床图片到本地,详见:https://github.com/hugo-fixit/FixIt/pull/362
[params.page.cacheRemoteImages]
  enable = false
  # replace remote image url with local image url
  # 用本地图片链接替换远程图片链接
  replace = false