(wip) add content loader

version-2
trivernis 1 year ago
parent 3c22c723ad
commit ce20464337
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG Key ID: 7E6D18B61C8D2F4B

@ -0,0 +1,56 @@
use std::{collections::HashMap, path::PathBuf};
use async_walkdir::{Filtering, WalkDir};
use futures::{future, StreamExt};
use serde::Deserialize;
#[derive(Deserialize)]
pub struct TemplateName(String);
impl AsRef<str> for TemplateName {
fn as_ref(&self) -> &str {
&self.0
}
}
#[derive(Deserialize)]
pub struct Page {
template: TemplateName,
#[serde(flatten)]
data: HashMap<String, toml::Value>,
}
pub struct ContentLoader {
path: PathBuf,
}
impl ContentLoader {
pub fn new(path: PathBuf) -> Self {
Self { path }
}
async fn load_pages(&self) -> Vec<Page> {
todo!()
}
async fn find_files(&self) -> Vec<PathBuf> {
WalkDir::new(&self.path)
.filter(|e| async move {
e.path()
.extension()
.map(|e| {
if e == "toml" {
Filtering::Continue
} else {
Filtering::Ignore
}
})
.unwrap_or(Filtering::Ignore)
})
.map(|e| e.expect("failed to read dir").path())
.collect::<Vec<_>>()
.await
}
}
fn parse_page(path: PathBuf) {}

@ -3,7 +3,9 @@ use std::path::PathBuf;
use config::ConfigLoader; use config::ConfigLoader;
use miette::Result; use miette::Result;
mod config; mod config;
mod content_loader;
#[derive(Debug)] #[derive(Debug)]
pub struct Paths { pub struct Paths {

Loading…
Cancel
Save