More efficient sitemap building
This commit is contained in:
parent
a0630efb76
commit
a297b11f2a
@ -17,6 +17,7 @@ also specify classes on headers now
|
|||||||
- `skip_prefixes` is now checked before parsing external link URLs
|
- `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
|
- Add `render` attribute to taxonomies configuration in `config.toml`, for when you don't want to render
|
||||||
any pages related to that taxonomy
|
any pages related to that taxonomy
|
||||||
|
- Serialize `transparent` field from front-matter of sections
|
||||||
|
|
||||||
## 0.15.3 (2022-01-23)
|
## 0.15.3 (2022-01-23)
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ use std::cmp::Ordering;
|
|||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
pub struct SitemapEntry<'a> {
|
pub struct SitemapEntry<'a> {
|
||||||
pub permalink: Cow<'a, str>,
|
pub permalink: Cow<'a, str>,
|
||||||
pub updated: Option<String>,
|
pub updated: &'a Option<String>,
|
||||||
pub extra: Option<&'a Map<String, Value>>,
|
pub extra: Option<&'a Map<String, Value>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ impl<'a> PartialEq for SitemapEntry<'a> {
|
|||||||
impl<'a> Eq for SitemapEntry<'a> {}
|
impl<'a> Eq for SitemapEntry<'a> {}
|
||||||
|
|
||||||
impl<'a> SitemapEntry<'a> {
|
impl<'a> SitemapEntry<'a> {
|
||||||
pub fn new(permalink: Cow<'a, str>, updated: Option<String>) -> Self {
|
pub fn new(permalink: Cow<'a, str>, updated: &'a Option<String>) -> Self {
|
||||||
SitemapEntry { permalink, updated, extra: None }
|
SitemapEntry { permalink, updated, extra: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,52 +61,44 @@ pub fn find_entries<'a>(
|
|||||||
taxonomies: &'a [Taxonomy],
|
taxonomies: &'a [Taxonomy],
|
||||||
config: &'a Config,
|
config: &'a Config,
|
||||||
) -> Vec<SitemapEntry<'a>> {
|
) -> Vec<SitemapEntry<'a>> {
|
||||||
let pages = library
|
let mut entries = HashSet::new();
|
||||||
.pages
|
|
||||||
.values()
|
for p in library.pages.values() {
|
||||||
.map(|p| {
|
|
||||||
let mut entry = SitemapEntry::new(
|
let mut entry = SitemapEntry::new(
|
||||||
Cow::Borrowed(&p.permalink),
|
Cow::Borrowed(&p.permalink),
|
||||||
p.meta.updated.clone().or_else(|| p.meta.date.clone()),
|
if p.meta.updated.is_some() { &p.meta.updated } else { &p.meta.date },
|
||||||
);
|
);
|
||||||
entry.add_extra(&p.meta.extra);
|
entry.add_extra(&p.meta.extra);
|
||||||
entry
|
entries.insert(entry);
|
||||||
})
|
}
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
let mut sections = library
|
for s in library.sections.values() {
|
||||||
.sections
|
if s.meta.render {
|
||||||
.values()
|
let mut entry = SitemapEntry::new(Cow::Borrowed(&s.permalink), &None);
|
||||||
.filter(|s| s.meta.render)
|
|
||||||
.map(|s| {
|
|
||||||
let mut entry = SitemapEntry::new(Cow::Borrowed(&s.permalink), None);
|
|
||||||
entry.add_extra(&s.meta.extra);
|
entry.add_extra(&s.meta.extra);
|
||||||
entry
|
entries.insert(entry);
|
||||||
})
|
}
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
for section in library.sections.values() {
|
if let Some(paginate_by) = s.paginate_by() {
|
||||||
if let Some(paginate_by) = section.paginate_by() {
|
let number_pagers = (s.pages.len() as f64 / paginate_by as f64).ceil() as isize;
|
||||||
let number_pagers = (section.pages.len() as f64 / paginate_by as f64).ceil() as isize;
|
|
||||||
for i in 1..=number_pagers {
|
for i in 1..=number_pagers {
|
||||||
let permalink =
|
let permalink = format!("{}{}/{}/", s.permalink, s.meta.paginate_path, i);
|
||||||
format!("{}{}/{}/", section.permalink, section.meta.paginate_path, i);
|
entries.insert(SitemapEntry::new(Cow::Owned(permalink), &None));
|
||||||
sections.push(SitemapEntry::new(Cow::Owned(permalink), None))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut taxonomies_entries = vec![];
|
|
||||||
for taxonomy in taxonomies {
|
for taxonomy in taxonomies {
|
||||||
if !taxonomy.kind.render {
|
if !taxonomy.kind.render {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let name = &taxonomy.kind.name;
|
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 {
|
for item in &taxonomy.items {
|
||||||
terms.push(SitemapEntry::new(
|
entries.insert(SitemapEntry::new(
|
||||||
Cow::Owned(config.make_permalink(&format!("{}/{}", name, item.slug))),
|
Cow::Owned(config.make_permalink(&format!("{}/{}", name, item.slug))),
|
||||||
None,
|
&None,
|
||||||
));
|
));
|
||||||
|
|
||||||
if taxonomy.kind.is_paginated() {
|
if taxonomy.kind.is_paginated() {
|
||||||
@ -121,28 +113,13 @@ pub fn find_entries<'a>(
|
|||||||
taxonomy.kind.paginate_path(),
|
taxonomy.kind.paginate_path(),
|
||||||
i
|
i
|
||||||
));
|
));
|
||||||
terms.push(SitemapEntry::new(Cow::Owned(permalink), None))
|
entries.insert(SitemapEntry::new(Cow::Owned(permalink), &None));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
taxonomies_entries.push(terms);
|
let mut entries = entries.into_iter().collect::<Vec<_>>();
|
||||||
}
|
|
||||||
|
|
||||||
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::<Vec<_>>();
|
|
||||||
entries.sort();
|
entries.sort();
|
||||||
entries
|
entries
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user