Browse Source

Fix pagers not being in sitemap

Closes #521
index-subcmd
Vincent Prouillet 6 years ago
parent
commit
0cf8e8ca1c
5 changed files with 55 additions and 9 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +8
    -0
      components/config/src/config.rs
  3. +3
    -3
      components/library/src/pagination/mod.rs
  4. +16
    -0
      components/site/src/lib.rs
  5. +27
    -6
      components/site/tests/site.rs

+ 1
- 0
CHANGELOG.md View File

@@ -4,6 +4,7 @@


- Fix deleting markdown file in `zola serve` - Fix deleting markdown file in `zola serve`
- Fix pagination for taxonomies being broken and add missing documentation for it - Fix pagination for taxonomies being broken and add missing documentation for it
- Add missing pager pages from the sitemap




## 0.5.0 (2018-11-17) ## 0.5.0 (2018-11-17)


+ 8
- 0
components/config/src/config.rs View File

@@ -37,6 +37,14 @@ impl Taxonomy {
false false
} }
} }

pub fn paginate_path(&self) -> &str {
if let Some(ref path) = self.paginate_path {
path
} else {
"page"
}
}
} }


impl Default for Taxonomy { impl Default for Taxonomy {


+ 3
- 3
components/library/src/pagination/mod.rs View File

@@ -100,7 +100,7 @@ impl<'a> Paginator<'a> {
.kind .kind
.paginate_path .paginate_path
.clone() .clone()
.unwrap_or_else(|| "pages".to_string()),
.unwrap_or_else(|| "page".to_string()),
is_index: false, is_index: false,
template: format!("{}/single.html", taxonomy.kind.name), template: format!("{}/single.html", taxonomy.kind.name),
}; };
@@ -350,7 +350,7 @@ mod tests {


assert_eq!(paginator.pagers[1].index, 2); assert_eq!(paginator.pagers[1].index, 2);
assert_eq!(paginator.pagers[1].pages.len(), 1); assert_eq!(paginator.pagers[1].pages.len(), 1);
assert_eq!(paginator.pagers[1].permalink, "https://vincent.is/tags/something/pages/2/");
assert_eq!(paginator.pagers[1].path, "tags/something/pages/2/");
assert_eq!(paginator.pagers[1].permalink, "https://vincent.is/tags/something/page/2/");
assert_eq!(paginator.pagers[1].path, "tags/something/page/2/");
} }
} }

+ 16
- 0
components/site/src/lib.rs View File

@@ -721,6 +721,13 @@ impl Site {
.iter() .iter()
.map(|s| SitemapEntry::new(s.permalink.clone(), None)) .map(|s| SitemapEntry::new(s.permalink.clone(), None))
.collect::<Vec<_>>(); .collect::<Vec<_>>();
for section in self.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+1 {
let permalink = format!("{}{}/{}/", section.permalink, section.meta.paginate_path, i);
sections.push(SitemapEntry::new(permalink, None))
}
}
sections.sort_by(|a, b| a.permalink.cmp(&b.permalink)); sections.sort_by(|a, b| a.permalink.cmp(&b.permalink));
context.insert("sections", &sections); context.insert("sections", &sections);


@@ -734,7 +741,16 @@ impl Site {
self.config.make_permalink(&format!("{}/{}", &name, item.slug)), self.config.make_permalink(&format!("{}/{}", &name, item.slug)),
None, 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+1 {
let permalink = self.config.make_permalink(&format!("{}/{}/{}/{}", name, item.slug, taxonomy.kind.paginate_path(), i));
terms.push(SitemapEntry::new(permalink, None))
}
}
} }

terms.sort_by(|a, b| a.permalink.cmp(&b.permalink)); terms.sort_by(|a, b| a.permalink.cmp(&b.permalink));
taxonomies.push(terms); taxonomies.push(terms);
} }


+ 27
- 6
components/site/tests/site.rs View File

@@ -467,6 +467,13 @@ fn can_build_site_with_pagination_for_section() {
"posts/page/4/index.html", "posts/page/4/index.html",
"Last: https://replace-this-with-your-url.com/posts/page/5/" "Last: https://replace-this-with-your-url.com/posts/page/5/"
)); ));

// sitemap contains the pager pages
assert!(file_contains!(
public,
"sitemap.xml",
"<loc>https://replace-this-with-your-url.com/posts/page/4/</loc>"
));
} }


#[test] #[test]
@@ -512,6 +519,13 @@ fn can_build_site_with_pagination_for_index() {
assert!(file_contains!(public, "index.html", "Last: https://replace-this-with-your-url.com/")); assert!(file_contains!(public, "index.html", "Last: https://replace-this-with-your-url.com/"));
assert_eq!(file_contains!(public, "index.html", "has_prev"), false); assert_eq!(file_contains!(public, "index.html", "has_prev"), false);
assert_eq!(file_contains!(public, "index.html", "has_next"), false); assert_eq!(file_contains!(public, "index.html", "has_next"), false);

// sitemap contains the pager pages
assert!(file_contains!(
public,
"sitemap.xml",
"<loc>https://replace-this-with-your-url.com/page/1/</loc>"
))
} }


#[test] #[test]
@@ -558,15 +572,15 @@ fn can_build_site_with_pagination_for_taxonomy() {
assert!(file_exists!(public, "tags/a/rss.xml")); assert!(file_exists!(public, "tags/a/rss.xml"));
assert!(file_exists!(public, "tags/b/rss.xml")); assert!(file_exists!(public, "tags/b/rss.xml"));
// And pagination! // And pagination!
assert!(file_exists!(public, "tags/a/pages/1/index.html"));
assert!(file_exists!(public, "tags/b/pages/1/index.html"));
assert!(file_exists!(public, "tags/a/pages/2/index.html"));
assert!(file_exists!(public, "tags/b/pages/2/index.html"));
assert!(file_exists!(public, "tags/a/page/1/index.html"));
assert!(file_exists!(public, "tags/b/page/1/index.html"));
assert!(file_exists!(public, "tags/a/page/2/index.html"));
assert!(file_exists!(public, "tags/b/page/2/index.html"));


// should redirect to posts/ // should redirect to posts/
assert!(file_contains!( assert!(file_contains!(
public, public,
"tags/a/pages/1/index.html",
"tags/a/page/1/index.html",
"http-equiv=\"refresh\" content=\"0;url=https://replace-this-with-your-url.com/tags/a/\"" "http-equiv=\"refresh\" content=\"0;url=https://replace-this-with-your-url.com/tags/a/\""
)); ));
assert!(file_contains!(public, "tags/a/index.html", "Num pagers: 6")); assert!(file_contains!(public, "tags/a/index.html", "Num pagers: 6"));
@@ -582,9 +596,16 @@ fn can_build_site_with_pagination_for_taxonomy() {
assert!(file_contains!( assert!(file_contains!(
public, public,
"tags/a/index.html", "tags/a/index.html",
"Last: https://replace-this-with-your-url.com/tags/a/pages/6/"
"Last: https://replace-this-with-your-url.com/tags/a/page/6/"
)); ));
assert_eq!(file_contains!(public, "tags/a/index.html", "has_prev"), false); assert_eq!(file_contains!(public, "tags/a/index.html", "has_prev"), false);

// sitemap contains the pager pages
assert!(file_contains!(
public,
"sitemap.xml",
"<loc>https://replace-this-with-your-url.com/tags/a/page/6/</loc>"
))
} }


#[test] #[test]


Loading…
Cancel
Save