From 21c9ee3d7aff566cda855503ef9e67392cb56b91 Mon Sep 17 00:00:00 2001 From: Hendrik Eeckhaut Date: Wed, 27 Dec 2023 23:21:14 +0100 Subject: [PATCH] Updated theme to v0.4.36 (#56) + add script to update the theme automatically --- theme/index.hbs | 213 ++++++++++++++++++++---------------------- theme/update_theme.rs | 44 +++++++++ 2 files changed, 146 insertions(+), 111 deletions(-) create mode 100755 theme/update_theme.rs diff --git a/theme/index.hbs b/theme/index.hbs index aacaab1..7edcb73 100644 --- a/theme/index.hbs +++ b/theme/index.hbs @@ -1,62 +1,59 @@ - - - - - - {{ title }} - {{#if is_print }} - - {{/if}} - {{#if base_url}} - - {{/if}} - - - - {{> head}} - - - - - - {{#if favicon_svg}} - - {{/if}} - {{#if favicon_png}} - - {{/if}} - - - - {{#if print_enable}} - - {{/if}} - - - - {{#if copy_fonts}} - - {{/if}} - - - - - - - - {{#each additional_css}} - - {{/each}} - - {{#if mathjax_support}} - - - {{/if}} - - - + + + + + {{ title }} + {{#if is_print }} + + {{/if}} + {{#if base_url}} + + {{/if}} + + + + {{> head}} + + + + + + {{#if favicon_svg}} + + {{/if}} + {{#if favicon_png}} + + {{/if}} + + + + {{#if print_enable}} + + {{/if}} + + + + {{#if copy_fonts}} + + {{/if}} + + + + + + + + {{#each additional_css}} + + {{/each}} + + {{#if mathjax_support}} + + + {{/if}} + +
+ + @@ -216,17 +214,15 @@
- - + \ No newline at end of file diff --git a/theme/update_theme.rs b/theme/update_theme.rs new file mode 100755 index 0000000..c53ab7a --- /dev/null +++ b/theme/update_theme.rs @@ -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::>() + .join("\n"); + + let mut file = File::create("index.hbs")?; + file.write_all(filtered_content.as_bytes())?; + + Ok(()) +}