use std::{fmt::Debug, collections::HashMap};
use fs_extra::dir::get_size;
use mopa::{Any, mopafy};
use crate::error::Error;
use super::{IntoInner, config::Config};
pub mod reader;
pub mod watcher;
#[derive(Debug, Clone, PartialEq)]
pub struct Data<T> {
pub file_content: T,
}
impl<T> Data<T> {
pub fn new(d: T) -> Self {
Self { file_content: d }
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Html(String);
impl Html {
pub fn new(d: &str) -> Self {
Self(d.to_string())
}
}
type DataMap = HashMap<String, String>;
pub trait Content: Any + Debug { }
mopafy!{Content}
#[derive(Debug, Clone)]
pub struct Markdown(String);
impl Markdown {
pub fn new(d: &str) -> Self {
Self(d.to_string())
}
}
pub fn build_size() -> Result<f64, Error> {
let config = Config::read_config()?;
let size = get_size(config.out_dir)?;
Ok(((size / 1024) / 1000) as f64)
}
impl From<String> for Markdown {
fn from(d: String) -> Self {
Self(d)
}
}
impl From<String> for Html {
fn from(d: String) -> Self {
Self(d)
}
}
impl From<&str> for Markdown {
fn from(d: &str) -> Self {
Self(d.to_string())
}
}
impl From<&str> for Html {
fn from(d: &str) -> Self {
Self(d.to_string())
}
}
impl IntoInner for Markdown {
type Output = String;
fn into_inner(&self) -> Self::Output {
self.0.to_owned()
}
}
impl IntoInner for Html {
type Output = String;
fn into_inner(&self) -> Self::Output {
self.0.to_owned()
}
}
impl<T: Clone> IntoInner for Data<T> {
type Output = T;
fn into_inner(&self) -> Self::Output {
self.file_content.clone()
}
}
impl Content for Html {}
impl Content for Markdown {}
impl<T: 'static + Debug> Content for Data<T> {}