From e509f26632dce862b0c2879115e605ba1c831c8b Mon Sep 17 00:00:00 2001 From: Geobert Quach Date: Thu, 13 Oct 2022 15:58:27 +0100 Subject: [PATCH] On creating/publishing, don't put subseconds in date --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 8 +++++++- src/new.rs | 7 ++++--- src/publish.rs | 5 +++-- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 50b4cd8..edb5082 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -103,7 +103,7 @@ checksum = "850878694b7933ca4c9569d30a34b55031b9b139ee1fc7b94a527c4ef960d690" [[package]] name = "emile" -version = "0.3.0" +version = "0.3.1" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index 875e7d5..75a7e19 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "emile" -version = "0.3.0" +version = "0.3.1" authors = ["Geobert Quach "] edition = "2021" diff --git a/src/main.rs b/src/main.rs index 765fd60..7dfff4a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,7 @@ mod scheduler; mod watcher; use opt::Opt; -use time::macros::format_description; +use time::{macros::format_description, OffsetDateTime}; use tracing_subscriber::{ fmt::time::UtcTime, prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, EnvFilter, @@ -94,3 +94,9 @@ fn zola_build() -> Result<()> { }, } } + +fn format_date(date: &OffsetDateTime) -> Result { + Ok(date.format(&format_description!( + "[year]-[month]-[day]T[hour]:[minute]:[second][offset_hour sign:mandatory]:[offset_minute]" + ))?) +} diff --git a/src/new.rs b/src/new.rs index b4c5d06..ad8f48d 100644 --- a/src/new.rs +++ b/src/new.rs @@ -3,9 +3,10 @@ use std::path::PathBuf; use anyhow::{bail, Result}; use slug::slugify; -use time::{format_description::well_known::Rfc3339, OffsetDateTime}; +use time::OffsetDateTime; use crate::config::SiteConfig; +use crate::format_date; use crate::post::modify_post; pub fn create_draft(title: &str, cfg: &SiteConfig) -> Result<()> { @@ -37,7 +38,7 @@ pub fn create_draft(title: &str, cfg: &SiteConfig) -> Result<()> { Ok(format!( "+++\ntitle = \"{}\"\ndate = {}\ndraft = true\n", title, - date.format(&Rfc3339)? + format_date(&date)? )) } else { Ok(format!("{}\n", line)) @@ -47,7 +48,7 @@ pub fn create_draft(title: &str, cfg: &SiteConfig) -> Result<()> { format!( "+++\ntitle = \"{}\"\ndate = {}\ndraft = true\n+++\n", title, - date.format(&Rfc3339)? + format_date(&date)? ) }; fs::write(&dest, new_content)?; diff --git a/src/publish.rs b/src/publish.rs index fb0b61b..eeea10b 100644 --- a/src/publish.rs +++ b/src/publish.rs @@ -2,9 +2,10 @@ use std::fs::{self, DirEntry}; use std::path::Path; use anyhow::{bail, Result}; -use time::{format_description::well_known::Rfc3339, OffsetDateTime}; +use time::OffsetDateTime; use crate::config::SiteConfig; +use crate::format_date; use crate::post::modify_post; pub fn publish_post(slug: &str, src_dir: &Path, cfg: &SiteConfig) -> Result { @@ -18,7 +19,7 @@ pub fn publish_post(slug: &str, src_dir: &Path, cfg: &SiteConfig) -> Result