From c3f59bceec9f16e76155a652ba9289196ff9aec5 Mon Sep 17 00:00:00 2001 From: Justin Turpin Date: Thu, 23 Jul 2020 02:03:17 -0700 Subject: [PATCH] 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 --- components/library/src/content/section.rs | 10 ++++++++++ components/site/src/sitemap.rs | 13 +++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/components/library/src/content/section.rs b/components/library/src/content/section.rs index 9630a725..5a2a61c0 100644 --- a/components/library/src/content/section.rs +++ b/components/library/src/content/section.rs @@ -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 { + 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 diff --git a/components/site/src/sitemap.rs b/components/site/src/sitemap.rs index afb20928..52d458bd 100644 --- a/components/site/src/sitemap.rs +++ b/components/site/src/sitemap.rs @@ -85,12 +85,13 @@ pub fn find_entries<'a>( }) .collect::>(); - 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)) + } } }