@@ -6,17 +6,18 @@ use std::{
6
6
path:: { Path , PathBuf } ,
7
7
sync:: LazyLock ,
8
8
} ;
9
+ use toml:: value:: Date ;
9
10
10
11
#[ derive( Debug , Clone , Serialize ) ]
11
12
pub struct Post {
12
13
pub ( crate ) filename : String ,
13
14
pub ( crate ) layout : String ,
14
15
pub ( crate ) title : String ,
15
16
pub ( crate ) author : String ,
16
- pub ( crate ) year : i32 ,
17
+ pub ( crate ) year : u16 ,
17
18
pub ( crate ) show_year : bool ,
18
- pub ( crate ) month : u32 ,
19
- pub ( crate ) day : u32 ,
19
+ pub ( crate ) month : u8 ,
20
+ pub ( crate ) day : u8 ,
20
21
pub ( crate ) contents : String ,
21
22
pub ( crate ) url : String ,
22
23
pub ( crate ) published : String ,
@@ -30,16 +31,7 @@ pub struct Post {
30
31
impl Post {
31
32
pub ( crate ) fn open ( path : & Path , manifest : & Manifest ) -> eyre:: Result < Self > {
32
33
// yeah this might blow up, but it won't
33
- let filename = path. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
34
-
35
- // we need to get the metadata out of the url
36
- let mut split = filename. splitn ( 4 , '-' ) ;
37
-
38
- // we do some unwraps because these need to be valid
39
- let year = split. next ( ) . unwrap ( ) . parse :: < i32 > ( ) . unwrap ( ) ;
40
- let month = split. next ( ) . unwrap ( ) . parse :: < u32 > ( ) . unwrap ( ) ;
41
- let day = split. next ( ) . unwrap ( ) . parse :: < u32 > ( ) . unwrap ( ) ;
42
- let filename = split. next ( ) . unwrap ( ) . to_string ( ) ;
34
+ let filename = path. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . into ( ) ;
43
35
44
36
let contents = std:: fs:: read_to_string ( path) ?;
45
37
@@ -50,6 +42,7 @@ impl Post {
50
42
release,
51
43
team : team_string,
52
44
layout,
45
+ date : Date { year, month, day } ,
53
46
..
54
47
} ,
55
48
contents,
@@ -69,7 +62,7 @@ impl Post {
69
62
let contents = comrak:: markdown_to_html ( contents, & options) ;
70
63
71
64
// finally, the url.
72
- let mut url = PathBuf :: from ( & * filename) ;
65
+ let mut url = PathBuf :: from ( & filename) ;
73
66
url. set_extension ( "html" ) ;
74
67
75
68
// this is fine
@@ -139,8 +132,8 @@ impl Post {
139
132
}
140
133
}
141
134
142
- fn build_post_time ( year : i32 , month : u32 , day : u32 , seconds : u32 ) -> String {
143
- let date = chrono:: NaiveDate :: from_ymd_opt ( year, month, day) . unwrap ( ) ;
135
+ fn build_post_time ( year : u16 , month : u8 , day : u8 , seconds : u32 ) -> String {
136
+ let date = chrono:: NaiveDate :: from_ymd_opt ( year. into ( ) , month. into ( ) , day. into ( ) ) . unwrap ( ) ;
144
137
let date_time = date. and_hms_opt ( 0 , 0 , seconds) . unwrap ( ) ;
145
138
chrono:: DateTime :: < chrono:: Utc > :: from_naive_utc_and_offset ( date_time, chrono:: Utc ) . to_rfc3339 ( )
146
139
}
0 commit comments