aboutsummaryrefslogtreecommitdiff
path: root/src/command/generate.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/command/generate.rs')
-rw-r--r--src/command/generate.rs42
1 files changed, 21 insertions, 21 deletions
diff --git a/src/command/generate.rs b/src/command/generate.rs
index cc9e401..a79058d 100644
--- a/src/command/generate.rs
+++ b/src/command/generate.rs
@@ -1,13 +1,13 @@
-use std::fs::{create_dir_all, read_dir, remove_dir_all, File};
-use std::io::{Read, Result};
-use std::path::PathBuf;
+use crate::archiver::archive;
use crate::configuration::Configuration;
use crate::constants::METADATA_FILENAME;
-use crate::gemini_parser::parse;
use crate::generator::generate;
-use crate::archiver::archive;
use crate::metadata::Metadata;
use crate::post::Post;
+use gema_texto::{gemini_parser::parse, html_renderer::render_html};
+use std::fs::{create_dir_all, read_dir, remove_dir_all, File};
+use std::io::{Read, Result};
+use std::path::Path;
pub struct Generate;
@@ -16,22 +16,22 @@ impl Generate {
Generate
}
- fn read_posts(&self, posts_directory: &PathBuf, max_posts: u8) -> Vec<Post> {
+ fn read_posts(&self, posts_directory: &Path, 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) {
+ let post_path = posts_directory.join(i.to_string());
+ match self.read_post(&post_path, i) {
Some(post) => posts.push(post),
- None => continue
+ None => continue,
}
}
posts
}
- fn find_blog_content(&self, post_directory: &PathBuf) -> Option<String> {
- let entries = read_dir(&post_directory).ok()?;
+ fn find_blog_content(post_path: &Path) -> Option<String> {
+ let entries = read_dir(post_path).ok()?;
for entry in entries.filter_map(Result::ok) {
let entry_path = entry.path();
match entry_path.extension() {
@@ -42,24 +42,24 @@ impl Generate {
file.read_to_string(&mut contents).ok()?;
return Some(contents);
}
- },
- None => continue
+ }
+ None => continue,
}
}
None
}
- fn read_post(&self, post_directory: &PathBuf, index: u8) -> Option<Post> {
+ fn read_post(&self, post_directory: &Path, 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);
+ let raw = Generate::find_blog_content(post_directory)?;
+ let html = render_html(&parse(&raw));
Some(Post {
metadata,
index,
html,
- raw
+ raw,
})
}
}
@@ -69,7 +69,7 @@ impl super::Command for Generate {
vec![]
}
- fn execute(&self, _: Option<&String>, configuration: &Configuration, _: &String) -> Result<()> {
+ fn execute(&self, _: Option<&String>, configuration: &Configuration, _: &str) -> Result<()> {
let _ = remove_dir_all(&configuration.blog_output_directory);
create_dir_all(&configuration.blog_output_directory)?;
@@ -78,7 +78,7 @@ impl super::Command for Generate {
&configuration.static_directory,
&configuration.templates_directory,
&configuration.blog_output_directory,
- &posts
+ &posts,
)?;
let _ = remove_dir_all(&configuration.archive_output_directory);
@@ -86,9 +86,9 @@ impl super::Command for Generate {
archive(
&configuration.archive_directory,
&configuration.templates_directory,
- &configuration.archive_output_directory
+ &configuration.archive_output_directory,
)?;
- return Ok(())
+ Ok(())
}
fn after_dependencies(&self) -> Vec<Box<dyn super::Command>> {