Skip to content

Commit 5e6ea5a

Browse files
author
Stuart Reilly
committed
Try adding baseurl to rspack
1 parent 4f3df8a commit 5e6ea5a

File tree

5 files changed

+24
-15
lines changed

5 files changed

+24
-15
lines changed

README-DEV.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ with the `:` removed.
6969

7070
Liquid templates have access to the following variables, depending on which hook they are running in:
7171
- `site` - hooks with `:site` owner
72-
- [Jekyll site](https://github.com/jekyll/jekyll/blob/master/lib/jekyll/document.rb)
72+
- Same as the `site` object in normal templates
7373
- `doc` - hooks with `:document` owner
7474
- [Jekyll document](https://github.com/jekyll/jekyll/blob/master/lib/jekyll/document.rb)
7575
- `page` - hooks with `:pages` owner
76-
- [Jekyll page](https://github.com/jekyll/jekyll/blob/master/lib/jekyll/document.rb)
76+
- Same as the `page` object in normal template
7777
- `payload` - hooks with either the `:pre_render` or `:post_render` event
7878
- a hash containing variables to be used during rendering (`:pre_render`) or their final values after rendering
7979
(`:post_render`)

_config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,6 @@ hook_exec:
8989
site:
9090
post_write:
9191
bundle-js:
92+
env:
93+
BASE_URL: "{{ site.baseurl }}"
9294
cmd: "node_modules/.bin/rspack build"

gems/hook-exec-gem/lib/hook-exec.rb

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ module HookExec
77
def convert_arg_to_h_entry(arg)
88
case arg.class
99
when Jekyll::Site.class
10-
["site", arg]
10+
{"site" => arg.to_liquid["site"] }
1111
when Hash.class
12-
["payload", arg]
12+
{"payload" => arg}
1313
when Jekyll::Page.class
14-
["page", arg]
14+
arg.to_liquid
1515
when Jekyll::Document.class
16-
["document", arg]
16+
arg.to_liquid
1717
when Array.class
18-
["files", arg]
18+
{"files" => arg}
1919
else
20-
logger.warn { "Unknown argument type #{arg.class} for #{owner}.#{event} hook" }
20+
Jekyll.logger.warn("Hook Exec") { "Unknown argument type #{arg.class} for #{owner}.#{event} hook" }
2121
end
2222
end
2323
module_function :convert_arg_to_h_entry
@@ -31,26 +31,27 @@ def convert_arg_to_h_entry(arg)
3131
env = hook["env"] ||= {}
3232
env.transform_values! { |v| Liquid::Template.parse(v) }
3333
priority = hook["priority"] ||= Jekyll::Hooks::DEFAULT_PRIORITY
34-
logger = PluginMetaLogger.instance.new_logger("HookExec: #{owner}.#{event}.#{name}", PluginMetaLogger.instance.config)
34+
logger = PluginMetaLogger.instance.new_logger(HookExec, PluginMetaLogger.instance.config)
35+
log_prefix = "#{owner}.#{event}.#{name}"
3536

3637
Jekyll::Hooks.register(owner.to_sym, event.to_sym, priority: priority) do |*args|
37-
arg_hash = args.collect(&HookExec.method(:convert_arg_to_h_entry)).to_h
38+
arg_hash = args.collect(&HookExec.method(:convert_arg_to_h_entry)).reduce({}, :merge)
3839
processed_env = env.transform_values {|v| v.render(arg_hash)}
3940
processed_cmd = cmd.render(arg_hash)
4041

4142
time = Benchmark::realtime do
4243
stdout, stderr, status = Open3.capture3(processed_env, processed_cmd)
43-
logger.debug { "stdout:\n#{stdout}" }
44+
logger.debug { "#{log_prefix} stdout:\n#{stdout}" }
4445
unless status.success?
45-
logger.error { "stderr: #{stderr}" }
46+
logger.error { "#{log_prefix} stderr: #{stderr}" }
4647
raise "failed with status #{status.exitstatus}"
4748
end
4849
end
4950

5051
if time < 1.0
51-
logger.debug {"took #{(time * 1000).round(2)}ms"}
52+
logger.debug {"#{log_prefix} took #{(time * 1000).round(2)}ms"}
5253
else
53-
logger.debug {"took #{time.round(2)}s"}
54+
logger.debug {"#{log_prefix} took #{time.round(2)}s"}
5455
end
5556
end
5657
Jekyll.logger.info("HookExec") { "Registered #{owner}.#{event}.#{name} hook" }

rspack.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import rspack from "@rspack/core";
33

44
const isProd = process.env["JEKYLL_ENV"] === "production";
55

6+
// noinspection JSUnusedGlobalSymbols
67
export default defineConfig({
78
module: {
89
rules: [
@@ -42,6 +43,9 @@ export default defineConfig({
4243
// We have jquery, trust
4344
jQuery: "jquery",
4445
}),
46+
new rspack.DefinePlugin({
47+
BASE_URL: process.env["BASE_URL"] ?? "/",
48+
}),
4549
],
4650
resolve: {
4751
extensions: [".js", ".json", ".wasm", ".ts"],

scripts/author-list.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
declare const BASE_URL: string;
2+
13
export function loadAuthorList() {
2-
fetch("/authors.json", {
4+
fetch(BASE_URL + "authors.json", {
35
method: "GET",
46
headers: { Accept: "application/json" },
57
})

0 commit comments

Comments
 (0)