Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ clone:

steps:
- name: build
image: ruby:3.4
image: cimg/ruby:3.4.9-node
environment:
JEKYLL_ENV: production
BUNDLE_PATH: vendor/bundle
commands:
- npm config set registry http://mirrors.cloud.tencent.com/npm
- npm install
- bundle config mirror.https://rubygems.org https://mirrors.cloud.tencent.com/rubygems
- bundle install --verbose
- bundle exec jekyll build --trace --verbose
Expand All @@ -22,6 +24,8 @@ steps:
path: /drone/src/vendor
- name: jekyll-cache
path: /drone/src/.jekyll-cache
- name: node_modules
path: /drone/src/node_modules
when:
branch: [main]

Expand All @@ -35,3 +39,6 @@ volumes:
- name: jekyll-cache
host:
path: /home/ubuntu/docs.hmcl.net/cache/jekyll-cache
- name: node_modules
host:
path: /home/ubuntu/docs.hmcl.net/cache/node_modules
8 changes: 5 additions & 3 deletions .github/workflows/pr-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,14 @@ jobs:
git fetch https://github.com/${{ needs.preview-create-init.outputs.repository }} ${{ needs.preview-create-init.outputs.sha }}
git merge --squash ${{ needs.preview-create-init.outputs.sha }} --no-edit
git commit -m "Merge #${{ env.GITHUB_PR_NUMBER }} for preview build"
- name: Setup node
uses: actions/setup-node@v6
with:
node-version: 24
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.4"
bundler-cache: ${{ env.PREVIEW_WATCH }}
cache-version: PR-${{ env.GITHUB_PR_NUMBER }}
- name: Jekyll Build
run: |
echo "url: https://${{ needs.preview-create-init.outputs.domain }}" > _action.yml
Expand All @@ -239,7 +241,7 @@ jobs:
echo "destination: /home/runner/site" >> _action.yml
echo "preview:" >> _action.yml
echo " pr-number: ${{ env.GITHUB_PR_NUMBER }}" >> _action.yml
${{ env.PREVIEW_WATCH }} || bundle install --jobs 4
npm install && bundle install --jobs 4
bundle exec jekyll build --trace --config _config.yml,_action.yml
- id: upload-site
name: Upload Site
Expand Down
24 changes: 17 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
_site
.sass-cache
.jekyll-cache
.jekyll-metadata
vendor
Gemfile.lock
.sass-cache/
.jekyll-cache/
.jekyll-metadata/

/.idea/

/_site/

/vendor/
/node_modules/

.bundle
/.idea/

/Gemfile.lock
/package-lock.json
/yarn.lock
/pnpm-lock.yaml
/bun.lock
4 changes: 1 addition & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,4 @@ gem "wdm", "0.2.0", :platforms => [:windows]
gem "http_parser.rb", "0.8.0", :platforms => [:jruby]

# plugin dependencies
gem "webp-ffi", "0.4.0" if ENV["ENABLE_WEBP_AUTO_CONVERSION"] == "true" || ENV["DRONE"] == "true"
gem "mini_racer", "0.20.0" if ENV["ENABLE_EMBEDDED_V8"] == "true" || ENV["DRONE"] == "true"
gem "terser", "1.2.7"
gem "open3", "0.2.1"
22 changes: 13 additions & 9 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
# layouts_dir: _layouts
# data_dir: _data
# includes_dir: _includes
# cache_dir: .jekyll-cache
disable_disk_cache: true
cache_dir: .jekyll-cache/v260607
# disable_disk_cache: false
sass:
# sass_dir: _sass
# minimal-mistakes
Expand Down Expand Up @@ -50,6 +50,13 @@ include:
exclude:
- README.md
- LICENSE
- tsconfig.json
- tsconfig.node.json
- package.json
- package-lock.json
- yarn.lock
- pnpm-lock.yaml
- bun.lock
keep_files: []
encoding: "utf-8"
# markdown_ext: "markdown,mkdown,mkdn,mkd,md"
Expand Down Expand Up @@ -328,9 +335,6 @@ feed:
post_process:
terser:
/assets/js/main.min.js:
- /assets/js/settings.js
- /assets/js/theme.js
- /assets/js/meta.js
- /assets/js/vendor/jquery/jquery-3.6.0.js
- /assets/js/plugins/gumshoe.js
- /assets/js/plugins/jquery.ba-throttle-debounce.js
Expand All @@ -339,14 +343,14 @@ post_process:
- /assets/js/plugins/jquery.magnific-popup.js
- /assets/js/plugins/smooth-scroll.js
- /assets/js/plugins/jquery.auto-redirect.js
- /assets/js/extend.ts.js
- /assets/js/_main.js
remove_dirs:
- /assets/images/
- /assets/js/plugins/
- /assets/js/lunr/
- /assets/js/vendor/
- /assets/js/plugins/
remove_files:
- /assets/js/meta.js
- /assets/js/_main.js
- /assets/js/theme.js
- /assets/js/settings.js
- /assets/js/extend.ts.js
- /assets/js/main.min.js.map
2 changes: 1 addition & 1 deletion _launcher/shader.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ authors:

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

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

