-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ add script to update the theme automatically
- Loading branch information
Showing
2 changed files
with
146 additions
and
111 deletions.
There are no files selected for viewing
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,44 @@ | ||
#!/usr/bin/env cargo +nightly -Zscript | ||
|
||
// This script fetches the 'index.hbs' file from the mdBook repository and filters the | ||
// content to only present the 'ayu' theme. | ||
|
||
//! ```cargo | ||
//! [dependencies] | ||
//! reqwest = { version = "0.11", features = ["blocking"] } | ||
//! ``` | ||
use reqwest::blocking; | ||
use std::fs::File; | ||
use std::io::{self, Write}; | ||
|
||
const MDBOOK_VERSION: &str = "0.4.36"; | ||
|
||
fn main() -> io::Result<()> { | ||
let url = format!( | ||
"https://raw.githubusercontent.com/rust-lang/mdBook/v{MDBOOK_VERSION}/src/theme/index.hbs" | ||
); | ||
|
||
let response = blocking::get(&url) | ||
.expect("Failed fetch template file") | ||
.text() | ||
.expect("Failed fetch template file"); | ||
|
||
// filter unwanted themes: only keep ayu | ||
let filtered_content = response | ||
.lines() | ||
.filter(|line| { | ||
if line.contains("role=\"menuitem\"") { | ||
line.contains("id=\"ayu\"") | ||
} else { | ||
true | ||
} | ||
}) | ||
.collect::<Vec<_>>() | ||
.join("\n"); | ||
|
||
let mut file = File::create("index.hbs")?; | ||
file.write_all(filtered_content.as_bytes())?; | ||
|
||
Ok(()) | ||
} |