Skip to content

Commit

Permalink
Pages WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwo committed Aug 30, 2024
1 parent 511a113 commit 2bf8f40
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Pages
on: push

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/configure-pages@v3
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
cache-dependency-path: prototypes/basic/package-lock.json
- name: Setup hq
run: |
curl -sL https://github.com/ludovicianul/hq/releases/download/hq-1.3.2/hq_linux_amd64_1.3.2.tar.gz --output - | tar -xzv
- name: Build site
run: |
pushd ./prototypes/basic
npm install
coproc npm run dev &
while ! (echo >/dev/tcp/localhost/3000); do sleep 1; done
popd
pushd ./doc
export HQ=$(realpath ../hq)
make -j all
make -j all
popd
- name: Upload artifact
uses: actions/upload-pages-artifact@v2
49 changes: 49 additions & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
HQ ?= $(shell which hq)

SOURCES := $(wildcard ../lib/importer/assets/docs/*.html)
OBJECTS := $(subst ../lib/importer/assets/docs/,./,${SOURCES})

# Create a list of all of the assets the pages need, by looking at the scripts
# and stylesheets they intended to download.
assets.txt: ${SOURCES}
(echo $^ | xargs -n1 | xargs -I INPUT ${HQ} -r '[data-plugin-only]' -f INPUT -a src 'script[src]'; \
echo $^ | xargs -n1 | xargs -I INPUT ${HQ} -r '[data-plugin-only]' -f INPUT -a href 'link[rel=stylesheet]') | \
sort -u | grep . > $@

# Now build a Makefile dependency include, specifying the correct download
# location for each asset and that we require it for a complete package.
assets.mk: assets.txt
for ASSET in $$(cat assets.txt); do \
export SRC=$$(echo $$ASSET | sed 's:^[^\/]:/plugin-assets/%40register-dynamics%2Fimporter/assets/docs/.:'); \
printf "all: $$(basename $$ASSET)\n"; \
printf "%s: SRC=%s\n\n" $$(basename $$ASSET) $$SRC; \
done > $@

.PHONY: all
all: ${OBJECTS} | assets.txt # Rewrite all of the asset paths to be local now.
for ASSET in $$(cat assets.txt); do \
sed -i '' -e "s:$$ASSET:$$(basename $$ASSET):" ${OBJECTS}; \
done
include assets.mk

# We can generate the .gitignore from all of the things we know we are going to
# end up with in the root dir.
.gitignore: assets.txt
(cat $^; printf '%s\n' ${OBJECTS}; echo assets.mk) | xargs basename > $@
all: .gitignore

# Download the page and remove any elements marked only for plugin use.
%.html: ../lib/importer/assets/docs/%.html
curl --fail -sL http://localhost:3000/$(subst ../lib/importer/,/plugin-assets/%40register-dynamics%2Fimporter/,$^) | \
${HQ} -r '[data-plugin-only]' -o $@ html

# Download the asset. This is the easiest way to get the real thing, as some of
# them (e.g. application.css) are generated by the Prototype Kit and can't just
# be copied from the disk.
%.css %.js:
curl --fail -sL "http://localhost:3000/${SRC}" > $@

.PHONY: clean
clean:
-cat .gitignore | xargs $(RM)
-$(RM) assets.mk assets.txt

0 comments on commit 2bf8f40

Please sign in to comment.