forked from rust-lang/docs.rs
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch fontawesome from font files to embedded SVG
Fixes rust-lang#790 The rationale for embedding the SVG files directly in the binary: * avoid file I/O occurring in your Tera Filter, which would likely have complex knock-on effects when combined with `async` * avoid complex error handling in your Tera Filter, which is the inevitable outcome of file I/O * avoid having to carefully construct filesystem paths, with all the terrible possible outcomes and failure modes that come with that (using the infrastructure that the existing static file server uses is not an option, because it's not an HTTP request) * I'm guessing it's faster to pull a string out of the binary's text section than it is to open a file for every request, though I have done no benchmarking to justify this wild speculation The rationale for doing it in its own crate: * we're not using any of docs.rs's file handling infrastructure anyway, so all the other stuff in its build.rs was just getting in the way while I coded up its codegen script * it should be useful in other Rust web projects, regardless of the web framework they're using * let's not force rustc to parse a 1.3MiB source file every time you change docs.rs; this seems like prime "separate translation unit" material
- Loading branch information
Showing
1,652 changed files
with
1,836 additions
and
7,546 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/target | ||
Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "font-awesome-as-a-crate" | ||
version = "0.1.2" | ||
# https://github.com/FortAwesome/Font-Awesome/blob/master/composer.json | ||
authors = ["Michael Howell <[email protected]>", "Travis Chase", "Dave Gandy", "Rob Madole", "Jory Raphael", "Geremia Taglialatela", "Brian Talbot", "Mike Wilkerson", "Fonticons Inc <[email protected]>"] | ||
edition = "2018" | ||
license = "CC-BY-4.0 AND MIT" | ||
description = "Font Awesome Free, packaged as a crate" | ||
repository = "https://github.com/rust-lang/docs.rs" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# [Font Awesome Free](https://fontawesome.com/how-to-use/on-the-web/setup/hosting-font-awesome-yourself) SVG files as a crate | ||
|
||
This is not officially supported by Fonticons, Inc. | ||
If you have problems, [contact us](https://github.com/rust-lang/docs.rs), not them. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use std::{ | ||
env, | ||
fs::{read_dir, File}, | ||
io::{Read, Write}, | ||
path::Path, | ||
}; | ||
|
||
fn main() { | ||
println!("cargo:rustc-cfg=font_awesome_out_dir"); | ||
write_fontawesome_sprite(); | ||
} | ||
|
||
fn write_fontawesome_sprite() { | ||
let dest_path = Path::new(&env::var("OUT_DIR").unwrap()).join("fontawesome.rs"); | ||
let mut dest_file = File::create(&dest_path).unwrap(); | ||
dest_file | ||
.write_all(b"fn fontawesome_svg(dir:&str,file:&str)->&'static str{match(dir,file){") | ||
.expect("fontawesome fn write"); | ||
for dirname in &["brands", "regular", "solid"] { | ||
let dir = read_dir(Path::new("fontawesome-free-5.14.0-web/svgs").join(dirname)).unwrap(); | ||
let mut data = String::new(); | ||
for file in dir { | ||
let file = file.expect("fontawesome directory access"); | ||
let filename = file | ||
.file_name() | ||
.into_string() | ||
.expect("fontawesome filenames are unicode"); | ||
let mut file = File::open(file.path()).expect("fontawesome file access"); | ||
data.clear(); | ||
file.read_to_string(&mut data) | ||
.expect("fontawesome file read"); | ||
// if this assert goes off, add more hashes here and in the format! below | ||
assert!( | ||
data.find("###").is_none(), | ||
"file {} breaks raw string", | ||
filename, | ||
); | ||
dest_file | ||
.write_all( | ||
format!( | ||
r####"("{dirname}","{filename}")=>r###"{data}"###,"####, | ||
data = data, | ||
dirname = dirname, | ||
filename = filename.replace(".svg", ""), | ||
) | ||
.as_bytes(), | ||
) | ||
.expect("write fontawesome file"); | ||
} | ||
} | ||
dest_file | ||
.write_all(b"_=>\"\"}}") | ||
.expect("fontawesome fn write"); | ||
} |
File renamed without changes.
3 changes: 3 additions & 0 deletions
3
crates/font-awesome-as-a-crate/fontawesome-free-5.14.0-web/VENDOR.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
The svgs folder was downloaded from https://fontawesome.com/how-to-use/on-the-web/setup/hosting-font-awesome-yourself | ||
The rest of fontawesome was just deleted; this means that the font license and MIT license are not applicable, just the copyright license on the icon files themselves. | ||
|
1 change: 1 addition & 0 deletions
1
crates/font-awesome-as-a-crate/fontawesome-free-5.14.0-web/svgs/brands/500px.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
...-awesome-as-a-crate/fontawesome-free-5.14.0-web/svgs/brands/accessible-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
...es/font-awesome-as-a-crate/fontawesome-free-5.14.0-web/svgs/brands/accusoft.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
...s-a-crate/fontawesome-free-5.14.0-web/svgs/brands/acquisitions-incorporated.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
crates/font-awesome-as-a-crate/fontawesome-free-5.14.0-web/svgs/brands/adn.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
crates/font-awesome-as-a-crate/fontawesome-free-5.14.0-web/svgs/brands/adobe.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
...es/font-awesome-as-a-crate/fontawesome-free-5.14.0-web/svgs/brands/adversal.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
...t-awesome-as-a-crate/fontawesome-free-5.14.0-web/svgs/brands/affiliatetheme.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
crates/font-awesome-as-a-crate/fontawesome-free-5.14.0-web/svgs/brands/airbnb.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
crates/font-awesome-as-a-crate/fontawesome-free-5.14.0-web/svgs/brands/algolia.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
crates/font-awesome-as-a-crate/fontawesome-free-5.14.0-web/svgs/brands/alipay.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
.../font-awesome-as-a-crate/fontawesome-free-5.14.0-web/svgs/brands/amazon-pay.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
crates/font-awesome-as-a-crate/fontawesome-free-5.14.0-web/svgs/brands/amazon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
crates/font-awesome-as-a-crate/fontawesome-free-5.14.0-web/svgs/brands/amilia.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.