点开之后选择合适的版本然后等待安装完成即可。
目前,如果要在 `Fabric` 使用 `OptiFine` ,需要通过 **方式四** 安装。
Expand Down
19 changes: 12 additions & 7 deletions _plugins/kramdown_enhancer.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
begin
require "webp-ffi"
rescue LoadError; end

module KramdownEnhancer
CACHE = Jekyll::Cache.new("KramdownEnhancer")
GITHUB_LINK_REGEX = /\b(GP-\d+|GC-[0-9a-f]{7})\b/
BLOCKQUOTE_TYPES = {
note: "notice--info",
Expand Down Expand Up @@ -173,7 +170,6 @@ def relative_url(input)
Jekyll::Hooks.register :site, :post_read do |site|
KramdownEnhancer.baseurl = site.config["baseurl"]
webp_list = []
webp_enabled = defined?(WebP)
site.each_site_file do |file|
KramdownEnhancer.file[file.relative_path] = file
if file.is_a?(Jekyll::StaticFile)
Expand All @@ -182,9 +178,18 @@ def relative_url(input)
destination = File.join(site.dest, url)
if File.exist?(source)
KramdownEnhancer.webp[file.url] = url
elsif webp_enabled && %w[.png .jpg .jpeg .tif .tiff].include?(file.extname.downcase)
elsif Jekyll.env == "production" && %w[.png .jpg .jpeg .tif .tiff].include?(file.extname.downcase)
source_base64 = Base64.encode64(File.read(file.path, mode: "rb"))
hash = Digest::SHA256.hexdigest(source_base64)
if KramdownEnhancer::CACHE.key?("webp_#{hash}")
Jekyll.logger.info "Kramdown Enhancer:", "[webp] Hit Cache #{url}"
else
destination_base64 = Script.call("webp", source: source_base64)
KramdownEnhancer::CACHE["webp_#{hash}"] = Base64.decode64(destination_base64)
Jekyll.logger.info "Kramdown Enhancer:", "[webp] Generated #{url}"
end
FileUtils.mkdir_p(File.dirname(destination))
WebP.encode(file.path, destination)
File.write(destination, KramdownEnhancer::CACHE["webp_#{hash}"], mode: "wb")
webp_list.push(KramdownEnhancer::WebpFile.new(site, site.dest, File.dirname(url), File.basename(url)))
KramdownEnhancer.webp[file.url] = url
end
Expand Down
124 changes: 73 additions & 51 deletions _plugins/post_process.rb
Original file line number Diff line number Diff line change
@@ -1,51 +1,73 @@
require "terser"

ExecJS.runtime = ExecJS::Runtimes::MiniRacer if ExecJS::Runtimes::MiniRacer.available?

Jekyll::Hooks.register :site, :post_write do |site|
config = site.config["post_process"]
next unless config

terser = config["terser"]
if terser.is_a?(Hash)
terser.each do |terser_output, terser_inputs|
next unless terser_output.is_a?(String) && terser_inputs.is_a?(Array)

terser_codes = []
terser_inputs_all_exist = true
terser_inputs.each do |file|
destination = File.join(site.dest, file)
if File.exist?(destination)
terser_codes << File.read(destination, encoding: "UTF-8")
else
terser_inputs_all_exist = false
break
end
end

if terser_inputs_all_exist
destination = File.join(site.dest, terser_output.to_s)
File.write(destination, Terser.compile(terser_codes.join(";")))
Jekyll.logger.info "Post Process:", "terser #{terser_output}"
end
end
end

remove_files = config["remove_files"]
if remove_files.is_a?(Array)
remove_files.each do |file|
destination = File.join(site.dest, file)
File.delete(destination) if File.exist?(destination)
Jekyll.logger.info "Post Process:", "remove_files #{file}"
end
end

remove_dirs = config["remove_dirs"]
if remove_dirs.is_a?(Array)
remove_dirs.each do |dir|
destination = File.join(site.dest, dir)
FileUtils.rm_rf(destination) if File.directory?(destination)
Jekyll.logger.info "Post Process:", "remove_dirs #{dir}"
end
end
end
Jekyll::Hooks.register :site, :post_write do |site|
config = site.config["post_process"]
next unless config

cache = nil
terser = config["terser"]
if terser.is_a?(Hash)
terser.each do |terser_output, terser_inputs|
next unless terser_output.is_a?(String) && terser_inputs.is_a?(Array)

cache = Jekyll::Cache.new("PostProcess") unless cache
terser_codes = []
terser_inputs_all_exist = true
terser_inputs.each do |file|
destination = File.join(site.dest, file)
if File.exist?(destination)
terser_codes << File.read(destination, encoding: "UTF-8")
else
terser_inputs_all_exist = false
break
end
end

if terser_inputs_all_exist
destination = File.join(site.dest, terser_output.to_s)
code = terser_codes.join(";")
hash = Digest::SHA256.hexdigest(code)
unless cache.key?("terser_#{hash}")
cache["terser_#{hash}"] = Script.call("terser", code: code)
end
File.write(destination, cache["terser_#{hash}"])
Jekyll.logger.info "Post Process:", "[terser] #{terser_output}"
end
end
end

remove_files = config["remove_files"]
if remove_files.is_a?(Array)
remove_files.each do |file|
destination = File.join(site.dest, file)
File.delete(destination) if File.exist?(destination)
Jekyll.logger.info "Post Process:", "[remove_files] #{file}"
end
end

remove_dirs = config["remove_dirs"]
if remove_dirs.is_a?(Array)
remove_dirs.each do |dir|
destination = File.join(site.dest, dir)
FileUtils.rm_rf(destination) if File.directory?(destination)
Jekyll.logger.info "Post Process:", "[remove_dirs] #{dir}"
end
end

# clean history jekyll cache
jekyll_cache_dir = File.dirname(site.cache_dir)
current_cache_name = File.basename(site.cache_dir)
if File.basename(jekyll_cache_dir) == ".jekyll-cache"
Dir.entries(jekyll_cache_dir).select do |entry|
next if entry == "." || entry == ".."
entry_path = File.join(jekyll_cache_dir, entry)
if File.file?(entry_path)
File.delete(entry_path)
Jekyll.logger.info "Post Process:", "[clean_history_jekyll_cache] #{entry}"
elsif File.directory?(entry_path)
if entry < current_cache_name
FileUtils.rm_rf(entry_path)
Jekyll.logger.info "Post Process:", "[clean_history_jekyll_cache] #{entry}"
end
end
end
end
end
33 changes: 33 additions & 0 deletions _plugins/script.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module Script
class << self
def init
begin
stdout, _, status = Open3.capture3("bun", "-v")
if status.success?
@runtime = "bun"
Jekyll.logger.info "Script:", "[init] #{@runtime} #{stdout}"
return
end
rescue
# Ignored
end

stdout, stderr, status = Open3.capture3("node", "-v")
raise stderr unless status.success?
@runtime = "node"
Jekyll.logger.info "Script:", "[init] #{@runtime} #{stdout}"
end

def call(name, param)
init unless @runtime
uuid = SecureRandom.uuid
stdout, stderr, status = Open3.capture3(@runtime, "_plugins/scripts/call.js", stdin_data: {"name": name, "param": param, "uuid": uuid}.to_json)
raise stderr unless status.success?
log, _, result = stdout.rpartition(uuid)
log.split("\n").map do |line|
Jekyll.logger.info "Script:", "[#{name}] #{line}"
end
JSON.parse(result)
end
end
end
13 changes: 13 additions & 0 deletions _plugins/scripts/call.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
let input = "";

process.stdin.on("data", (chunk) => {
input += chunk;
});

process.stdin.on("end", async () => {
const data = JSON.parse(input);
const mod = await import("./" + data.name + ".js");
const result = await mod.default(data.param);
console.log(data.uuid);
console.log(JSON.stringify(result));
});
9 changes: 9 additions & 0 deletions _plugins/scripts/terser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { minify } from "terser";

export default async function ({ code }) {
const result = await minify(code, {
compress: false,
mangle: true
});
return result.code;
}
Loading