Skip to content

Commit e6326c9

Browse files
authored
update
1 parent 97b9ff7 commit e6326c9

10 files changed

Lines changed: 32 additions & 22 deletions

File tree

_config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
# layouts_dir: _layouts
99
# data_dir: _data
1010
# includes_dir: _includes
11-
# cache_dir: .jekyll-cache
12-
disable_disk_cache: true
11+
cache_dir: .jekyll-cache/v260607
12+
# disable_disk_cache: false
1313
sass:
1414
# sass_dir: _sass
1515
# minimal-mistakes

_launcher/shader.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ authors:
2424

2525
在对应的游戏版本管理页面,点击 `自动安装` ,你会看到有个 `OptiFine` 的选项。
2626

27-
![OptiFine_AutoInstaller](/assets/img/docs/shader/install_auto-16338577874692.png)
27+
![OptiFine_AutoInstaller](/assets/img/docs/shader/install_auto.png)
2828

2929
点开之后选择合适的版本然后等待安装完成即可。
3030
目前,如果要在 `Fabric` 使用 `OptiFine` ,需要通过 **方式四** 安装。

_plugins/filter-version-sort.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def valid_string_array?(array, property)
1414
end
1515

1616
def version_to_numbers(version_string)
17-
version_string.split('.').map { |n| n.to_i }
17+
version_string.split(".").map { |n| n.to_i }
1818
end
1919
end
2020

_plugins/kramdown_enhancer.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ def relative_url(input)
167167
end
168168

169169
Jekyll::Hooks.register :site, :post_read do |site|
170+
cache = Jekyll::Cache.new("KramdownEnhancer")
170171
KramdownEnhancer.baseurl = site.config["baseurl"]
171172
webp_list = []
172173
site.each_site_file do |file|
@@ -178,9 +179,17 @@ def relative_url(input)
178179
if File.exist?(source)
179180
KramdownEnhancer.webp[file.url] = url
180181
elsif %w[.png .jpg .jpeg .tif .tiff].include?(file.extname.downcase)
182+
source_base64 = Base64.encode64(File.read(file.path, mode: "rb"))
183+
hash = Digest::SHA256.hexdigest(source_base64)
184+
if cache.key?("webp_#{hash}")
185+
Jekyll.logger.info "Kramdown Enhancer:", "[webp] Hit Cache #{url}"
186+
else
187+
destination_base64 = Script.call("webp", source: source_base64)
188+
cache["webp_#{hash}"] = Base64.decode64(destination_base64)
189+
Jekyll.logger.info "Kramdown Enhancer:", "[webp] Generated #{url}"
190+
end
181191
FileUtils.mkdir_p(File.dirname(destination))
182-
result = Node.call("webp", source: file.path, destination: destination)
183-
Jekyll.logger.info "Kramdown Enhancer:", "[webp] Generated #{result}"
192+
File.write(destination, cache["webp_#{hash}"], mode: "wb")
184193
webp_list.push(KramdownEnhancer::WebpFile.new(site, site.dest, File.dirname(url), File.basename(url)))
185194
KramdownEnhancer.webp[file.url] = url
186195
end

_plugins/post_process.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
if terser_inputs_all_exist
2323
destination = File.join(site.dest, terser_output.to_s)
24-
File.write(destination, Node.call("terser", code: terser_codes.join(";")))
24+
File.write(destination, Script.call("terser", code: terser_codes.join(";")))
2525
Jekyll.logger.info "Post Process:", "[terser] #{terser_output}"
2626
end
2727
end
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
require "json"
2-
require "open3"
3-
4-
module Node
1+
module Script
52
class << self
63
attr_reader :runtime
74

@@ -10,23 +7,29 @@ def init
107
stdout, _, status = Open3.capture3("bun", "-v")
118
if status.success?
129
@runtime = "bun"
13-
Jekyll.logger.info "Node:", "[init] #{@runtime} #{stdout}"
10+
Jekyll.logger.info "Script:", "[init] #{@runtime} #{stdout}"
1411
return
1512
end
1613
rescue
14+
# Ignored
1715
end
1816

1917
stdout, stderr, status = Open3.capture3("node", "-v")
2018
raise stderr unless status.success?
2119
@runtime = "node"
22-
Jekyll.logger.info "Node:", "[init] #{@runtime} #{stdout}"
20+
Jekyll.logger.info "Script:", "[init] #{@runtime} #{stdout}"
2321
end
2422

2523
def call(name, param)
2624
init unless @runtime
27-
stdout, stderr, status = Open3.capture3(@runtime, "_plugins/scripts/call.js", stdin_data: {"name": name, "param": param}.to_json)
25+
uuid = SecureRandom.uuid
26+
stdout, stderr, status = Open3.capture3(@runtime, "_plugins/scripts/call.js", stdin_data: {"name": name, "param": param, "uuid": uuid}.to_json)
2827
raise stderr unless status.success?
29-
JSON.parse(stdout)
28+
log, _, result = stdout.rpartition(uuid)
29+
log.split("\n").map do |line|
30+
Jekyll.logger.info "Script:", "[log] #{line}"
31+
end
32+
JSON.parse(result)
3033
end
3134
end
3235
end

_plugins/scripts/call.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ process.stdin.on("end", async () => {
88
const data = JSON.parse(input);
99
const mod = await import("./" + data.name + ".js");
1010
const result = await mod.default(data.param);
11+
console.log(data.uuid);
1112
console.log(JSON.stringify(result));
1213
});

_plugins/scripts/webp.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
import fs from "fs";
2-
import path from "path";
31
import sharp from "sharp";
42

5-
export default async function ({ source, destination }) {
3+
export default async function ({ source }) {
4+
const buffer = new Buffer(source, "base64");
65
if (global.Bun && Bun.Image) {
7-
await Bun.file(source).image().webp().write(destination);
8-
} else {
9-
await sharp(source).toFile(destination);
6+
return new Blob(buffer).image().webp().toBase64();
107
}
11-
return path.relative("./", destination);
8+
return (await sharp(buffer).webp().toBuffer()).toString("base64");
129
}
-282 KB
Binary file not shown.
-130 KB
Binary file not shown.

0 commit comments

Comments
 (0)