Closed DrSensor closed 1 year ago
Good news, Knit is what I'm looking for!
Since Soupault also use Lua (older), this make Lua as the preferred language for the build system of this project.
Gonna replace GNU Make with Knit [^1] when this PR finish. Just need to change the github action and merge but currently I'm too lazy for that 😅
[^1]: Knit better Make
Motivation
By design, Nusa support multiple language either via bindgen (which compile other langs into ES class) or (WIP) link directly to wasm module. This mean it need a build system that is flexible enough to accommodate many languages with different toolchains. The site generator also need to be flexible too so it can generate various demo pages and playgrounds.
Details
This PR migrate site generator + build system from Lume (Deno) to Soupault + GNU Make. Soupault approach much more flexible than Lume. In Lume, I need to wrap everything either as a plugin or function generator which quite brittle. But in Soupault, I just need to write pair of selector and transformation inside the config file. Soupault also support incremental build which cache every preprocessors/transformer output based on checksum. The downside is I need create some small plugin in Lua v2.5 for trivial stuff. The plugin itself is pretty simple so that's not a problem. As for minification and others, Makefile is quite powerful and very flexible. It's very easy to integrate with other tools. The downside is it's not obvious on how to do certain things in Makefile. The GNU docs still lack of examples, so Stackoverflow is your best friend.
In the future, I'm thinking to replace GNU Make with nextgen build system. Some of them are:
All of those build-system doesn't have html-preprocessor for use case like site generator.
Ideally
I prefer simple CLI for processing html + better GNU Make (no need to be compatible); so I can write this kind of rules, ```Makefile MAKEFLAGS += --cache-dir=.cache/make --cache=sha256 # use content addressing instead of timestamp for incremental build build: $(MAKE) -j $(BUILD_DIR)/site/** # Process all demo html pages $(BUILD_DIR)/site/demo/%.html: examples/%.html $(MAKE) --template:demo=<($(MAKE) --highlight=$<) > $@ --template$(COL)demo$(EQ)%.html: %.html @cat $< | htmp --append --selector=body -f .site/templates/demo.html # Default operation: copy all resources $(BUILD_DIR)/site/%: % [ ! -d $(dir $@) ] && mkdir -p $(dir $@) cp $< $@ --highlight$(EQ)%.html: %.html @cat $< | htmp --replace --selector='code[class^="language-"]' -c 'highlight -O html -f -S $$(echo $$ATTR_CLASS | sed -e "s/language-//")' # GNU Make can't escape syntax token in target rule, so the only way is to use variable COL = : EQ = = ```TODO in the future: