Skip to content

Commit d2caa30

Browse files
authored
修改构建镜像为 cimg/ruby:3.4.9-node
1 parent 8898bb5 commit d2caa30

22 files changed

Lines changed: 321 additions & 119 deletions

.drone.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ clone:
77

88
steps:
99
- name: build
10-
image: ruby:3.4
10+
image: cimg/ruby:3.4.9-node
1111
environment:
1212
JEKYLL_ENV: production
1313
BUNDLE_PATH: vendor/bundle
1414
commands:
15+
- npm config set registry http://mirrors.cloud.tencent.com/npm
16+
- npm install
1517
- bundle config mirror.https://rubygems.org https://mirrors.cloud.tencent.com/rubygems
1618
- bundle install --verbose
1719
- bundle exec jekyll build --trace --verbose
@@ -22,6 +24,8 @@ steps:
2224
path: /drone/src/vendor
2325
- name: jekyll-cache
2426
path: /drone/src/.jekyll-cache
27+
- name: node_modules
28+
path: /drone/src/node_modules
2529
when:
2630
branch: [main]
2731

@@ -35,3 +39,6 @@ volumes:
3539
- name: jekyll-cache
3640
host:
3741
path: /home/ubuntu/docs.hmcl.net/cache/jekyll-cache
42+
- name: node_modules
43+
host:
44+
path: /home/ubuntu/docs.hmcl.net/cache/node_modules

.github/workflows/pr-preview.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,14 @@ jobs:
225225
git fetch https://github.com/${{ needs.preview-create-init.outputs.repository }} ${{ needs.preview-create-init.outputs.sha }}
226226
git merge --squash ${{ needs.preview-create-init.outputs.sha }} --no-edit
227227
git commit -m "Merge #${{ env.GITHUB_PR_NUMBER }} for preview build"
228+
- name: Setup node
229+
uses: actions/setup-node@v6
230+
with:
231+
node-version: 24
228232
- name: Setup Ruby
229233
uses: ruby/setup-ruby@v1
230234
with:
231235
ruby-version: "3.4"
232-
bundler-cache: ${{ env.PREVIEW_WATCH }}
233-
cache-version: PR-${{ env.GITHUB_PR_NUMBER }}
234236
- name: Jekyll Build
235237
run: |
236238
echo "url: https://${{ needs.preview-create-init.outputs.domain }}" > _action.yml
@@ -239,7 +241,7 @@ jobs:
239241
echo "destination: /home/runner/site" >> _action.yml
240242
echo "preview:" >> _action.yml
241243
echo " pr-number: ${{ env.GITHUB_PR_NUMBER }}" >> _action.yml
242-
${{ env.PREVIEW_WATCH }} || bundle install --jobs 4
244+
npm install && bundle install --jobs 4
243245
bundle exec jekyll build --trace --config _config.yml,_action.yml
244246
- id: upload-site
245247
name: Upload Site

.gitignore

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1-
_site
2-
.sass-cache
3-
.jekyll-cache
4-
.jekyll-metadata
5-
vendor
6-
Gemfile.lock
1+
.sass-cache/
2+
.jekyll-cache/
3+
.jekyll-metadata/
4+
5+
/.idea/
6+
7+
/_site/
8+
9+
/vendor/
10+
/node_modules/
11+
712
.bundle
8-
/.idea/
13+
14+
/Gemfile.lock
15+
/package-lock.json
16+
/yarn.lock
17+
/pnpm-lock.yaml
18+
/bun.lock

Gemfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,4 @@ gem "wdm", "0.2.0", :platforms => [:windows]
3232
gem "http_parser.rb", "0.8.0", :platforms => [:jruby]
3333

3434
# plugin dependencies
35-
gem "webp-ffi", "0.4.0" if ENV["ENABLE_WEBP_AUTO_CONVERSION"] == "true" || ENV["DRONE"] == "true"
36-
gem "mini_racer", "0.20.0" if ENV["ENABLE_EMBEDDED_V8"] == "true" || ENV["DRONE"] == "true"
37-
gem "terser", "1.2.7"
35+
gem "open3", "0.2.1"

_config.yml

