-
-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Option to cache remote image locally. #860
Conversation
Now image.html can get width and height data from cached remote images, and the old style of setting width and height manually still works.
Someone is attempting to deploy a commit to a Personal Account owned by @HEIGE-PCloud on Vercel. @HEIGE-PCloud first needs to authorize it. |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感谢你的 PR!等配置文件和文档准备好了就可以合并了 :)
想问一下 |
我看了一下为为什么这张图片一直获取错误的原因 https://octodex.github.com/images/stormtroopocat.jpg https://github.com/gohugoio/hugo/blob/d33a7ebcc16e804f1db0dc1f1edad4d9f9e816ef/media/mediaType.go#L71 Hugo 会首先检测文件本身的 content-type,然后把它和 reponse 里收到的 content-type 做比较。 如果它们不相同就算识别失败。看注释这是期望行为。 这张图虽然结尾是 可能自己配置图床的时候也要小心点( |
我当时猜测也是http response的问题,不过没有仔细去查,这个获取失败调了很久才找到一个比较鲁棒的方式 |
配置文件和文档已准备完毕。 |
中文版本
通过hugo自带的
GetRemote
方程和一些比较鲁棒的匹配方式将图床上的图片缓存到本地,主要目的是解决图床图片不手动设置宽高就会出现懒加载布局偏移的问题,缓存是其次(hugo只能为存储到本地的图片获取宽高),我的想法是将这个功能作为可选项提供给用户(默认关闭),因为这个功能的Pros and Cons比较明显。优点
srcset
的内容可以基于hugo的image resize生成不同尺寸的加载图(参照MDN文档),甚至在resize的过程中实现普通图片转换为webp
格式。缺点
English version
With the
GetRemote
function provided by hugo and some robust matching methods, DoIt 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.Pros
webp
format while resizing.Cons