page-level themes, specified in the front-matter #443
Closed
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.
All these definitions are valid syntax:
Any custom theme (as opposed to the default theme indicated in the configuration file) get bundled with rollup as
_observablehq/style-{hash}.css
(the default theme is unchanged, bundled as_observablehq/style.css
).Note that a page-level theme does not add to the default theme configuration (this is necessary because you don't necessarily want the default theme; we could debate how to indicate that you extend the default, maybe by having a reserved word such as default: [default, solarized] ? This can't be auto since it's not guaranteed that the default theme in the configuration is auto…).
The theme names must be strings containing only letters, numbers, underscores and dashes (
\w-
). Commas in particular are not allowed because they will be the separator for multiple themes.On preview, the server needs to know what the hash means, so we pass add a search parameter in the URL, with the theme name(s), possibly joined by a comma, in the clear. The server then does a safety check against the hash, and if it passes builds the combined stylesheet.
On build, this stuff is not necessary, so for the sake of minimizing the HTML, the URL is passed only as
style-{hash}.css
.This means, however, that the rendered page is not strictly the same in preview and in build. If we think this is an issue, there are two possibilities, and I have not been able to choose:
I have not pushed the theme-comic-sans.css file so you can't test this:

(It could be nice to have more built-in theme files to test, but I think it's more important to have a theme resolution mechanism that first checks if the
docs/{theme}.css
file exists, then the built-in, and then errors. It could be for a different PR though.)