refactor: remove duplicate code
This commit is contained in:
parent
b8a73bfb3e
commit
ee96033639
5 changed files with 61 additions and 119 deletions
|
|
@ -1,44 +1,24 @@
|
|||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
use chrono::Utc;
|
||||
use walkdir::WalkDir;
|
||||
|
||||
use crate::config::Settings;
|
||||
use crate::error::StreamdError;
|
||||
use crate::extract::parse_markdown_file;
|
||||
use crate::localize::{localize_stream_file, TaskConfiguration};
|
||||
use crate::localize::TaskConfiguration;
|
||||
use crate::models::LocalizedShard;
|
||||
use crate::query::find_shard_by_position;
|
||||
|
||||
fn all_files() -> Result<Vec<LocalizedShard>, StreamdError> {
|
||||
let settings = Settings::load()?;
|
||||
let mut shards = Vec::new();
|
||||
|
||||
for entry in WalkDir::new(&settings.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, &TaskConfiguration, chrono_tz::UTC)
|
||||
{
|
||||
shards.push(shard);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(shards)
|
||||
}
|
||||
use super::load_markdown_shards;
|
||||
|
||||
pub fn collect_open_tasks(show_future: bool) -> Result<Vec<LocalizedShard>, StreamdError> {
|
||||
let all_shards = all_files()?;
|
||||
let settings = Settings::load()?;
|
||||
let all_shards = load_markdown_shards(
|
||||
Path::new(&settings.base_folder),
|
||||
&TaskConfiguration,
|
||||
chrono_tz::UTC,
|
||||
)?;
|
||||
let now = Utc::now();
|
||||
|
||||
let mut tasks: Vec<LocalizedShard> = find_shard_by_position(&all_shards, "task", "open")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue