Skip to content

Commit

Permalink
Don't link bootstrap-icons by hand
Browse files Browse the repository at this point in the history
The html-tag for loading bootstrap-icons is now generated and always
contains the correct path.
  • Loading branch information
alexkazik committed Apr 6, 2024
1 parent b9e4863 commit 1995efe
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
5 changes: 5 additions & 0 deletions examples/icons/Trunk.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[[hooks]]
stage = "pre_build"
command = "cargo"
command_arguments = ["run", "--bin", "link-bootstrap-icons"]

[[hooks]]
stage = "build"
command = "cargo"
Expand Down
3 changes: 2 additions & 1 deletion examples/icons/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<base data-trunk-public-url/>
<meta charset="utf-8"/>
<title>Yew App</title>
<link rel="stylesheet" href="bootstrap-icons-v1.11.3/bootstrap-icons.css"/>
<!-- Adapt the path according to your project (probably remove the `../`) -->
<link data-trunk rel="inline" href="../target/generated/link-bootstrap-icons.html"/>
<link data-trunk rel="rust" data-bin="icons"/>
</head>
</html>
31 changes: 31 additions & 0 deletions examples/icons/src/bin/link-bootstrap-icons.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use std::path::PathBuf;
use yew_bootstrap::icons::BIFiles;

fn main() -> Result<(), std::io::Error> {
for l in 0..5 {
let mut path_base = PathBuf::from(
std::env::var("TRUNK_SOURCE_DIR").expect("Environment variable TRUNK_SOURCE_DIR"),
);
for _ in 0..l {
path_base = path_base.join("..");
}
let path_target = path_base.join("target");

if !path_target.is_dir() || !path_base.join("Cargo.lock").is_file() {
continue;
}

let path_generated = path_target.join("generated");
if !path_generated.is_dir() {
std::fs::create_dir(&path_generated)?;
}
let contents = format!(
"<link rel=\"stylesheet\" href=\"bootstrap-icons-{}/bootstrap-icons.css\" />",
BIFiles::VERSION
);
std::fs::write(path_generated.join("link-bootstrap-icons.html"), contents)?;

return Ok(());
}
panic!("Couldn't find the target directory");
}

0 comments on commit 1995efe

Please sign in to comment.