Skip to content

Commit

Permalink
fix: taxonomies missing lang in sitemap (#2373)
Browse files Browse the repository at this point in the history
  • Loading branch information
bemyak authored and Keats committed Dec 18, 2023
1 parent f560b48 commit 8ba7374
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
8 changes: 2 additions & 6 deletions components/content/src/pagination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,8 @@ impl<'a> Paginator<'a> {
paginate_reversed: false,
root: PaginationRoot::Taxonomy(taxonomy, item),
permalink: item.permalink.clone(),
path: format!("/{}/{}/", taxonomy.slug, item.slug),
paginate_path: taxonomy
.kind
.paginate_path
.clone()
.unwrap_or_else(|| "page".to_string()),
path: item.path.clone(),
paginate_path: taxonomy.kind.paginate_path().to_owned(),
is_index: false,
template: template.to_string(),
};
Expand Down
13 changes: 4 additions & 9 deletions components/site/src/sitemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,19 @@ pub fn find_entries<'a>(
if !taxonomy.kind.render {
continue;
}
let name = &taxonomy.kind.name;
entries.insert(SitemapEntry::new(Cow::Owned(config.make_permalink(name)), &None));
entries.insert(SitemapEntry::new(Cow::Borrowed(&taxonomy.permalink), &None));

for item in &taxonomy.items {
entries.insert(SitemapEntry::new(
Cow::Owned(config.make_permalink(&format!("{}/{}", name, item.slug))),
&None,
));
entries.insert(SitemapEntry::new(Cow::Borrowed(&item.permalink), &None));

if taxonomy.kind.is_paginated() {
let number_pagers = (item.pages.len() as f64
/ taxonomy.kind.paginate_by.unwrap() as f64)
.ceil() as isize;
for i in 1..=number_pagers {
let permalink = config.make_permalink(&format!(
"{}/{}/{}/{}",
name,
item.slug,
"{}{}/{}/",
item.path,
taxonomy.kind.paginate_path(),
i
));
Expand Down
8 changes: 8 additions & 0 deletions components/site/tests/site_i18n.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ fn can_build_multilingual_site() {
assert!(file_contains!(public, "fr/tags/index.html", "bonjour"));
assert!(!file_contains!(public, "fr/tags/index.html", "hello"));

// sitemap contains per-language taxonomies
assert!(file_contains!(public, "sitemap.xml", "https://example.com/tags/"));
assert!(file_contains!(public, "sitemap.xml", "https://example.com/tags/hello/"));
assert!(file_contains!(public, "sitemap.xml", "https://example.com/fr/tags/"));
assert!(file_contains!(public, "sitemap.xml", "https://example.com/fr/tags/bonjour/"));

assert!(!file_contains!(public, "sitemap.xml", "https://example.com/tags/bonjour"));

// one lang index per language
assert!(file_exists!(public, "search_index.en.js"));
assert!(file_exists!(public, "search_index.it.js"));
Expand Down

0 comments on commit 8ba7374

Please sign in to comment.