+
+ fn read_posts(&self, posts_directory: &PathBuf, max_posts: u8) -> Vec<Post> {
+ let mut posts = Vec::new();
+
+ for i in 0..max_posts {
+ let post_directory = posts_directory.join(i.to_string());
+ match self.read_post(&post_directory, i) {
+ Some(post) => posts.push(post),
+ None => continue
+ }
+ }
+
+ posts
+ }
+
+ fn find_blog_content(&self, post_directory: &PathBuf) -> Option<String> {
+ let entries = read_dir(&post_directory).ok()?;
+ for entry in entries.filter_map(Result::ok) {
+ let entry_path = entry.path();
+ match entry_path.extension() {
+ Some(extension) => {
+ if extension == "gmi" {
+ let mut file = File::open(entry_path).ok()?;
+ let mut contents = String::new();
+ file.read_to_string(&mut contents).ok()?;
+ return Some(contents);
+ }
+ },
+ None => continue
+ }
+ }
+ None
+ }
+
+ fn read_post(&self, post_directory: &PathBuf, index: u8) -> Option<Post> {
+ let metadata_path = post_directory.join(METADATA_FILENAME);
+ let metadata = Metadata::read_or_create(&metadata_path);
+ let raw = self.find_blog_content(&post_directory)?;
+ let html = parse(&raw);
+
+ Some(Post {
+ metadata,
+ index,
+ html,
+ raw
+ })
+ }