10 releases

new 0.3.1 Apr 20, 2024
0.3.0 Apr 4, 2024
0.2.6 Nov 10, 2023
0.2.5 Oct 4, 2023
0.0.1 Jul 5, 2023

#748 in Procedural macros

Download history 15/week @ 2024-01-04 21/week @ 2024-01-11 29/week @ 2024-01-18 53/week @ 2024-01-25 90/week @ 2024-02-01 44/week @ 2024-02-08 45/week @ 2024-02-15 51/week @ 2024-02-22 28/week @ 2024-02-29 31/week @ 2024-03-07 54/week @ 2024-03-14 23/week @ 2024-03-21 58/week @ 2024-03-28 240/week @ 2024-04-04 45/week @ 2024-04-11 157/week @ 2024-04-18

502 downloads per month
Used in escape-artist

MIT/Apache

26KB
409 lines

iconify-rs

This crate provides a macro to embed SVGs from Iconify. For a list of icons, see Iconify Icon Sets.

📝 Usage

let svg = iconify::svg!("mdi:home", color = "red")

iconify::svg! will download and embed an SVG as a string. It will also cache the request, so it won't download the same SVG twice.

let svg = "<svg>...</svg>"

Options

You can pass options to the macro to customize the SVG.

let svg = iconify::svg!("mdi:home",
    width = "24",
    height = "24",
    color = "red",
    // ... and more.
)

All options from the Iconify API are supported. You can find the documentation for the options for the svg! macro here.

Templating

It can also be used directly in rsx, or any compile-time template engine.

Maud:

html! {
    body {
        .card {
            (PreEscaped(iconify::svg!("mdi:home")))
            p { "Hello!" }
        }
    }
}

Askama

<body>
  <div class="card">
    {{ iconify::svg!("mdi:home")|safe }}
    <p>Hello!</p>
</body>

✨ Features

  • Directly embed SVGs from Iconify
  • Caches requests (default feature)
  • Offline mode
  • SVG transforms (through API)
  • (Soon) CSS fetching

🔌 Offline Mode

If you don't want iconify-rs to make requests at compile-time in CI (or other reasons), you can use offline mode with prepared icons.

  1. Enable the offline feature.
  2. Prepare icons by setting ICONIFY_PREPARE=true and running cargo check. This will generate a directory for you in CARGO_MANIFEST_DIR called icons with all the icons you invoked.
  3. Now you're ready to go! Just run cargo build and it will use the icons you prepared.

If you want to set a custom directory, you can also set ICONIFY_OFFLINE_DIR.

⚙️ Configuration

  • ICONIFY_URL - Sets the API url to use. If not set, the default is "https://api.iconify.design"
  • ICONIFY_PREPARE - If set, icons will be written to the offline icons directory (offline mode only)
  • ICONIFY_OFFLINE_DIR - Sets the offline icons directory. If not set, the default is "/icons" in your project directory

Dependencies

~2–15MB
~189K SLoC