Skip to content

Commit d52e087

Browse files
NeverBehaveclaude
andcommitted
Add build-time image optimization with eleventy-img
Use eleventyImageTransformPlugin to automatically convert images to WebP with original format fallback, add lazy loading and async decoding to all images. Narrowed passthrough copy to src/assets/file only since images are now processed by the plugin. Fixed malformed image paths in two posts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2b4c355 commit d52e087

5 files changed

Lines changed: 429 additions & 9 deletions

File tree

eleventy.config.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import markdownItCjkBreaks from "markdown-it-cjk-breaks";
33
import markdownItImplicitFigures from "markdown-it-implicit-figures";
44
import markdownItFootnote from "markdown-it-footnote";
55
import markdownItAttrs from "markdown-it-attrs";
6+
import { eleventyImageTransformPlugin } from "@11ty/eleventy-img";
67
import syntaxHighlight from "@11ty/eleventy-plugin-syntaxhighlight";
78
import pluginRss from "@11ty/eleventy-plugin-rss";
89
import fs from "fs";
@@ -15,6 +16,15 @@ export default function (eleventyConfig) {
1516
// --- Plugins ---
1617
eleventyConfig.addPlugin(syntaxHighlight);
1718
eleventyConfig.addPlugin(pluginRss);
19+
eleventyConfig.addPlugin(eleventyImageTransformPlugin, {
20+
formats: ["webp", "auto"],
21+
widths: ["auto"],
22+
failOnError: false,
23+
defaultAttributes: {
24+
loading: "lazy",
25+
decoding: "async",
26+
},
27+
});
1828

1929
// --- Markdown ---
2030
const md = markdownIt({ html: true, linkify: true })
@@ -40,7 +50,7 @@ export default function (eleventyConfig) {
4050
});
4151

4252
// --- Passthrough copy ---
43-
eleventyConfig.addPassthroughCopy("src/assets");
53+
eleventyConfig.addPassthroughCopy("src/assets/file");
4454
eleventyConfig.addPassthroughCopy("src/static");
4555

4656
// --- Tailwind CSS ---

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
},
99
"devDependencies": {
1010
"@11ty/eleventy": "3",
11+
"@11ty/eleventy-img": "^6.0.4",
1112
"@11ty/eleventy-plugin-rss": "^3.0.0",
1213
"@11ty/eleventy-plugin-syntaxhighlight": "^5.0.2",
1314
"@tailwindcss/postcss": "^4.2.2",

src/posts/keep-your-google-voice-with-sao.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Tasker 是我当时为了挂国内短信卡而购入的一款自动化软件,
4242

4343
但是这个在 15 年的时候就停止了, 但是作者在帖子某个帖子下面回复说, 为了方便维护, 转向一个系列叫做[AutoApps](https://joaoapps.com/autoapps/)
4444

45-
![](.//assets/media/keep-your-google-voice-with-sao/autoapps.png)
45+
![](/assets/media/keep-your-google-voice-with-sao/autoapps.png)
4646

4747
简单点来说, 大约就是把各个子功能单独强化并作为`Tasker`兼容的组件单独出售, 一开始让我确实感觉有点被欺骗, 但是单个组件支持看广告免费试用, 买断或者是集体订阅
4848

@@ -60,11 +60,11 @@ Tasker 是我当时为了挂国内短信卡而购入的一款自动化软件,
6060

6161
在免费试用期测试完整以后便买断了这个组件
6262

63-
![](.//assets/media/keep-your-google-voice-with-sao/play_store_1.png)
63+
![](/assets/media/keep-your-google-voice-with-sao/play_store_1.png)
6464

6565
注意一下各个组件价格还不一样的, 有些功能少的价格便宜, 多的也就贵一点, 看论坛整体生态还是不错的, 还支持不少第三方插件
6666

67-
![](.//assets/media/keep-your-google-voice-with-sao/result.png)
67+
![](/assets/media/keep-your-google-voice-with-sao/result.png)
6868

6969
### 已知问题
7070

src/posts/moving-my-blog-2.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ https://www.h404bi.com/blog/2019/04/recent-changes-of-my-site
3939

4040
---
4141

42-
![Github Sponsor](../assets/media/..//assets/media/moving-my-blog-2/sponsor.png)
42+
![Github Sponsor](/assets/media/moving-my-blog-2/sponsor.png)
4343

4444
整体体验还行, 顺便试试看新开的`Amex`
4545

0 commit comments

Comments
 (0)