Repository navigation
Make compiled stylesheets reference their assets relatively - #23
Merged
Merged
Conversation
Remix writes every url() in the compiled CSS against the /myst_assets_folder/ public path. `myst build --html` rewrites that placeholder in html, js and json but not in CSS, so on a static host under a base URL the bundled brand fonts 404 and the paper falls back to Georgia. This went unnoticed until the Google Fonts link was dropped in favour of the bundled brand fonts. Add a post-build step, `relativize-css-assets`, that rewrites those urls relative to each stylesheet under public/build. Fonts sit beside the stylesheets, so the result resolves in every serving mode: static export, the express server with or without a prefix, and remix dev. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The build now makes every url() in the compiled CSS relative, so the prefixed server only needs to rewrite module imports and asset URLs in JavaScript. The path safety check moves ahead of the extension gate so a null-byte probe still gets a 404 whatever its extension. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Derive the change from the rewrite itself instead of a duplicated public-path literal and pre-check, pass the stylesheet directory once, match only the minified url() form Remix emits, and stop describing remix dev, which never runs the script. The test follows the existing bin-script idiom, cleans up per test, and keeps one negative check per gate. The README note moves beside the static-export instructions. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Contributor
|
Lightcone previews: Paper · Playground — inventory, viewers, dialogs and glyphs d591643 · @astra-spec/ui 0.0.6 from 6248ae0 · Lightcone brand 0.0.3 · astra-theme d591643 · content 3735fcc · MySTRA https://github.com/LightconeResearch/MySTRA/releases/download/v0.0.8/mystra.mjs |
5 of 7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On https://www.mystviewer.org/eiffl/myst_proto the paper renders in Georgia: all five bundled brand font files 404. Remix writes every
url()in the compiled CSS against the/myst_assets_folder/public path, andmyst build --htmlrewrites that placeholder in html, js and json but not in CSS (packages/myst-cli/src/build/html/index.ts, still the case on mystmd main). Under a base URL the font urls therefore point at the host root.This has been latent since the brand fonts were first bundled. It went unnoticed until #17 dropped the Google Fonts link that used to supply Newsreader, Quattrocento and Alegreya from absolute URLs. The KaTeX font faces in the same stylesheet have always 404ed on static hosts, masked by the CDN KaTeX stylesheet.
The same rewrite already exists twice downstream: the theme's express server patches CSS when serving under a prefix, and astra-ui's preview builder patches the static export. Neither helps a static host such as mystviewer.
Fix
A post-build step,
relativize-css-assets ./public, runs afterremix buildin both themes and rewrites everyurl(/myst_assets_folder/...)in the stylesheets underpublic/build/to a path relative to that stylesheet. Fonts sit beside the stylesheets, so the result is the form Vite and webpack emit natively and resolves in every serving mode without anyone substituting the placeholder:MYSTRA_BASE_URL(JupyterLab)remix devThe compiled stylesheet keeps its hashed name, so manifests are unaffected. The flip side: the same fingerprint now names different bytes than the previous release, so a static host that cached the old copy under the immutable policy needs a purge or a fresh deployment path once. mystviewer deploys under a per-build directory, so it is not affected.
The script fails the build if any
/myst_assets_folder/reference survives the rewrite, so a bundler change that emits a form it does not recognise cannot ship silently.Verification
npm test: 16 files, 142 tests pass, including a new test for the script (quoted/unquoted urls, nested stylesheets, data and remote urls, scripts and files outsidebuild/untouched).npm run build:articleandbuild:book: 5 stylesheets rewritten each, no placeholder left in any compiled CSS.BASE_URL=/eiffl/myst_proto myst build --htmlon the DESI prototype, served from a plain file server under that path: all five brand fonts load,document.fontsreports no failures, and the inline reference span measures identically to the local render./myst_assets_folder/_assets/….Also in this PR
The express asset handler no longer rewrites stylesheets, only JavaScript, since the compiled CSS carries relative urls. Its path safety check now runs before the extension gate so a null-byte probe gets a 404 whatever its extension. The server test's CSS fixture uses the relative form the build produces and expects it served verbatim.
Follow-ups (not in this PR)
.cssis rewritten like the other extensions.🤖 Generated with Claude Code