refactor: remove duplicate code
All checks were successful
Release / Build and Release (push) Successful in 5s
Continuous Integration / Lint, Check & Test (push) Successful in 1m43s
Continuous Integration / Build Package (push) Successful in 1m54s

This commit is contained in:
Konstantin Fickel 2026-04-13 19:49:50 +02:00
parent b8a73bfb3e
commit ee96033639
Signed by: kfickel
GPG key ID: A793722F9933C1A5
5 changed files with 61 additions and 119 deletions

View file

@ -1,6 +1,41 @@
use std::fs;
use std::path::Path;
use chrono_tz::Tz;
use walkdir::WalkDir;
use crate::error::StreamdError;
use crate::extract::parse_markdown_file;
use crate::localize::localize_stream_file;
use crate::models::{LocalizedShard, RepositoryConfiguration};
pub mod completions;
pub mod daily;
pub mod edit;
pub mod new;
pub mod timesheet;
pub mod todo;
pub fn load_markdown_shards(
base_folder: &Path,
config: &RepositoryConfiguration,
tz: Tz,
) -> Result<Vec<LocalizedShard>, StreamdError> {
let mut shards = Vec::new();
for entry in WalkDir::new(base_folder)
.max_depth(1)
.into_iter()
.filter_map(|e| e.ok())
{
let path = entry.path();
if path.extension().map(|e| e == "md").unwrap_or(false) {
let file_name = path.to_string_lossy().to_string();
let content = fs::read_to_string(path)?;
let stream_file = parse_markdown_file(&file_name, &content);
if let Ok(shard) = localize_stream_file(&stream_file, config, tz) {
shards.push(shard);
}
}
}
Ok(shards)
}