Skip to content

Conversation

@mbostock
Copy link
Member

@mbostock mbostock commented Aug 22, 2024

Alternative to #1589 and #1595. Adds a globalStylesheets option to the config which specifies a set of stylesheets to add to all pages (in addition to the style option which can be specified either globally or on a specific page). By default it’s Source Serif Pro 4 from Google Fonts. Also adds a little heuristic to add the preconnect for Google Fonts if a Google Fonts stylesheet is detected. Related #423.

@mbostock
Copy link
Member Author

Also tacked on an upgrade to Source Serif 4 that @Fil noticed…

@mbostock mbostock enabled auto-merge (squash) August 22, 2024 03:12
@mbostock mbostock changed the title defaultStylesheets config option globalStylesheets config option Aug 22, 2024
@Fil Fil disabled auto-merge August 22, 2024 06:21
Copy link
Contributor

@Fil Fil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think this is the right call 😅

@Fil
Copy link
Contributor

Fil commented Aug 22, 2024

I've added a bit of documentation

@Fil Fil self-requested a review August 22, 2024 12:42
@mbostock mbostock enabled auto-merge (squash) August 22, 2024 13:24
@mbostock mbostock merged commit 86e30a8 into main Aug 22, 2024
@mbostock mbostock deleted the mbostock/config-stylesheets branch August 22, 2024 13:30
@shadoof
Copy link

shadoof commented Sep 29, 2025

Apologies for possibly naive question, but when creating a new framework with latest version, there is no indication in observablehq.config.js for how the 'default' version of this option should be setup (i.e. so as to load Source Serif 4) which is exactly what I would like. Visual Studio Code offers ["src/styles.css"] as a value but since this file does not exist after npx @observablehq/framework@latest create is run, I'm guessing that's a problem?

And does the above issue discussion imply that @import url('[google font]') should work globally in this context in any of my array of CSS 'globalStylesheets' ?

@Fil
Copy link
Contributor

Fil commented Oct 1, 2025

@shadoof here's a concrete example:

in observablehq.config.js I define:

{
  "style": "/assets/global.css",
  "globalStylesheets": ["https://fonts.googleapis.com/css2?family=Kavoon&display=swap"]
}

and in the global stylesheet (src/assets/global.css) I add this rule:

:root {
    --serif: "Kavoon";
}

and this is the result:

Capture d’écran 2025-10-01 à 10 47 37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants