From 9f341d439f7aa5fd2365024169ead2d6bdc3210c Mon Sep 17 00:00:00 2001 From: "Adam T. Carpenter" Date: Sat, 14 Sep 2024 20:30:05 -0400 Subject: feat: rewrite complete --- src/posts/fs_post_repo.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/posts/fs_post_repo.rs (limited to 'src/posts/fs_post_repo.rs') 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) -> Self { + Self { dir: path.into() } + } +} + +impl PostRepo for FsPostRepo { + fn load(&self) -> impl IntoIterator { + 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())) + } +} -- cgit v1.2.3 From 18339f611fd17e1300593edd65adf7604a39ad72 Mon Sep 17 00:00:00 2001 From: "Adam T. Carpenter" Date: Sat, 14 Sep 2024 20:54:44 -0400 Subject: feat: working rudimentary blog presentation --- src/posts/fs_post_repo.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/posts/fs_post_repo.rs') diff --git a/src/posts/fs_post_repo.rs b/src/posts/fs_post_repo.rs index eb37a6a..13f797b 100644 --- a/src/posts/fs_post_repo.rs +++ b/src/posts/fs_post_repo.rs @@ -1,3 +1,4 @@ +use crate::posts::abstractions::post::Post; use crate::posts::abstractions::repo::PostRepo; use crate::posts::fs_post::FsPost; use std::{fs, path::PathBuf}; @@ -20,4 +21,12 @@ impl PostRepo for FsPostRepo { .filter(|d| !d.file_name().to_string_lossy().starts_with('.')) .map(|d| FsPost::with_path(d.path())) } + + fn by_id(&self, post_id: &str) -> FsPost { + let posts = self.load(); + posts + .into_iter() + .find(|p| p.get_title() == post_id) + .unwrap() + } } -- cgit v1.2.3