Lines changed: 13 additions & 5 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
@@ -50,6 +50,13 @@ include:
5050
exclude:
5151
- README.md
5252
- LICENSE
53+
- tsconfig.json
54+
- tsconfig.node.json
55+
- package.json
56+
- package-lock.json
57+
- yarn.lock
58+
- pnpm-lock.yaml
59+
- bun.lock
5360
keep_files: []
5461
encoding: "utf-8"
5562
# markdown_ext: "markdown,mkdown,mkdn,mkd,md"
@@ -330,7 +337,6 @@ post_process:
330337
/assets/js/main.min.js:
331338
- /assets/js/settings.js
332339
- /assets/js/theme.js
333-
- /assets/js/meta.js
334340
- /assets/js/vendor/jquery/jquery-3.6.0.js
335341
- /assets/js/plugins/gumshoe.js
336342
- /assets/js/plugins/jquery.ba-throttle-debounce.js
@@ -339,14 +345,16 @@ post_process:
339345
- /assets/js/plugins/jquery.magnific-popup.js
340346
- /assets/js/plugins/smooth-scroll.js
341347
- /assets/js/plugins/jquery.auto-redirect.js
348+
- /assets/js/meta.ts.js
342349
- /assets/js/_main.js
343350
remove_dirs:
344351
- /assets/images/
345-
- /assets/js/plugins/
352+
- /assets/js/lunr/
346353
- /assets/js/vendor/
354+
- /assets/js/plugins/
347355
remove_files:
348-
- /assets/js/meta.js
349356
- /assets/js/_main.js
350357
- /assets/js/theme.js
358+
- /assets/js/meta.ts.js
351359
- /assets/js/settings.js
352360
- /assets/js/main.min.js.map

