File tree Expand file tree Collapse file tree 6 files changed +38
-14
lines changed
test_site/content/posts/tutorials/programming Expand file tree Collapse file tree 6 files changed +38
-14
lines changed Original file line number Diff line number Diff line change 1
- use std:: collections:: HashMap ;
2
-
3
- use tera:: Value ;
1
+ use tera:: { Map , Value } ;
4
2
use toml;
5
3
6
- use errors:: Result ;
7
-
8
4
use super :: { InsertAnchor , SortBy } ;
5
+ use errors:: Result ;
6
+ use utils:: de:: fix_toml_dates;
9
7
10
8
static DEFAULT_PAGINATE_PATH : & str = "page" ;
11
9
@@ -63,16 +61,21 @@ pub struct SectionFrontMatter {
63
61
#[ serde( skip_serializing) ]
64
62
pub aliases : Vec < String > ,
65
63
/// Any extra parameter present in the front matter
66
- pub extra : HashMap < String , Value > ,
64
+ pub extra : Map < String , Value > ,
67
65
}
68
66
69
67
impl SectionFrontMatter {
70
68
pub fn parse ( toml : & str ) -> Result < SectionFrontMatter > {
71
- let f: SectionFrontMatter = match toml:: from_str ( toml) {
69
+ let mut f: SectionFrontMatter = match toml:: from_str ( toml) {
72
70
Ok ( d) => d,
73
71
Err ( e) => bail ! ( e) ,
74
72
} ;
75
73
74
+ f. extra = match fix_toml_dates ( f. extra ) {
75
+ Value :: Object ( o) => o,
76
+ _ => unreachable ! ( "Got something other than a table in section extra" ) ,
77
+ } ;
78
+
76
79
Ok ( f)
77
80
}
78
81
@@ -102,7 +105,7 @@ impl Default for SectionFrontMatter {
102
105
transparent : false ,
103
106
page_template : None ,
104
107
aliases : Vec :: new ( ) ,
105
- extra : HashMap :: new ( ) ,
108
+ extra : Map :: new ( ) ,
106
109
}
107
110
}
108
111
}
Original file line number Diff line number Diff line change @@ -206,7 +206,7 @@ pub struct SerializingSection<'a> {
206
206
ancestors : Vec < String > ,
207
207
title : & ' a Option < String > ,
208
208
description : & ' a Option < String > ,
209
- extra : & ' a HashMap < String , Value > ,
209
+ extra : & ' a Map < String , Value > ,
210
210
path : & ' a str ,
211
211
components : & ' a [ String ] ,
212
212
toc : & ' a [ Heading ] ,
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ extern crate utils;
20
20
#[ cfg( test) ]
21
21
extern crate tempfile;
22
22
23
- mod sitemap;
23
+ pub mod sitemap;
24
24
25
25
use std:: collections:: HashMap ;
26
26
use std:: fs:: { copy, create_dir_all, remove_dir_all} ;
Original file line number Diff line number Diff line change @@ -11,9 +11,9 @@ use tera::{Map, Value};
11
11
/// for examples so we trim down all entries to only that
12
12
#[ derive( Debug , Serialize ) ]
13
13
pub struct SitemapEntry < ' a > {
14
- permalink : Cow < ' a , str > ,
15
- date : Option < String > ,
16
- extra : Option < & ' a Map < String , Value > > ,
14
+ pub permalink : Cow < ' a , str > ,
15
+ pub date : Option < String > ,
16
+ pub extra : Option < & ' a Map < String , Value > > ,
17
17
}
18
18
19
19
// Hash/Eq is not implemented for tera::Map but in our case we only care about the permalink
@@ -77,7 +77,11 @@ pub fn find_entries<'a>(
77
77
. sections_values ( )
78
78
. iter ( )
79
79
. filter ( |s| s. meta . render )
80
- . map ( |s| SitemapEntry :: new ( Cow :: Borrowed ( & s. permalink ) , None ) )
80
+ . map ( |s| {
81
+ let mut entry = SitemapEntry :: new ( Cow :: Borrowed ( & s. permalink ) , None ) ;
82
+ entry. add_extra ( & s. meta . extra ) ;
83
+ entry
84
+ } )
81
85
. collect :: < Vec < _ > > ( ) ;
82
86
83
87
for section in library. sections_values ( ) . iter ( ) . filter ( |s| s. meta . paginate_by . is_some ( ) ) {
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ use std::path::Path;
8
8
9
9
use common:: { build_site, build_site_with_setup} ;
10
10
use config:: Taxonomy ;
11
+ use site:: sitemap;
11
12
use site:: Site ;
12
13
13
14
#[ test]
@@ -87,6 +88,19 @@ fn can_parse_site() {
87
88
. unwrap ( ) ;
88
89
assert_eq ! ( prog_section. subsections. len( ) , 0 ) ;
89
90
assert_eq ! ( prog_section. pages. len( ) , 2 ) ;
91
+
92
+ // Testing extra variables in sections & sitemaps
93
+ // Regression test for #https://github.com/getzola/zola/issues/842
94
+ assert_eq ! (
95
+ prog_section. meta. extra. get( "we_have_extra" ) . and_then( |s| s. as_str( ) ) ,
96
+ Some ( "variables" )
97
+ ) ;
98
+ let sitemap_entries = sitemap:: find_entries ( & library, & site. taxonomies [ ..] , & site. config ) ;
99
+ let sitemap_entry = sitemap_entries
100
+ . iter ( )
101
+ . find ( |e| e. permalink . ends_with ( "tutorials/programming/" ) )
102
+ . expect ( "expected to find programming section in sitemap" ) ;
103
+ assert_eq ! ( Some ( & prog_section. meta. extra) , sitemap_entry. extra) ;
90
104
}
91
105
92
106
#[ test]
Original file line number Diff line number Diff line change 2
2
title = " Programming"
3
3
sort_by = " weight"
4
4
weight = 1
5
+
6
+ [extra ]
7
+ we_have_extra = " variables"
5
8
+++
You can’t perform that action at this time.
0 commit comments