summaryrefslogtreecommitdiff
path: root/src/posts/fs_post_repo.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/posts/fs_post_repo.rs')
-rw-r--r--src/posts/fs_post_repo.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/posts/fs_post_repo.rs b/src/posts/fs_post_repo.rs
new file mode 100644
index 0000000..eb37a6a
--- /dev/null
+++ b/src/posts/fs_post_repo.rs
@@ -0,0 +1,23 @@
+use crate::posts::abstractions::repo::PostRepo;
+use crate::posts::fs_post::FsPost;
+use std::{fs, path::PathBuf};
+
+pub struct FsPostRepo {
+ dir: PathBuf,
+}
+
+impl FsPostRepo {
+ pub fn with_dir(path: impl Into<PathBuf>) -> Self {
+ Self { dir: path.into() }
+ }
+}
+
+impl PostRepo for FsPostRepo {
+ fn load(&self) -> impl IntoIterator<Item = FsPost> {
+ let files = fs::read_dir(&self.dir).unwrap();
+ files
+ .flatten()
+ .filter(|d| !d.file_name().to_string_lossy().starts_with('.'))
+ .map(|d| FsPost::with_path(d.path()))
+ }
+}