_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/kramdown_enhancer.rb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
begin
2-
require "webp-ffi"
3-
rescue LoadError; end
4-
51
module KramdownEnhancer
2+
CACHE = Jekyll::Cache.new("KramdownEnhancer")
63
GITHUB_LINK_REGEX = /\b(GP-\d+|GC-[0-9a-f]{7})\b/
74
BLOCKQUOTE_TYPES = {
85
note: "notice--info",
@@ -173,7 +170,6 @@ def relative_url(input)
173170
Jekyll::Hooks.register :site, :post_read do |site|
174171
KramdownEnhancer.baseurl = site.config["baseurl"]
175172
webp_list = []
176-
webp_enabled = defined?(WebP)
177173
site.each_site_file do |file|
178174
KramdownEnhancer.file[file.relative_path] = file
179175
if file.is_a?(Jekyll::StaticFile)
@@ -182,9 +178,18 @@ def relative_url(input)
182178
destination = File.join(site.dest, url)
183179
if File.exist?(source)
184180
KramdownEnhancer.webp[file.url] = url
185-
elsif webp_enabled && %w[.png .jpg .jpeg .tif .tiff].include?(file.extname.downcase)
181+
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 KramdownEnhancer::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+
KramdownEnhancer::CACHE["webp_#{hash}"] = Base64.decode64(destination_base64)
189+
Jekyll.logger.info "Kramdown Enhancer:", "[webp] Generated #{url}"
190+
end
186191
FileUtils.mkdir_p(File.dirname(destination))
187-
WebP.encode(file.path, destination)
192+
File.write(destination, KramdownEnhancer::CACHE["webp_#{hash}"], mode: "wb")
188193
webp_list.push(KramdownEnhancer::WebpFile.new(site, site.dest, File.dirname(url), File.basename(url)))
189194
KramdownEnhancer.webp[file.url] = url
190195
end

_plugins/post_process.rb

Lines changed: 73 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,73 @@
1-
require "terser"
2-
3-
ExecJS.runtime = ExecJS::Runtimes::MiniRacer if ExecJS::Runtimes::MiniRacer.available?
4-
5-
Jekyll::Hooks.register :site, :post_write do |site|
6-
config = site.config["post_process"]
7-
next unless config
8-
9-
terser = config["terser"]
10-
if terser.is_a?(Hash)
11-
terser.each do |terser_output, terser_inputs|
12-
next unless terser_output.is_a?(String) && terser_inputs.is_a?(Array)
13-
14-
terser_codes = []
15-
terser_inputs_all_exist = true
16-
terser_inputs.each do |file|
17-
destination = File.join(site.dest, file)
18-
if File.exist?(destination)
19-
terser_codes << File.read(destination, encoding: "UTF-8")
20-
else
21-
terser_inputs_all_exist = false
22-
break
23-
end
24-
end
25-
26-
if terser_inputs_all_exist
27-
destination = File.join(site.dest, terser_output.to_s)
28-
File.write(destination, Terser.compile(terser_codes.join(";")))
29-
Jekyll.logger.info "Post Process:", "terser #{terser_output}"
30-
end
31-
end
32-
end
33-
34-
remove_files = config["remove_files"]
35-
if remove_files.is_a?(Array)
36-
remove_files.each do |file|
37-
destination = File.join(site.dest, file)
38-
File.delete(destination) if File.exist?(destination)
39-
Jekyll.logger.info "Post Process:", "remove_files #{file}"
40-
end
41-
end
42-
43-
remove_dirs = config["remove_dirs"]
44-
if remove_dirs.is_a?(Array)
45-
remove_dirs.each do |dir|
46-
destination = File.join(site.dest, dir)
47-
FileUtils.rm_rf(destination) if File.directory?(destination)
48-
Jekyll.logger.info "Post Process:", "remove_dirs #{dir}"
49-
end
50-
end
51-
end
1+
Jekyll::Hooks.register :site, :post_write do |site|
2+
config = site.config["post_process"]
3+
next unless config
4+
5+
cache = nil
6+
terser = config["terser"]
7+
if terser.is_a?(Hash)
8+
terser.each do |terser_output, terser_inputs|
9+
next unless terser_output.is_a?(String) && terser_inputs.is_a?(Array)
10+
11+
cache = Jekyll::Cache.new("PostProcess") unless cache
12+
terser_codes = []
13+
terser_inputs_all_exist = true
14+
terser_inputs.each do |file|
15+
destination = File.join(site.dest, file)
16+
if File.exist?(destination)
17+
terser_codes << File.read(destination, encoding: "UTF-8")
18+
else
19+
terser_inputs_all_exist = false
20+
break
21+
end
22+
end
23+
24+
if terser_inputs_all_exist
25+
destination = File.join(site.dest, terser_output.to_s)
26+
code = terser_codes.join(";")
27+
hash = Digest::SHA256.hexdigest(code)
28+
unless cache.key?("terser_#{hash}")
29+
cache["terser_#{hash}"] = Script.call("terser", code: code)
30+
end
31+
File.write(destination, cache["terser_#{hash}"])
32+
Jekyll.logger.info "Post Process:", "[terser] #{terser_output}"
33+
end
34+
end
35+
end
36+
37+
remove_files = config["remove_files"]
38+
if remove_files.is_a?(Array)
39+
remove_files.each do |file|
40+
destination = File.join(site.dest, file)
41+
File.delete(destination) if File.exist?(destination)
42+
Jekyll.logger.info "Post Process:", "[remove_files] #{file}"
43+
end
44+
end
45+
46+
remove_dirs = config["remove_dirs"]
47+
if remove_dirs.is_a?(Array)
48+
remove_dirs.each do |dir|
49+
destination = File.join(site.dest, dir)
50+
FileUtils.rm_rf(destination) if File.directory?(destination)
51+
Jekyll.logger.info "Post Process:", "[remove_dirs] #{dir}"
52+
end
53+
end
54+
55+
# clean history jekyll cache
56+
jekyll_cache_dir = File.dirname(site.cache_dir)
57+
current_cache_name = File.basename(site.cache_dir)
58+
if File.basename(jekyll_cache_dir) == ".jekyll-cache"
59+
Dir.entries(jekyll_cache_dir).select do |entry|
60+
next if entry == "." || entry == ".."
61+
entry_path = File.join(jekyll_cache_dir, entry)
62+
if File.file?(entry_path)
63+
File.delete(entry_path)
64+
Jekyll.logger.info "Post Process:", "[clean_history_jekyll_cache] #{entry}"
65+
elsif File.directory?(entry_path)
66+
if entry < current_cache_name
67+
FileUtils.rm_rf(entry_path)
68+
Jekyll.logger.info "Post Process:", "[clean_history_jekyll_cache] #{entry}"
69+
end
70+
end
71+
end
72+
end
73+
end

_plugins/script.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module Script
2+
class << self
3+
def init
4+
begin
5+
stdout, _, status = Open3.capture3("bun", "-v")
6+
if status.success?
7+
@runtime = "bun"
8+
Jekyll.logger.info "Script:", "[init] #{@runtime} #{stdout}"
9+
return
10+
end
11+
rescue
12+
# Ignored
13+
end
14+
15+
stdout, stderr, status = Open3.capture3("node", "-v")
16+
raise stderr unless status.success?
17+
@runtime = "node"
18+
Jekyll.logger.info "Script:", "[init] #{@runtime} #{stdout}"
19+
end
20+
21+
def call(name, param)
22+
init unless @runtime
23+
uuid = SecureRandom.uuid
24+
stdout, stderr, status = Open3.capture3(@runtime, "_plugins/scripts/call.js", stdin_data: {"name": name, "param": param, "uuid": uuid}.to_json)
25+
raise stderr unless status.success?
26+
log, _, result = stdout.rpartition(uuid)
27+
log.split("\n").map do |line|
28+
Jekyll.logger.info "Script:", "[#{name}] #{line}"
29+
end
30+
JSON.parse(result)
31+
end
32+
end
33+
end

_plugins/scripts/call.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
let input = "";
2+
3+
process.stdin.on("data", (chunk) => {
4+
input += chunk;
5+
});
6+
7+
process.stdin.on("end", async () => {
8+
const data = JSON.parse(input);
9+
const mod = await import("./" + data.name + ".js");
10+
const result = await mod.default(data.param);
11+
console.log(data.uuid);
12+
console.log(JSON.stringify(result));
13+
});

0 commit comments

Comments
 (0)