Crates.io | dioxus-google-fonts |
lib.rs | dioxus-google-fonts |
version | |
source | src |
created_at | 2025-04-12 13:47:13.346635+00 |
updated_at | 2025-04-12 14:02:33.775898+00 |
description | A declarative Google Fonts embedding for Dioxus |
homepage | |
repository | |
max_upload_size | |
id | 1630933 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
π Declarative Google Fonts embedding for Dioxus β done right.
This crate provides two declarative macros for working with Google Fonts in a Dioxus app:
google_fonts_url!
β generates the Google Fonts <link>
URLgoogle_fonts!
β renders an actual document::Link
node for easy use in rsx!
β
Links are generated at compile time
β
Declarative macro syntax
β
Supports multiple fonts, weights and italics
β
Auto-generates ital,wght@...
combinations
β
Automatically adds display=swap
β
Works out of the box with Dioxus Web + SSR
Add to your Cargo.toml
:
# In your main Dioxus app
dioxus-google-fonts = "0.1"
# This is a procedural macro crate, it will bring in `proc-macro2`, `syn`, etc.
use dioxus_google_fonts::google_fonts_url;
fn main() -> Element {
let url = google_fonts_url!([
("Roboto", wght = [400, 700], ital = [(1, 700)]),
("Manrope", wght = ["200..800"])
]);
assert_eq!(
url,
"https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&family=Manrope:wght@200..800&display=swap"
);
}
use dioxus::prelude::*;
use dioxus_google_fonts::google_fonts;
fn App() -> Element {
rsx! {
{ google_fonts!([
("Roboto", wght = [400, 700], ital = [(1, 700)]),
("Mukta", wght = ["200..900"])
]) }
h1 { "Hello, typographically!" }
}
}
fn main() {
dioxus::web::launch(App);
}
Each font entry uses a tuple-like DSL:
("Font Name", wght = [weights...], ital = [(italic_flag, weight)...])
wght
: weights, as numbers (400
, 700
) or ranges ("200..800"
)ital
: tuples like (1, 700)
β italic, weightital,wght@...
style gets auto-generateddisplay=swap
is always added to the URL (sensible default)https://fonts.googleapis.com/css2?
family=Roboto:ital,wght@1,700&
family=Manrope:wght@200..800&
display=swap
π¦ Crate: crates.io/crates/dioxus-google-fonts
π οΈ Repo: github.com/dsplce-co/dioxus-google-fonts
PRs welcome! Letβs make Dioxus + typography best friends. π€
MIT or Apache-2.0, at your option.