@@ -92,6 +92,20 @@ impl Document {
92
92
pub ( crate ) fn to_jsonfeed ( & self , root_url : & str ) -> jsonfeed:: Item {
93
93
let link = format ! ( "{}/{}" , root_url, & self . url_path) ;
94
94
95
+ let tags = if !self . front . tags . is_empty ( ) {
96
+ self . front
97
+ . tags
98
+ . iter ( )
99
+ . map ( |s| s. as_str ( ) . to_owned ( ) )
100
+ . collect ( )
101
+ } else {
102
+ self . front
103
+ . categories
104
+ . iter ( )
105
+ . map ( |s| s. as_str ( ) . to_owned ( ) )
106
+ . collect ( )
107
+ } ;
108
+
95
109
jsonfeed:: Item {
96
110
id : link. clone ( ) ,
97
111
url : Some ( link) ,
@@ -100,19 +114,7 @@ impl Document {
100
114
self . description_to_str ( ) . unwrap_or_else ( || "" . into ( ) ) ,
101
115
) ,
102
116
date_published : self . front . published_date . map ( |date| date. to_rfc2822 ( ) ) ,
103
- tags : Some (
104
- self . front
105
- . tags
106
- . as_ref ( )
107
- . map ( |tags| tags. iter ( ) . map ( |s| s. as_str ( ) . to_owned ( ) ) . collect ( ) )
108
- . unwrap_or_else ( || {
109
- self . front
110
- . categories
111
- . iter ( )
112
- . map ( |s| s. as_str ( ) . to_owned ( ) )
113
- . collect ( )
114
- } ) ,
115
- ) ,
117
+ tags : Some ( tags) ,
116
118
..Default :: default ( )
117
119
}
118
120
}
@@ -328,10 +330,11 @@ fn document_attributes(
328
330
. map ( Value :: scalar)
329
331
. collect ( ) ,
330
332
) ;
333
+ let tags = Value :: Array ( front. tags . iter ( ) . cloned ( ) . map ( Value :: scalar) . collect ( ) ) ;
331
334
// Reason for `file`:
332
335
// - Allow access to assets in the original location
333
336
// - Ease linking back to page's source
334
- let file: Object = vec ! [
337
+ let file: Object = [
335
338
(
336
339
"permalink" . into ( ) ,
337
340
Value :: scalar ( source_file. as_str ( ) . to_owned ( ) ) ,
@@ -349,7 +352,7 @@ fn document_attributes(
349
352
]
350
353
. into_iter ( )
351
354
. collect ( ) ;
352
- let attributes = vec ! [
355
+ let attributes = [
353
356
( "permalink" . into ( ) , Value :: scalar ( url_path. to_owned ( ) ) ) ,
354
357
( "title" . into ( ) , Value :: scalar ( front. title . clone ( ) ) ) ,
355
358
( "slug" . into ( ) , Value :: scalar ( front. slug . clone ( ) ) ) ,
@@ -358,6 +361,7 @@ fn document_attributes(
358
361
Value :: scalar ( front. description . as_deref ( ) . unwrap_or ( "" ) . to_owned ( ) ) ,
359
362
) ,
360
363
( "categories" . into ( ) , categories) ,
364
+ ( "tags" . into ( ) , tags) ,
361
365
( "is_draft" . into ( ) , Value :: scalar ( front. is_draft ) ) ,
362
366
( "weight" . into ( ) , Value :: scalar ( front. weight ) ) ,
363
367
( "file" . into ( ) , Value :: Object ( file) ) ,
@@ -366,11 +370,6 @@ fn document_attributes(
366
370
] ;
367
371
let mut attributes: Object = attributes. into_iter ( ) . collect ( ) ;
368
372
369
- if let Some ( ref tags) = front. tags {
370
- let tags = Value :: Array ( tags. iter ( ) . cloned ( ) . map ( Value :: scalar) . collect ( ) ) ;
371
- attributes. insert ( "tags" . into ( ) , tags) ;
372
- }
373
-
374
373
if let Some ( ref published_date) = front. published_date {
375
374
attributes. insert ( "published_date" . into ( ) , Value :: scalar ( * published_date) ) ;
376
375
}
0 commit comments