Skip to content

修改构建镜像为 cimg/ruby:3.4.9-node#468

Open
neveler wants to merge 6 commits into
HMCL-dev:mainfrom
neveler:node
Open

修改构建镜像为 cimg/ruby:3.4.9-node#468
neveler wants to merge 6 commits into
HMCL-dev:mainfrom
neveler:node

Conversation

@neveler

@neveler neveler commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

修改构建镜像为 cimg/ruby:3.4.9-node

自引入 mini_racer 之后,项目就具备了运行 js 代码的能力。鉴于 execjs 兼容多平台 js 引擎的限制,使用 execjs 执行 js 代码会有很多限制。

https://github.com/CircleCI-Public/cimg-ruby/blob/main/3.4/node/Dockerfile

因此,本 PR 旨在改用环境中自带 node 的镜像用于站点构建。


  • 修改构建镜像为 cimg/ruby:3.4.9-node: 新镜像构建环境中包含 nodejs 环境
  • webp: 旧插件因镜像环境变更而无法继续使用,使用 node / bun 自动生成图片 webp 格式
  • terser: 使用 node / bun 调用 terser 压缩 javascript 代码产物
  • 添加删除路径 /assets/js/lunr/
  • 重新启用 jekyll 缓存
  • 移除重复的静态资源
  • 添加 ts 转换器:可以将 xxx.ts 编译生成为 xxx.ts.js
  • 支持清理历史 jekyll cache: 通过在 _config.yml 配置 cache_dir: .jekyll-cache/v260607 插件会自动删除 .jekyll-cache 里的文件,也会删除名称字符序小于当前缓存名称的文件夹
  • 为插件添加缓存以提升构建速度

ruby 与 node 之间的通信

通过 Ruby 的 open3 调用 Node 来执行 JavaScript 脚本。通信流程如下:

  • 输入:通过 stdin 传入一个 JSON 字符串,内容包括脚本名称、参数和唯一标识
  • 输出:通过 stdout 接收 Node 输出,输出内容包括日志、唯一标识(分隔符)和返回值

定义新 JavaScript 脚本

  • _plugins/scripts 目录下创建 <脚本名称>.js 文件,并确保脚本会默认导出一个函数,该函数接收一个 json 对象作为入参,并返回一个可序列化的 json 对象 / 值。
    export default async function ({ param1, param2 }) {
      // do something
      return { data1: "xxx", data2: 123 };
    }
  • 脚本定义完成后在 rb 文件里使用 Script.call 即可完成 javascript 脚本调用。
    result = Script.call("<脚本名称>", param1: 123, param2: "456")

https://node-docs.hmcl.workers.dev

@neveler neveler marked this pull request as ready for review June 6, 2026 14:32
@neveler neveler marked this pull request as draft June 7, 2026 08:59
@neveler neveler marked this pull request as ready for review June 7, 2026 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant