Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace lume with soupault #70

Merged
merged 83 commits into from
Jul 17, 2023
Merged

Conversation

DrSensor
Copy link
Owner

@DrSensor DrSensor commented Jun 4, 2023

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:

  • buck2 - This is strong candidate and has lot of goodies but most of built-ins rules still untested
  • pants2 - They have very clear docs and roadmap. However, they use CPython instead of Starlark
  • please+pleasings - I think of this as lightweight version of Bazel or Buck2

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,

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:

  • add flake.nix
  • compare on how to build custom rules in buck2, pants2, and please

DrSensor added 30 commits May 9, 2023 02:43
A bit early but I need it to display the sources as <tablist>

There is 2 way to approach this:
1. Create my-own plugin (ugh!🐛!)
2. Chain preprocess-element widget with something 🤔
Unlike other popular devserver, I use SSE instead of WebSocket.
It's done via caddy reverse_proxy Unix Socket created by ncat.
It create multiple temp FIFO file every time SSE connection open.
An import map is used to resolve module specifiers in static and dynamic imports,
and **therefore must be declared and processed before any <script> elements**
that import modules using specifiers declared in the map.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap
* Fix char dot (.) being transformed into char colon (:)

* Fix source tabpanel being too wide
PS: I'm still using deno 🦕
@DrSensor DrSensor added the build Thing related to build system + tools & packages distribution label Jul 17, 2023
Latest nix-quick-install-action support flake.nix without extra config
@DrSensor DrSensor merged commit a2fe6ab into main Jul 17, 2023
@DrSensor DrSensor deleted the refactor/replace-lume-with-soupault branch July 17, 2023 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Thing related to build system + tools & packages distribution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant