@@ -34,6 +34,16 @@ pub struct NewArgs {
34
34
/// Title of the post
35
35
pub title : Option < String > ,
36
36
37
+ /// Publish date of the post
38
+ ///
39
+ /// Supported formats:
40
+ ///
41
+ /// "now" - current date, "YYYY-MM-DD HH:MM:SS", "DD Month YYYY HH:MM:SS",
42
+ /// "DD Mon YYYY HH:MM:SS", "MM/DD/YYYY HH:MM:SS", "Dow Mon DD HH:MM:SS YYYY"
43
+ ///
44
+ #[ arg( long, value_name = "date" ) ]
45
+ pub date : Option < String > ,
46
+
37
47
/// New document's parent directory or file (default: `<CWD>/title.ext`)
38
48
#[ arg( short, long, value_name = "DIR_OR_FILE" ) ]
39
49
pub file : Option < path:: PathBuf > ,
@@ -57,6 +67,7 @@ impl NewArgs {
57
67
let config = cobalt:: cobalt_model:: Config :: from_config ( config) ?;
58
68
59
69
let title = self . title . as_deref ( ) ;
70
+ let date = self . date . as_deref ( ) ;
60
71
61
72
let mut file = env:: current_dir ( ) . unwrap_or_default ( ) ;
62
73
if let Some ( rel_file) = self . file . as_deref ( ) {
@@ -65,7 +76,7 @@ impl NewArgs {
65
76
66
77
let ext = self . with_ext . as_deref ( ) ;
67
78
68
- create_new_document ( & config, title, file, ext, self . edit )
79
+ create_new_document ( & config, title, date , file, ext, self . edit )
69
80
. with_context ( || anyhow:: format_err!( "Could not create document" ) ) ?;
70
81
71
82
Ok ( ( ) )
@@ -222,6 +233,7 @@ pub fn create_new_project_for_path(dest: &path::Path) -> Result<()> {
222
233
pub fn create_new_document (
223
234
config : & cobalt_model:: Config ,
224
235
title : Option < & str > ,
236
+ date : Option < & str > ,
225
237
mut file : path:: PathBuf ,
226
238
extension : Option < & str > ,
227
239
edit : bool ,
@@ -297,6 +309,13 @@ pub fn create_new_document(
297
309
front. title = Some ( liquid:: model:: KString :: from_ref ( "Untitled" ) ) ;
298
310
}
299
311
312
+ if let Some ( date) = date {
313
+ front. published_date = Some (
314
+ liquid:: model:: DateTime :: from_str ( date)
315
+ . ok_or_else ( || anyhow:: format_err!( "Wrong date format" ) ) ?,
316
+ ) ;
317
+ }
318
+
300
319
let doc = cobalt_model:: Document :: new ( front. clone ( ) , content) ;
301
320
let mut doc = doc. to_string ( ) ;
302
321
if edit || title. is_none ( ) {
0 commit comments