code housekeeping

This commit is contained in:
りき萌 2025-08-26 12:46:50 +02:00
parent e1b6578b2a
commit d3c3ff8e4e
10 changed files with 108 additions and 100 deletions

View file

@ -3,15 +3,15 @@ use std::{
ops::ControlFlow,
};
use anyhow::{anyhow, Context};
use anyhow::{Context, anyhow};
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
use serde::{Deserialize, Serialize};
use tracing::{error, info_span, instrument};
use crate::{
html::highlight::{
compiled::{compile_syntax, CompiledSyntax},
Syntax,
compiled::{CompiledSyntax, compile_syntax},
},
import_map::ImportRoot,
vfs::{self, Content, Dir, DynDir, ImageSize, VPath, VPathBuf},
@ -116,12 +116,11 @@ impl Config {
#[instrument(name = "Config::autopopulate_emoji", skip(self))]
pub fn autopopulate_emoji(&mut self, dir: &dyn Dir) -> anyhow::Result<()> {
vfs::walk_dir_rec(dir, VPath::ROOT, &mut |path| {
if path.extension().is_some_and(is_image_file) {
if let Some(emoji_name) = path.file_stem() {
if !self.emoji.contains_key(emoji_name) {
self.emoji.insert(emoji_name.to_owned(), path.to_owned());
}
}
if path.extension().is_some_and(is_image_file)
&& let Some(emoji_name) = path.file_stem()
&& !self.emoji.contains_key(emoji_name)
{
self.emoji.insert(emoji_name.to_owned(), path.to_owned());
}
ControlFlow::Continue(())
@ -133,16 +132,16 @@ impl Config {
#[instrument(name = "Config::autopopulate_pics", skip(self))]
pub fn autopopulate_pics(&mut self, dir: &dyn Dir) -> anyhow::Result<()> {
vfs::walk_dir_rec(dir, VPath::ROOT, &mut |path| {
if path.extension().is_some_and(is_image_file) {
if let Some(pic_name) = path.file_stem() {
let pic_id = pic_name
.split_once('-')
.map(|(before_dash, _after_dash)| before_dash)
.unwrap_or(pic_name);
if path.extension().is_some_and(is_image_file)
&& let Some(pic_name) = path.file_stem()
{
let pic_id = pic_name
.split_once('-')
.map(|(before_dash, _after_dash)| before_dash)
.unwrap_or(pic_name);
if !self.pics.contains_key(pic_id) {
self.pics.insert(pic_id.to_owned(), path.to_owned());
}
if !self.pics.contains_key(pic_id) {
self.pics.insert(pic_id.to_owned(), path.to_owned());
}
}