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

Add copy-custom-fonts parameter to HtmlConfig to enable custom fonts #1799

Closed

Conversation

emirror-de
Copy link

@emirror-de emirror-de commented May 5, 2022

This PR introduces a new parameter to the HtmlConfig struct named copy_custom_fonts. When set to true, the fonts/fonts.css file is scanned for @font-face rules that contain a src: url(font-file.name) attribute. The files that have been found are copied into the book folder on build/serve.

If copy_fonts is also enabled, the build in fonts/fonts.css is extended by the custom one. In addition to that, the build in font files are also copied to the output folder.

Example usage:

Create a fonts/ folder in your book root. Then copy the fonts you want to use into this folder (in this example we are assuming Lato-Regular.ttf)

Create a custom fonts file fonts/fonts.css

@font-face {
     font-family: "Lato";
     font-style: normal;
     font-weight: normal;
     src: url('Lato-Regular.ttf');
}

Setup your book.toml that it contains the following parameters:

[output.html]
copy-fonts = true
copy-custom-fonts = true

Adjust your theme/css/general.css file according to your needs, for example:

html {
    font-family: "Lato", sans-serif;
}

It adds a new dependency lewp-css to Cargo.toml for simple parsing of the fonts/fonts.css file.
It also updates the msrv to 1.56.0 because lewp-css requires edition 2021.
Furthermore, the clap dependency gets updated.

@emirror-de emirror-de marked this pull request as draft May 5, 2022 14:06
@emirror-de emirror-de marked this pull request as ready for review May 5, 2022 15:15
@emirror-de emirror-de closed this May 17, 2022
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.

1 participant