Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing css files with @font-face declarations into a custom scss theme file for self-hosted fonts #9518

Open
chiragraman opened this issue Apr 28, 2024 Discussed in #9516 · 3 comments
Assignees
Labels
bug Something isn't working html Issues with HTML and related web technology (html/css/scss) themes Related to HTML theming or any other style related issue (like highlight-style)

Comments

@chiragraman
Copy link

Hello!

For convenience, the minimal reproducible example is here: https://github.com/chiragraman/quarto-fonts-test. Following the discussion in the Q&A post below, it seems relevant to create an issue to get to the bottom of how the relative paths are resolved. While a workable solution is to simply specify all @font-face definitions in a single scss file, it might be more elegant to be able to import the definitions from font-specific stylesheets in the case of multiple self-hosted fonts.

The core question is how to import these files within the rules layer of the custom scss file, since the relative paths resolve to be under _site/site_libs/bootstrap/ even if the resource path is _site/assets/fonts (the fonts aren't actually copied over either). More details in the discussion below.

Discussed in #9516

Originally posted by chiragraman April 28, 2024

Description

Hello!

This is most likely a basic question but I'd appreciate any help. I am trying to use custom fonts in a website project, and am running into errors arising from incorrect paths. I have set up a minimal example here with Fira Code as an example: https://github.com/chiragraman/quarto-fonts-test.

So far, I have followed the steps outlined in Issue #4387:

  • add the fonts as resource files
  • specified the @font-face declarations under /*-- scss:rules --*/
  • turned off the web-font paths by setting $web-font-path: "No";

The errors are most likely arising because I am trying to import the font stylesheet in a fonts.scss file and specify this as a theme file in _quarto.yml. I'm doing this so I can keep all import statements for multiple font stylesheets in one place.

Previewing yields the following errors:

GET: /
  /site_libs/bootstrap/fonts/Fira-Code/fira_code.css (404: Not Found)
GET: /site_libs/bootstrap/No (404: Not Found)

I'd appreciate any help in understanding how the paths work. Thanks!

@cscheid cscheid self-assigned this Apr 28, 2024
@mcanouil mcanouil added bug Something isn't working html Issues with HTML and related web technology (html/css/scss) themes Related to HTML theming or any other style related issue (like highlight-style) labels Apr 28, 2024
@chiragraman
Copy link
Author

chiragraman commented Apr 30, 2024

Update: My colleague Patrick may have a fix so that the font CSS files can directly be imported. The changes are in this PR on the minimal repo: chiragraman/quarto-fonts-test#1.

Briefly, the changes involved updating both the resources and the import paths. Crucially, the paths in the @font-face declarations do not need to be updates to point to the assets and can remain relative to the font directory of each font.

EDIT: The GET: /site_libs/bootstrap/No (404: Not Found) still persists, however.

@cscheid
Copy link
Collaborator

cscheid commented Apr 30, 2024

EDIT: The GET: /site_libs/bootstrap/No (404: Not Found) still persists, however.

You'll note that my original answer said:

You do this by overriding the $web-font-path directory (in this case, I just used a bad value, $web-font-path: "No")

I don't know if we have a good fix for this. Ideally something (either sass itself or our processing) would know that web-font-path: "disable" (or whatever we decide to call it) means "remove this from the SASS bundle", but I more-or-less intended that as a hack, and the error message is an inevitable consequence.

@chiragraman
Copy link
Author

Aha, makes sense. I agree, making this more explicit might be a better way to handle things.

I feel it might be better to have a separate boolean variable for checking whether web fonts should be enabled rather than overloading the path variable to serve multiple functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working html Issues with HTML and related web technology (html/css/scss) themes Related to HTML theming or any other style related issue (like highlight-style)
Projects
None yet
Development

No branches or pull requests

3 participants