From e43d612e3d017b2e93c3a041a75bee80f10644eb Mon Sep 17 00:00:00 2001 From: lqdev Date: Sun, 27 Aug 2023 18:47:57 +0200 Subject: [PATCH] just some random stuff --- content/index.tree | 5 +++++ crates/treehouse/src/cli/regenerate.rs | 1 + crates/treehouse/src/config.rs | 30 +++++++++++++++++++++++++- static/css/main.css | 28 ++++++++++++++++++++++++ treehouse.toml | 1 - 5 files changed, 63 insertions(+), 2 deletions(-) diff --git a/content/index.tree b/content/index.tree index c406604..1e30897 100644 --- a/content/index.tree +++ b/content/index.tree @@ -1,5 +1,10 @@ % id = "treehouse" - # liquidex's treehouse + + achievement unlocked: I don't want anything to do with this bullshit
+ …either that, or you folded the entire tree by accident.
+ feel free to go back any time by clicking here. +
% id = "01H8V556P1PND8DQ73XBTZZJH7" - welcome! make yourself at home diff --git a/crates/treehouse/src/cli/regenerate.rs b/crates/treehouse/src/cli/regenerate.rs index 5fb36e2..b33a590 100644 --- a/crates/treehouse/src/cli/regenerate.rs +++ b/crates/treehouse/src/cli/regenerate.rs @@ -219,6 +219,7 @@ pub fn regenerate(paths: &Paths<'_>) -> anyhow::Result<()> { info!("loading config"); let mut config = Config::load(paths.config_file)?; config.site = std::env::var("TREEHOUSE_SITE").unwrap_or(config.site); + config.autopopulate_emoji(&paths.static_dir.join("emoji"))?; info!("cleaning target directory"); let _ = std::fs::remove_dir_all(paths.target_dir); diff --git a/crates/treehouse/src/config.rs b/crates/treehouse/src/config.rs index 01cf00d..f559e2c 100644 --- a/crates/treehouse/src/config.rs +++ b/crates/treehouse/src/config.rs @@ -1,7 +1,8 @@ -use std::{collections::HashMap, path::Path}; +use std::{collections::HashMap, ffi::OsStr, path::Path}; use anyhow::Context; use serde::{Deserialize, Serialize}; +use walkdir::WalkDir; #[derive(Debug, Clone, Deserialize, Serialize)] pub struct Config { @@ -28,4 +29,31 @@ impl Config { let string = std::fs::read_to_string(path).context("cannot read config file")?; toml_edit::de::from_str(&string).context("error in config file") } + + fn is_emoji_file(path: &Path) -> bool { + path.extension() == Some(OsStr::new("png")) || path.extension() == Some(OsStr::new("svg")) + } + + pub fn autopopulate_emoji(&mut self, dir: &Path) -> anyhow::Result<()> { + for file in WalkDir::new(dir) { + let entry = file?; + if entry.file_type().is_file() && Self::is_emoji_file(entry.path()) { + if let Some(emoji_name) = entry.path().file_stem() { + let emoji_name = emoji_name.to_string_lossy(); + if !self.emoji.contains_key(emoji_name.as_ref()) { + self.emoji.insert( + emoji_name.into_owned(), + entry + .path() + .strip_prefix(dir) + .unwrap_or(entry.path()) + .to_string_lossy() + .into_owned(), + ); + } + } + } + } + Ok(()) + } } diff --git a/static/css/main.css b/static/css/main.css index 605dcb0..4a40350 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -244,3 +244,31 @@ img.emoji { max-height: 1.375em; vertical-align: bottom; } + +/* Funny joke */ + +@keyframes hello-there { + 0% { + opacity: 0%; + } + + 70% { + opacity: 0%; + } + + 100% { + opacity: 70%; + } +} + +.oops-you-seem-to-have-gotten-stuck { + margin-top: 16px; + display: none; + position: absolute; + opacity: 0%; +} + +#index\:treehouse>details:not([open])>summary .oops-you-seem-to-have-gotten-stuck { + display: inline; + animation: 4s hello-there forwards; +} diff --git a/treehouse.toml b/treehouse.toml index a5d026a..1c5a54f 100644 --- a/treehouse.toml +++ b/treehouse.toml @@ -9,4 +9,3 @@ author = "liquidex" "dawd3/repo" = "https://github.com/liquidev/dawd3" [emoji] -hueh = "hueh.png"