diff --git a/CHANGELOG.md b/CHANGELOG.md index 2196d3acf5..cc37316643 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ also specify classes on headers now - `skip_prefixes` is now checked before parsing external link URLs - Add `render` attribute to taxonomies configuration in `config.toml`, for when you don't want to render any pages related to that taxonomy +- Serialize `transparent` field from front-matter of sections ## 0.15.3 (2022-01-23) diff --git a/components/site/src/sitemap.rs b/components/site/src/sitemap.rs index 6179c67dba..360fc5ae74 100644 --- a/components/site/src/sitemap.rs +++ b/components/site/src/sitemap.rs @@ -14,7 +14,7 @@ use std::cmp::Ordering; #[derive(Debug, Serialize)] pub struct SitemapEntry<'a> { pub permalink: Cow<'a, str>, - pub updated: Option, + pub updated: &'a Option, pub extra: Option<&'a Map>, } @@ -33,7 +33,7 @@ impl<'a> PartialEq for SitemapEntry<'a> { impl<'a> Eq for SitemapEntry<'a> {} impl<'a> SitemapEntry<'a> { - pub fn new(permalink: Cow<'a, str>, updated: Option) -> Self { + pub fn new(permalink: Cow<'a, str>, updated: &'a Option) -> Self { SitemapEntry { permalink, updated, extra: None } } @@ -61,52 +61,44 @@ pub fn find_entries<'a>( taxonomies: &'a [Taxonomy], config: &'a Config, ) -> Vec> { - let pages = library - .pages - .values() - .map(|p| { - let mut entry = SitemapEntry::new( - Cow::Borrowed(&p.permalink), - p.meta.updated.clone().or_else(|| p.meta.date.clone()), - ); - entry.add_extra(&p.meta.extra); - entry - }) - .collect::>(); - - let mut sections = library - .sections - .values() - .filter(|s| s.meta.render) - .map(|s| { - let mut entry = SitemapEntry::new(Cow::Borrowed(&s.permalink), None); + let mut entries = HashSet::new(); + + for p in library.pages.values() { + let mut entry = SitemapEntry::new( + Cow::Borrowed(&p.permalink), + if p.meta.updated.is_some() { &p.meta.updated } else { &p.meta.date }, + ); + entry.add_extra(&p.meta.extra); + entries.insert(entry); + } + + for s in library.sections.values() { + if s.meta.render { + let mut entry = SitemapEntry::new(Cow::Borrowed(&s.permalink), &None); entry.add_extra(&s.meta.extra); - entry - }) - .collect::>(); + entries.insert(entry); + } - for section in library.sections.values() { - if let Some(paginate_by) = section.paginate_by() { - let number_pagers = (section.pages.len() as f64 / paginate_by as f64).ceil() as isize; + if let Some(paginate_by) = s.paginate_by() { + let number_pagers = (s.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)) + let permalink = format!("{}{}/{}/", s.permalink, s.meta.paginate_path, i); + entries.insert(SitemapEntry::new(Cow::Owned(permalink), &None)); } } } - let mut taxonomies_entries = vec![]; for taxonomy in taxonomies { if !taxonomy.kind.render { continue; } let name = &taxonomy.kind.name; - let mut terms = vec![SitemapEntry::new(Cow::Owned(config.make_permalink(name)), None)]; + entries.insert(SitemapEntry::new(Cow::Owned(config.make_permalink(name)), &None)); + for item in &taxonomy.items { - terms.push(SitemapEntry::new( + entries.insert(SitemapEntry::new( Cow::Owned(config.make_permalink(&format!("{}/{}", name, item.slug))), - None, + &None, )); if taxonomy.kind.is_paginated() { @@ -121,28 +113,13 @@ pub fn find_entries<'a>( taxonomy.kind.paginate_path(), i )); - terms.push(SitemapEntry::new(Cow::Owned(permalink), None)) + entries.insert(SitemapEntry::new(Cow::Owned(permalink), &None)); } } } - - taxonomies_entries.push(terms); - } - - let mut all_sitemap_entries = HashSet::new(); - for p in pages { - all_sitemap_entries.insert(p); - } - for s in sections { - all_sitemap_entries.insert(s); - } - for terms in taxonomies_entries { - for term in terms { - all_sitemap_entries.insert(term); - } } - let mut entries = all_sitemap_entries.into_iter().collect::>(); + let mut entries = entries.into_iter().collect::>(); entries.sort(); entries }