Skip to content

Commit 6cd4a54

Browse files
ci: patch htmldiff
- set `<base>` for htmldiff - fix the bug about `<pre>` - set CORS header for services.w3.org/htmldiff Relates-to: typst-doc-cn#9
1 parent fb431fc commit 6cd4a54

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

.github/workflows/gh-pages.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ jobs:
6060
bash scripts/download_fonts.sh
6161
- run: pnpm install
6262
- run: pnpm build
63+
- run: bash scripts/patch-htmldiff.sh
6364
- name: Setup Pages
6465
uses: actions/configure-pages@v5
6566
- name: Upload artifact

netlify.toml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[build]
22
command = """
33
curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash && \
4-
cargo-binstall typst-cli ripgrep && \
4+
cargo-binstall typst-cli ripgrep sd && \
55
\
66
curl -OL https://www.7-zip.org/a/7z2409-linux-x64.tar.xz && \
77
tar -xvf 7z2409-linux-x64.tar.xz 7zz && ln -s 7zz 7z && \
@@ -10,9 +10,18 @@ export PATH=$PATH:$(pwd) && \
1010
bash scripts/download_fonts.sh && \
1111
\
1212
pnpm install && \
13-
pnpm build
13+
pnpm build && \
14+
\
15+
bash scripts/patch-htmldiff.sh
1416
"""
15-
# `cargo binstall` not works here
17+
# Remarks: `cargo-binstall` works, but `cargo binstall` not.
18+
19+
20+
[[headers]]
21+
for = "/assets/*"
22+
[headers.values]
23+
Access-Control-Allow-Origin = "https://services.w3.org" # Allow CORS for /htmldiff
24+
1625

1726
[[plugins]]
1827
package = "netlify-plugin-cache"

scripts/patch-htmldiff.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
set -euxo pipefail
3+
4+
# Patch htmldiff
5+
#
6+
# https://services.w3.org/htmldiff is running `htmldiff` (the python script),
7+
# and it will execute `htmldiff.pl` in CLI (rather than CGI) mode.
8+
#
9+
# The commit version might be the following:
10+
# https://github.com/w3c/htmldiff-ui/blob/5eac9b073c66b24422df613a537da2ec2f97f457/htmldiff.pl
11+
12+
# Set base.
13+
# Otherwise, CSS & JS will go to services.w3.org.
14+
#
15+
# This CGI-mode feature is missing in CLI mode.
16+
# https://github.com/w3c/htmldiff-ui/blob/5eac9b073c66b24422df613a537da2ec2f97f457/htmldiff.pl#L560-L563
17+
if [[ "${NETLIFY:-false}" == "true" ]]; then
18+
sd --fixed-strings "<head>" "<head><base href='$DEPLOY_URL/'>" dist/index.html
19+
fi
20+
21+
# Ensure at least one newline before every `</pre>`.
22+
#
23+
# This is a bug.
24+
# When `<pre>` and `</pre>` is on the same line, `splitit` should set `$preformatted` to true, but not.
25+
# https://github.com/w3c/htmldiff-ui/blob/main/htmldiff.pl#L406-L412
26+
sd --fixed-strings "</pre>" $'\n</pre>' dist/index.html

0 commit comments

Comments
 (0)