43 lines
1.6 KiB
Rust
43 lines
1.6 KiB
Rust
use std::path::Path;
|
|
|
|
pub const STATIC_DIR: &str = "static";
|
|
static STATIC_FILES: &[(&str, &[u8])] = &[
|
|
("style1.css", include_bytes!("../static/style1.css")),
|
|
("standgm.png", include_bytes!("../static/standgm.png")),
|
|
("banner.jpg", include_bytes!("../static/banner.jpg")),
|
|
("icon.png", include_bytes!("../static/icon.png")),
|
|
("Karma-Bold.otf", include_bytes!("../static/Karma-Bold.otf")),
|
|
(
|
|
"LinBiolinum_R.otf",
|
|
include_bytes!("../static/LinBiolinum_R.otf"),
|
|
),
|
|
("bg0.jpg", include_bytes!("../static/bg0.jpg")),
|
|
("bg1.jpg", include_bytes!("../static/bg1.jpg")),
|
|
("bg2.jpg", include_bytes!("../static/bg2.jpg")),
|
|
("script1.js", include_bytes!("../static/script1.js")),
|
|
];
|
|
pub static BACKGROUND_ABOUT: &[&str] = &[
|
|
"Claudia Peters, FreeImages.com",
|
|
r#"<a href="https://commons.wikimedia.org/wiki/File:Jukung_Pasar_Terapung.jpg">Muhammad Haris</a>, <a href="https://creativecommons.org/licenses/by-sa/4.0">CC BY-SA 4.0</a>"#,
|
|
r#"<a href="https://commons.wikimedia.org/wiki/File:Municipal_Market_of_S%C3%A3o_Paulo_city.jpg">Wilfredor</a>, <a href="https://creativecommons.org/licenses/by-sa/4.0">CC BY-SA 4.0</a>"#,
|
|
];
|
|
|
|
pub fn init_static_files(dir: &Path) {
|
|
let dir = dir.join(STATIC_DIR);
|
|
std::fs::create_dir_all(&dir).expect("Cannot create static dir");
|
|
|
|
for &(file, default) in STATIC_FILES {
|
|
let file_path = dir.join(file);
|
|
if !file_path.is_file() {
|
|
std::fs::write(file_path, default)
|
|
.unwrap_or_else(|_| panic!("Cannot write template file {}", file));
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn get_background() -> usize {
|
|
std::time::SystemTime::now()
|
|
.duration_since(std::time::UNIX_EPOCH)
|
|
.map_or(0, |t| t.as_secs() as usize / 86400 % 3)
|
|
}
|