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 <justinturpin@pop-os.localdomain>
This commit is contained in:
Justin Turpin 2020-07-23 02:03:17 -07:00 committed by GitHub
parent 9f20af1521
commit c3f59bceec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 6 deletions

View file

@ -252,6 +252,16 @@ impl Section {
pub fn to_serialized_basic<'a>(&'a self, library: &'a Library) -> SerializingSection<'a> {
SerializingSection::from_section_basic(self, Some(library))
}
pub fn paginate_by(&self) -> Option<usize> {
match self.meta.paginate_by {
None => None,
Some(x) => match x {
0 => None,
_ => Some(x)
}
}
}
}
/// Used to create a default index section if there is no _index.md in the root content directory

View file

@ -85,12 +85,13 @@ pub fn find_entries<'a>(
})
.collect::<Vec<_>>();
for section in library.sections_values().iter().filter(|s| s.meta.paginate_by.is_some()) {
let number_pagers =
(section.pages.len() as f64 / section.meta.paginate_by.unwrap() as f64).ceil() as isize;
for i in 1..=number_pagers {
let permalink = format!("{}{}/{}/", section.permalink, section.meta.paginate_path, i);
sections.push(SitemapEntry::new(Cow::Owned(permalink), None))
for section in library.sections_values().iter() {
if let Some(paginate_by) = section.paginate_by() {
let number_pagers = (section.pages.len() as f64 / paginate_by as f64).ceil() as isize;
for i in 1..=number_pagers {
let permalink = format!("{}{}/{}/", section.permalink, section.meta.paginate_path, i);
sections.push(SitemapEntry::new(Cow::Owned(permalink), None))
}
}
}