Skip to content

Commit c3f59bc

Browse files
justinturpinJustin Turpin
andauthored
Fix pagination section memory issue (#1097)
* Update sitemap.rs When paginate_by is zero, set number_pagers to 1 so at least 1 sitemap section is pushed * paginate_by updates Introduce section.paginate_by, use value if it exists, removes now unnecessary filter Co-authored-by: Justin Turpin <[email protected]>
1 parent 9f20af1 commit c3f59bc

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

components/library/src/content/section.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,16 @@ impl Section {
252252
pub fn to_serialized_basic<'a>(&'a self, library: &'a Library) -> SerializingSection<'a> {
253253
SerializingSection::from_section_basic(self, Some(library))
254254
}
255+
256+
pub fn paginate_by(&self) -> Option<usize> {
257+
match self.meta.paginate_by {
258+
None => None,
259+
Some(x) => match x {
260+
0 => None,
261+
_ => Some(x)
262+
}
263+
}
264+
}
255265
}
256266

257267
/// Used to create a default index section if there is no _index.md in the root content directory

components/site/src/sitemap.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,13 @@ pub fn find_entries<'a>(
8585
})
8686
.collect::<Vec<_>>();
8787

88-
for section in library.sections_values().iter().filter(|s| s.meta.paginate_by.is_some()) {
89-
let number_pagers =
90-
(section.pages.len() as f64 / section.meta.paginate_by.unwrap() as f64).ceil() as isize;
91-
for i in 1..=number_pagers {
92-
let permalink = format!("{}{}/{}/", section.permalink, section.meta.paginate_path, i);
93-
sections.push(SitemapEntry::new(Cow::Owned(permalink), None))
88+
for section in library.sections_values().iter() {
89+
if let Some(paginate_by) = section.paginate_by() {
90+
let number_pagers = (section.pages.len() as f64 / paginate_by as f64).ceil() as isize;
91+
for i in 1..=number_pagers {
92+
let permalink = format!("{}{}/{}/", section.permalink, section.meta.paginate_path, i);
93+
sections.push(SitemapEntry::new(Cow::Owned(permalink), None))
94+
}
9495
}
9596
}
9697

0 commit comments

Comments
 (0)