diff --git a/backend/task/src/tasks/import_posts.rs b/backend/task/src/tasks/import_posts.rs index 4610706..8ed67bc 100644 --- a/backend/task/src/tasks/import_posts.rs +++ b/backend/task/src/tasks/import_posts.rs @@ -2,6 +2,7 @@ use std::fs; use std::io::Read; use crate::utils::task_log; +use chrono::{DateTime, FixedOffset, Utc}; use serde::{Deserialize, Deserializer}; pub fn register(pool: &sqlx::Pool) { @@ -19,21 +20,15 @@ async fn import_posts( // Start task logging let task = task_log::start(1, pool).await?; - - // Setup markdown options let options = MarkdownOptions { options: markdown::Constructs::gfm(), }; - - // Read directory contents let entries = fs::read_dir(dir_path)?; - // Process each file for entry_result in entries { let file = entry_result?; let file_path = file.path(); - // Skip non-file entries if !file_path.is_file() { continue; } @@ -71,22 +66,23 @@ async fn import_posts( let content = markdown::to_html_with_options(&document.content, &markdown::Options::default()); - println!("{:?}", content); let title = document.metadata.title; + let pub_date = + DateTime::parse_from_str(document.metadata.date.as_ref(), "%Y-%m-%d %H:%M:%S %z")?; let content_final = content.unwrap(); // Insert into database let results = sqlx::query_as::<_, InsertPosts>( - "INSERT INTO posts (title, body, filename, author_id) VALUES ($1, $2, $3, $4) RETURNING title, body, filename, author_id" + "INSERT INTO posts (title, body, filename, publish_date, author_id) VALUES ($1, $2, $3, $4, $5) RETURNING title, body, filename, author_id" ) .bind(title) .bind(content_final) .bind(file_name_str) + .bind(pub_date) .bind(1) // Consider making author_id a parameter .fetch_one(pool) .await?; - println!("{:?}", results); println!("Successfully imported: {}", file_name_str); } else {