Skip to content
Draft
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
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,5 @@ 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"
5 changes: 5 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ include:
exclude:
- README.md
- LICENSE
- 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
19 changes: 12 additions & 7 deletions _plugins/kramdown_enhancer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
begin
require "webp-ffi"
rescue LoadError; end

module KramdownEnhancer
GITHUB_LINK_REGEX = /\b(GP-\d+|GC-[0-9a-f]{7})\b/
BLOCKQUOTE_TYPES = {
Expand Down Expand Up @@ -36,6 +32,16 @@ def baseurl=(input)
end
end

class WebP
class << self
def encode(source, destination)
stdout, stderr, status = Node::run("_plugins/kramdown_enhancer/webp.js", source, destination)
raise stderr unless status.success?
Jekyll.logger.info "KramdownEnhancer:", "[webp] Generated #{stdout}"
end
end
end

class WebpFile < Jekyll::StaticFile
def write(dest)
true
Expand Down Expand Up @@ -173,7 +179,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 +187,9 @@ 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 %w[.png .jpg .jpeg .tif .tiff].include?(file.extname.downcase)
FileUtils.mkdir_p(File.dirname(destination))
WebP.encode(file.path, destination)
KramdownEnhancer::WebP.encode(file.path, destination)
webp_list.push(KramdownEnhancer::WebpFile.new(site, site.dest, File.dirname(url), File.basename(url)))
KramdownEnhancer.webp[file.url] = url
end
Expand Down
22 changes: 22 additions & 0 deletions _plugins/kramdown_enhancer/webp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import fs from "fs";
import path from "path";
import sharp from "sharp";

const [source, destination] = process.argv.slice(2);

if (source === undefined || destination === undefined) {
throw new Error("param error");
}

if (!fs.existsSync(source)) {
throw new Error("source not exist");
}

const pwd = process.cwd();

sharp(source).toFile(destination, (err) => {
if (err) {
throw err;
}
console.log(path.relative(pwd, destination));
});
24 changes: 24 additions & 0 deletions _plugins/node.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require "open3"

module Node
class << self
def initialize
_, _, status = Open3.capture3("bun", "-v")
if status.success?
@runtime = "bun"
else
_, stderr, status = Open3.capture3("node", "-v")
raise stderr unless status.success?
@runtime = "node"
end
end

def run(*args)
if @runtime == "bun"
Open3.capture3("bun", "run", *args)
else
Open3.capture3("node", *args)
end
end
end
end
8 changes: 3 additions & 5 deletions _plugins/post_process.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
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
Expand All @@ -26,7 +24,7 @@
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}"
Jekyll.logger.info "Post Process:", "[terser] #{terser_output}"
end
end
end
Expand All @@ -36,7 +34,7 @@
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}"
Jekyll.logger.info "Post Process:", "[remove_files] #{file}"
end
end

Expand All @@ -45,7 +43,7 @@
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}"
Jekyll.logger.info "Post Process:", "[remove_dirs] #{dir}"
end
end
end
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"type": "module",
"dependencies": {
"sharp": "0.34.5"
},
"devDependencies": {
"@types/node": "25.9.1",
"typescript": "6.0.3"
}
}