2018-11-29 19:24:45 +00:00
|
|
|
extern crate config;
|
2017-07-01 07:47:41 +00:00
|
|
|
extern crate site;
|
2018-12-28 16:30:47 +00:00
|
|
|
mod common;
|
2017-03-14 12:25:45 +00:00
|
|
|
|
2018-07-16 08:54:05 +00:00
|
|
|
use std::collections::HashMap;
|
2017-03-14 12:25:45 +00:00
|
|
|
use std::env;
|
2018-10-31 07:18:57 +00:00
|
|
|
use std::path::Path;
|
2017-03-14 12:25:45 +00:00
|
|
|
|
2018-12-29 10:17:43 +00:00
|
|
|
use common::{build_site, build_site_with_setup};
|
2018-11-29 19:24:45 +00:00
|
|
|
use config::Taxonomy;
|
2017-07-01 07:47:41 +00:00
|
|
|
use site::Site;
|
2017-03-14 12:25:45 +00:00
|
|
|
|
|
|
|
#[test]
|
2017-05-15 10:53:39 +00:00
|
|
|
fn can_parse_site() {
|
2018-01-29 17:40:12 +00:00
|
|
|
let mut path = env::current_dir().unwrap().parent().unwrap().parent().unwrap().to_path_buf();
|
2017-03-14 12:25:45 +00:00
|
|
|
path.push("test_site");
|
2017-03-25 04:18:15 +00:00
|
|
|
let mut site = Site::new(&path, "config.toml").unwrap();
|
2017-03-21 07:57:00 +00:00
|
|
|
site.load().unwrap();
|
2017-03-14 12:25:45 +00:00
|
|
|
|
2018-11-07 18:42:15 +00:00
|
|
|
// Correct number of pages (sections do not count as pages)
|
2018-11-12 23:08:46 +00:00
|
|
|
assert_eq!(site.library.pages().len(), 22);
|
2017-03-14 12:25:45 +00:00
|
|
|
let posts_path = path.join("content").join("posts");
|
|
|
|
|
|
|
|
// Make sure the page with a url doesn't have any sections
|
2018-10-02 14:42:34 +00:00
|
|
|
let url_post = site.library.get_page(&posts_path.join("fixed-url.md")).unwrap();
|
2017-06-10 17:52:39 +00:00
|
|
|
assert_eq!(url_post.path, "a-fixed-url/");
|
2017-03-14 12:25:45 +00:00
|
|
|
|
|
|
|
// Make sure the article in a folder with only asset doesn't get counted as a section
|
2018-10-31 07:18:57 +00:00
|
|
|
let asset_folder_post =
|
|
|
|
site.library.get_page(&posts_path.join("with-assets").join("index.md")).unwrap();
|
2017-05-15 10:53:39 +00:00
|
|
|
assert_eq!(asset_folder_post.file.components, vec!["posts".to_string()]);
|
2017-03-14 12:25:45 +00:00
|
|
|
|
|
|
|
// That we have the right number of sections
|
2018-11-07 19:48:39 +00:00
|
|
|
assert_eq!(site.library.sections().len(), 11);
|
2017-03-14 12:25:45 +00:00
|
|
|
|
|
|
|
// And that the sections are correct
|
2018-10-02 14:42:34 +00:00
|
|
|
let index_section = site.library.get_section(&path.join("content").join("_index.md")).unwrap();
|
2018-11-07 18:42:15 +00:00
|
|
|
assert_eq!(index_section.subsections.len(), 4);
|
2017-05-08 10:29:37 +00:00
|
|
|
assert_eq!(index_section.pages.len(), 1);
|
2018-10-18 13:54:51 +00:00
|
|
|
assert!(index_section.ancestors.is_empty());
|
2017-05-08 10:29:37 +00:00
|
|
|
|
2018-10-02 14:42:34 +00:00
|
|
|
let posts_section = site.library.get_section(&posts_path.join("_index.md")).unwrap();
|
2018-11-05 23:46:11 +00:00
|
|
|
assert_eq!(posts_section.subsections.len(), 2);
|
2018-11-12 23:08:46 +00:00
|
|
|
assert_eq!(posts_section.pages.len(), 10);
|
2018-10-31 07:18:57 +00:00
|
|
|
assert_eq!(
|
|
|
|
posts_section.ancestors,
|
|
|
|
vec![*site.library.get_section_key(&index_section.file.path).unwrap()]
|
|
|
|
);
|
2018-10-15 20:28:25 +00:00
|
|
|
|
|
|
|
// Make sure we remove all the pwd + content from the sections
|
|
|
|
let basic = site.library.get_page(&posts_path.join("simple.md")).unwrap();
|
|
|
|
assert_eq!(basic.file.components, vec!["posts".to_string()]);
|
2018-10-18 13:54:51 +00:00
|
|
|
assert_eq!(
|
|
|
|
basic.ancestors,
|
|
|
|
vec![
|
|
|
|
*site.library.get_section_key(&index_section.file.path).unwrap(),
|
|
|
|
*site.library.get_section_key(&posts_section.file.path).unwrap(),
|
|
|
|
]
|
|
|
|
);
|
2017-03-14 12:25:45 +00:00
|
|
|
|
2018-10-31 07:18:57 +00:00
|
|
|
let tutorials_section =
|
|
|
|
site.library.get_section(&posts_path.join("tutorials").join("_index.md")).unwrap();
|
2017-03-14 12:25:45 +00:00
|
|
|
assert_eq!(tutorials_section.subsections.len(), 2);
|
2018-10-02 14:42:34 +00:00
|
|
|
let sub1 = site.library.get_section_by_key(tutorials_section.subsections[0]);
|
|
|
|
let sub2 = site.library.get_section_by_key(tutorials_section.subsections[1]);
|
|
|
|
assert_eq!(sub1.clone().meta.title.unwrap(), "Programming");
|
|
|
|
assert_eq!(sub2.clone().meta.title.unwrap(), "DevOps");
|
2017-03-14 12:25:45 +00:00
|
|
|
assert_eq!(tutorials_section.pages.len(), 0);
|
|
|
|
|
2018-10-31 07:18:57 +00:00
|
|
|
let devops_section = site
|
|
|
|
.library
|
|
|
|
.get_section(&posts_path.join("tutorials").join("devops").join("_index.md"))
|
|
|
|
.unwrap();
|
2017-03-14 12:25:45 +00:00
|
|
|
assert_eq!(devops_section.subsections.len(), 0);
|
|
|
|
assert_eq!(devops_section.pages.len(), 2);
|
2018-10-18 13:54:51 +00:00
|
|
|
assert_eq!(
|
|
|
|
devops_section.ancestors,
|
|
|
|
vec![
|
|
|
|
*site.library.get_section_key(&index_section.file.path).unwrap(),
|
|
|
|
*site.library.get_section_key(&posts_section.file.path).unwrap(),
|
|
|
|
*site.library.get_section_key(&tutorials_section.file.path).unwrap(),
|
|
|
|
]
|
|
|
|
);
|
2017-03-14 12:25:45 +00:00
|
|
|
|
2018-10-31 07:18:57 +00:00
|
|
|
let prog_section = site
|
|
|
|
.library
|
|
|
|
.get_section(&posts_path.join("tutorials").join("programming").join("_index.md"))
|
|
|
|
.unwrap();
|
2017-03-14 12:25:45 +00:00
|
|
|
assert_eq!(prog_section.subsections.len(), 0);
|
|
|
|
assert_eq!(prog_section.pages.len(), 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2017-05-15 10:53:39 +00:00
|
|
|
fn can_build_site_without_live_reload() {
|
2018-12-28 16:30:47 +00:00
|
|
|
let (_, _tmp_dir, public) = build_site("test_site");
|
2017-03-14 12:25:45 +00:00
|
|
|
|
2018-03-16 21:20:03 +00:00
|
|
|
assert!(&public.exists());
|
2017-03-14 12:25:45 +00:00
|
|
|
assert!(file_exists!(public, "index.html"));
|
|
|
|
assert!(file_exists!(public, "sitemap.xml"));
|
2017-03-20 12:40:03 +00:00
|
|
|
assert!(file_exists!(public, "robots.txt"));
|
2017-03-14 12:25:45 +00:00
|
|
|
assert!(file_exists!(public, "a-fixed-url/index.html"));
|
|
|
|
|
|
|
|
assert!(file_exists!(public, "posts/python/index.html"));
|
2017-10-23 08:49:13 +00:00
|
|
|
// Shortcodes work
|
|
|
|
assert!(file_contains!(public, "posts/python/index.html", "Basic shortcode"));
|
2017-10-23 08:57:39 +00:00
|
|
|
assert!(file_contains!(public, "posts/python/index.html", "Arrrh Bob"));
|
2017-10-23 12:18:05 +00:00
|
|
|
assert!(file_contains!(public, "posts/python/index.html", "Arrrh Bob_Sponge"));
|
2017-03-14 12:25:45 +00:00
|
|
|
assert!(file_exists!(public, "posts/tutorials/devops/nix/index.html"));
|
|
|
|
assert!(file_exists!(public, "posts/with-assets/index.html"));
|
2017-05-08 10:29:37 +00:00
|
|
|
assert!(file_exists!(public, "posts/no-section/simple/index.html"));
|
2017-03-14 12:25:45 +00:00
|
|
|
|
|
|
|
// Sections
|
|
|
|
assert!(file_exists!(public, "posts/index.html"));
|
|
|
|
assert!(file_exists!(public, "posts/tutorials/index.html"));
|
|
|
|
assert!(file_exists!(public, "posts/tutorials/devops/index.html"));
|
|
|
|
assert!(file_exists!(public, "posts/tutorials/programming/index.html"));
|
2017-09-12 07:13:10 +00:00
|
|
|
// Ensure subsection pages are correctly filled
|
|
|
|
assert!(file_contains!(public, "posts/tutorials/index.html", "Sub-pages: 2"));
|
2018-10-18 16:00:39 +00:00
|
|
|
|
|
|
|
// Pages and section get their relative path
|
|
|
|
assert!(file_contains!(public, "posts/tutorials/index.html", "posts/tutorials/_index.md"));
|
2018-10-31 07:18:57 +00:00
|
|
|
assert!(file_contains!(
|
|
|
|
public,
|
|
|
|
"posts/tutorials/devops/nix/index.html",
|
|
|
|
"posts/tutorials/devops/nix.md"
|
|
|
|
));
|
2017-03-14 12:25:45 +00:00
|
|
|
|
2017-06-16 14:09:01 +00:00
|
|
|
// aliases work
|
|
|
|
assert!(file_exists!(public, "an-old-url/old-page/index.html"));
|
|
|
|
assert!(file_contains!(public, "an-old-url/old-page/index.html", "something-else"));
|
|
|
|
|
2018-05-16 18:25:05 +00:00
|
|
|
// html aliases work
|
|
|
|
assert!(file_exists!(public, "an-old-url/an-old-alias.html"));
|
|
|
|
assert!(file_contains!(public, "an-old-url/an-old-alias.html", "something-else"));
|
|
|
|
|
2017-07-25 07:56:13 +00:00
|
|
|
// redirect_to works
|
|
|
|
assert!(file_exists!(public, "posts/tutorials/devops/index.html"));
|
|
|
|
assert!(file_contains!(public, "posts/tutorials/devops/index.html", "docker"));
|
|
|
|
|
2018-11-16 22:51:11 +00:00
|
|
|
// We do have categories
|
|
|
|
assert_eq!(file_exists!(public, "categories/index.html"), true);
|
|
|
|
assert_eq!(file_exists!(public, "categories/a-category/index.html"), true);
|
|
|
|
assert_eq!(file_exists!(public, "categories/a-category/rss.xml"), true);
|
|
|
|
// But no tags
|
2017-03-14 12:25:45 +00:00
|
|
|
assert_eq!(file_exists!(public, "tags/index.html"), false);
|
|
|
|
|
2017-08-23 10:17:24 +00:00
|
|
|
// Theme files are there
|
|
|
|
assert!(file_exists!(public, "sample.css"));
|
|
|
|
assert!(file_exists!(public, "some.js"));
|
|
|
|
|
2018-03-16 21:20:03 +00:00
|
|
|
// SASS and SCSS files compile correctly
|
|
|
|
assert!(file_exists!(public, "blog.css"));
|
|
|
|
assert!(file_contains!(public, "blog.css", "red"));
|
|
|
|
assert!(file_contains!(public, "blog.css", "blue"));
|
|
|
|
assert!(!file_contains!(public, "blog.css", "@import \"included\""));
|
|
|
|
assert!(file_contains!(public, "blog.css", "2rem")); // check include
|
|
|
|
assert!(!file_exists!(public, "_included.css"));
|
|
|
|
assert!(file_exists!(public, "scss.css"));
|
2018-03-17 18:57:03 +00:00
|
|
|
assert!(file_exists!(public, "sass.css"));
|
|
|
|
assert!(file_exists!(public, "nested_sass/sass.css"));
|
2018-03-16 21:20:03 +00:00
|
|
|
assert!(file_exists!(public, "nested_sass/scss.css"));
|
|
|
|
|
2017-03-14 12:25:45 +00:00
|
|
|
// no live reload code
|
|
|
|
assert_eq!(file_contains!(public, "index.html", "/livereload.js?port=1112&mindelay=10"), false);
|
2017-03-19 10:40:31 +00:00
|
|
|
|
|
|
|
// Both pages and sections are in the sitemap
|
2018-10-31 07:18:57 +00:00
|
|
|
assert!(file_contains!(
|
|
|
|
public,
|
|
|
|
"sitemap.xml",
|
|
|
|
"<loc>https://replace-this-with-your-url.com/posts/simple/</loc>"
|
|
|
|
));
|
|
|
|
assert!(file_contains!(
|
|
|
|
public,
|
|
|
|
"sitemap.xml",
|
|
|
|
"<loc>https://replace-this-with-your-url.com/posts/</loc>"
|
|
|
|
));
|
2017-09-25 09:55:43 +00:00
|
|
|
// Drafts are not in the sitemap
|
|
|
|
assert!(!file_contains!(public, "sitemap.xml", "draft"));
|
2018-09-30 17:05:56 +00:00
|
|
|
|
|
|
|
// robots.txt has been rendered from the template
|
2018-10-18 20:50:06 +00:00
|
|
|
assert!(file_contains!(public, "robots.txt", "User-agent: zola"));
|
2018-10-31 07:18:57 +00:00
|
|
|
assert!(file_contains!(
|
|
|
|
public,
|
|
|
|
"robots.txt",
|
|
|
|
"Sitemap: https://replace-this-with-your-url.com/sitemap.xml"
|
|
|
|
));
|
2017-03-14 12:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2017-05-15 10:53:39 +00:00
|
|
|
fn can_build_site_with_live_reload() {
|
2018-12-28 16:30:47 +00:00
|
|
|
let (_, _tmp_dir, public) = build_site_with_setup("test_site", |mut site| {
|
|
|
|
site.enable_live_reload(1000);
|
|
|
|
(site, true)
|
|
|
|
});
|
2017-03-14 12:25:45 +00:00
|
|
|
|
2018-12-28 16:30:47 +00:00
|
|
|
assert!(&public.exists());
|
2017-03-14 12:25:45 +00:00
|
|
|
|
|
|
|
assert!(file_exists!(public, "index.html"));
|
|
|
|
assert!(file_exists!(public, "sitemap.xml"));
|
2017-03-20 12:40:03 +00:00
|
|
|
assert!(file_exists!(public, "robots.txt"));
|
2017-03-14 12:25:45 +00:00
|
|
|
assert!(file_exists!(public, "a-fixed-url/index.html"));
|
|
|
|
|
|
|
|
assert!(file_exists!(public, "posts/python/index.html"));
|
|
|
|
assert!(file_exists!(public, "posts/tutorials/devops/nix/index.html"));
|
|
|
|
assert!(file_exists!(public, "posts/with-assets/index.html"));
|
|
|
|
|
|
|
|
// Sections
|
|
|
|
assert!(file_exists!(public, "posts/index.html"));
|
|
|
|
assert!(file_exists!(public, "posts/tutorials/index.html"));
|
|
|
|
assert!(file_exists!(public, "posts/tutorials/devops/index.html"));
|
|
|
|
assert!(file_exists!(public, "posts/tutorials/programming/index.html"));
|
|
|
|
// TODO: add assertion for syntax highlighting
|
|
|
|
|
2018-11-16 22:51:11 +00:00
|
|
|
// We do have categories
|
|
|
|
assert_eq!(file_exists!(public, "categories/index.html"), true);
|
|
|
|
assert_eq!(file_exists!(public, "categories/a-category/index.html"), true);
|
|
|
|
assert_eq!(file_exists!(public, "categories/a-category/rss.xml"), true);
|
|
|
|
// But no tags
|
2017-03-14 12:25:45 +00:00
|
|
|
assert_eq!(file_exists!(public, "tags/index.html"), false);
|
|
|
|
|
|
|
|
// no live reload code
|
2018-05-11 11:54:16 +00:00
|
|
|
assert!(file_contains!(public, "index.html", "/livereload.js"));
|
2018-03-28 15:01:14 +00:00
|
|
|
|
|
|
|
// the summary anchor link has been created
|
2018-10-31 07:18:57 +00:00
|
|
|
assert!(file_contains!(
|
|
|
|
public,
|
|
|
|
"posts/python/index.html",
|
|
|
|
r#"<a name="continue-reading"></a>"#
|
|
|
|
));
|
2018-03-28 19:08:44 +00:00
|
|
|
assert!(file_contains!(public, "posts/draft/index.html", r#"THEME_SHORTCODE"#));
|
2017-03-14 12:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2018-07-16 08:54:05 +00:00
|
|
|
fn can_build_site_with_taxonomies() {
|
2018-12-28 16:30:47 +00:00
|
|
|
let (site, _tmp_dir, public) = build_site_with_setup("test_site", |mut site| {
|
|
|
|
site.load().unwrap();
|
|
|
|
for (i, (_, page)) in site.library.pages_mut().iter_mut().enumerate() {
|
|
|
|
page.meta.taxonomies = {
|
|
|
|
let mut taxonomies = HashMap::new();
|
|
|
|
taxonomies.insert(
|
|
|
|
"categories".to_string(),
|
|
|
|
vec![if i % 2 == 0 { "A" } else { "B" }.to_string()],
|
|
|
|
);
|
|
|
|
taxonomies
|
|
|
|
};
|
|
|
|
}
|
|
|
|
site.populate_taxonomies().unwrap();
|
|
|
|
(site, false)
|
|
|
|
});
|
2017-03-19 11:20:24 +00:00
|
|
|
|
2018-12-28 16:30:47 +00:00
|
|
|
assert!(&public.exists());
|
2018-07-16 08:54:05 +00:00
|
|
|
assert_eq!(site.taxonomies.len(), 1);
|
2017-03-19 11:20:24 +00:00
|
|
|
|
|
|
|
assert!(file_exists!(public, "index.html"));
|
|
|
|
assert!(file_exists!(public, "sitemap.xml"));
|
2017-03-20 12:40:03 +00:00
|
|
|
assert!(file_exists!(public, "robots.txt"));
|
2017-03-19 11:20:24 +00:00
|
|
|
assert!(file_exists!(public, "a-fixed-url/index.html"));
|
|
|
|
|
|
|
|
assert!(file_exists!(public, "posts/python/index.html"));
|
|
|
|
assert!(file_exists!(public, "posts/tutorials/devops/nix/index.html"));
|
|
|
|
assert!(file_exists!(public, "posts/with-assets/index.html"));
|
|
|
|
|
|
|
|
// Sections
|
|
|
|
assert!(file_exists!(public, "posts/index.html"));
|
|
|
|
assert!(file_exists!(public, "posts/tutorials/index.html"));
|
|
|
|
assert!(file_exists!(public, "posts/tutorials/devops/index.html"));
|
|
|
|
assert!(file_exists!(public, "posts/tutorials/programming/index.html"));
|
|
|
|
|
|
|
|
// Categories are there
|
|
|
|
assert!(file_exists!(public, "categories/index.html"));
|
|
|
|
assert!(file_exists!(public, "categories/a/index.html"));
|
|
|
|
assert!(file_exists!(public, "categories/b/index.html"));
|
2018-07-16 08:54:05 +00:00
|
|
|
assert!(file_exists!(public, "categories/a/rss.xml"));
|
2018-10-31 07:18:57 +00:00
|
|
|
assert!(file_contains!(
|
|
|
|
public,
|
|
|
|
"categories/a/rss.xml",
|
|
|
|
"https://replace-this-with-your-url.com/categories/a/rss.xml"
|
|
|
|
));
|
2017-08-30 13:11:17 +00:00
|
|
|
// Extending from a theme works
|
|
|
|
assert!(file_contains!(public, "categories/a/index.html", "EXTENDED"));
|
2017-03-19 11:20:24 +00:00
|
|
|
// Tags aren't
|
|
|
|
assert_eq!(file_exists!(public, "tags/index.html"), false);
|
2017-03-20 03:42:43 +00:00
|
|
|
|
|
|
|
// Categories are in the sitemap
|
2018-10-31 07:18:57 +00:00
|
|
|
assert!(file_contains!(
|
|
|
|
public,
|
|
|
|
"sitemap.xml",
|
|
|
|
"<loc>https://replace-this-with-your-url.com/categories/</loc>"
|
|
|
|
));
|
|
|
|
assert!(file_contains!(
|
|
|
|
public,
|
|
|
|
"sitemap.xml",
|
|
|
|
"<loc>https://replace-this-with-your-url.com/categories/a/</loc>"
|
|
|
|
));
|
2017-03-14 12:25:45 +00:00
|
|
|
}
|
|
|
|
|
2017-04-10 11:26:35 +00:00
|
|
|
#[test]
|
2017-05-15 10:53:39 +00:00
|
|
|
fn can_build_site_and_insert_anchor_links() {
|
2018-12-28 16:30:47 +00:00
|
|
|
let (_, _tmp_dir, public) = build_site("test_site");
|
2017-04-10 11:26:35 +00:00
|
|
|
|
|
|
|
assert!(Path::new(&public).exists());
|
|
|
|
// anchor link inserted
|
2018-10-31 07:18:57 +00:00
|
|
|
assert!(file_contains!(
|
|
|
|
public,
|
|
|
|
"posts/something-else/index.html",
|
|
|
|
"<h1 id=\"title\"><a class=\"zola-anchor\" href=\"#title\""
|
|
|
|
));
|
2017-04-10 11:26:35 +00:00
|
|
|
}
|
2017-05-03 08:52:49 +00:00
|
|
|
|
|
|
|
#[test]
|
2017-05-15 10:53:39 +00:00
|
|
|
fn can_build_site_with_pagination_for_section() {
|
2018-12-28 16:30:47 +00:00
|
|
|
let (_, _tmp_dir, public) = build_site_with_setup("test_site", |mut site| {
|
|
|
|
site.load().unwrap();
|
|
|
|
for (_, section) in site.library.sections_mut() {
|
|
|
|
if section.is_index() {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
section.meta.paginate_by = Some(2);
|
|
|
|
section.meta.template = Some("section_paginated.html".to_string());
|
2017-05-12 11:24:44 +00:00
|
|
|
}
|
2018-12-28 16:30:47 +00:00
|
|
|
(site, false)
|
|
|
|
});
|
2017-05-03 08:52:49 +00:00
|
|
|
|
2018-12-28 16:30:47 +00:00
|
|
|
assert!(&public.exists());
|
2017-05-03 08:52:49 +00:00
|
|
|
|
|
|
|
assert!(file_exists!(public, "index.html"));
|
|
|
|
assert!(file_exists!(public, "sitemap.xml"));
|
|
|
|
assert!(file_exists!(public, "robots.txt"));
|
|
|
|
assert!(file_exists!(public, "a-fixed-url/index.html"));
|
|
|
|
assert!(file_exists!(public, "posts/python/index.html"));
|
|
|
|
assert!(file_exists!(public, "posts/tutorials/devops/nix/index.html"));
|
|
|
|
assert!(file_exists!(public, "posts/with-assets/index.html"));
|
|
|
|
|
|
|
|
// Sections
|
|
|
|
assert!(file_exists!(public, "posts/index.html"));
|
|
|
|
// And pagination!
|
|
|
|
assert!(file_exists!(public, "posts/page/1/index.html"));
|
2017-05-12 11:24:44 +00:00
|
|
|
// even if there is no pages, only the section!
|
|
|
|
assert!(file_exists!(public, "paginated/page/1/index.html"));
|
|
|
|
assert!(file_exists!(public, "paginated/index.html"));
|
2017-05-03 08:52:49 +00:00
|
|
|
// should redirect to posts/
|
|
|
|
assert!(file_contains!(
|
|
|
|
public,
|
|
|
|
"posts/page/1/index.html",
|
2017-06-10 17:52:39 +00:00
|
|
|
"http-equiv=\"refresh\" content=\"0;url=https://replace-this-with-your-url.com/posts/\""
|
2017-05-03 08:52:49 +00:00
|
|
|
));
|
2018-11-12 23:08:46 +00:00
|
|
|
assert!(file_contains!(public, "posts/index.html", "Num pagers: 5"));
|
2017-05-03 08:52:49 +00:00
|
|
|
assert!(file_contains!(public, "posts/index.html", "Page size: 2"));
|
|
|
|
assert!(file_contains!(public, "posts/index.html", "Current index: 1"));
|
2018-08-14 07:12:04 +00:00
|
|
|
assert!(!file_contains!(public, "posts/index.html", "has_prev"));
|
2017-05-03 08:52:49 +00:00
|
|
|
assert!(file_contains!(public, "posts/index.html", "has_next"));
|
2018-10-31 07:18:57 +00:00
|
|
|
assert!(file_contains!(
|
|
|
|
public,
|
|
|
|
"posts/index.html",
|
|
|
|
"First: https://replace-this-with-your-url.com/posts/"
|
|
|
|
));
|
|
|
|
assert!(file_contains!(
|
|
|
|
public,
|
|
|
|
"posts/index.html",
|
2018-11-12 23:08:46 +00:00
|
|
|
"Last: https://replace-this-with-your-url.com/posts/page/5/"
|
2018-10-31 07:18:57 +00:00
|
|
|
));
|
2017-05-03 08:52:49 +00:00
|
|
|
assert_eq!(file_contains!(public, "posts/index.html", "has_prev"), false);
|
|
|
|
|
|
|
|
assert!(file_exists!(public, "posts/page/2/index.html"));
|
2018-11-12 23:08:46 +00:00
|
|
|
assert!(file_contains!(public, "posts/page/2/index.html", "Num pagers: 5"));
|
2017-05-03 08:52:49 +00:00
|
|
|
assert!(file_contains!(public, "posts/page/2/index.html", "Page size: 2"));
|
|
|
|
assert!(file_contains!(public, "posts/page/2/index.html", "Current index: 2"));
|
|
|
|
assert!(file_contains!(public, "posts/page/2/index.html", "has_prev"));
|
2017-05-08 10:29:37 +00:00
|
|
|
assert!(file_contains!(public, "posts/page/2/index.html", "has_next"));
|
2018-10-31 07:18:57 +00:00
|
|
|
assert!(file_contains!(
|
|
|
|
public,
|
|
|
|
"posts/page/2/index.html",
|
|
|
|
"First: https://replace-this-with-your-url.com/posts/"
|
|
|
|
));
|
|
|
|
assert!(file_contains!(
|
|
|
|
public,
|
|
|
|
"posts/page/2/index.html",
|
2018-11-12 23:08:46 +00:00
|
|
|
"Last: https://replace-this-with-your-url.com/posts/page/5/"
|
2018-10-31 07:18:57 +00:00
|
|
|
));
|
2018-08-14 07:12:04 +00:00
|
|
|
|
|
|
|
assert!(file_exists!(public, "posts/page/3/index.html"));
|
2018-11-12 23:08:46 +00:00
|
|
|
assert!(file_contains!(public, "posts/page/3/index.html", "Num pagers: 5"));
|
2018-08-14 07:12:04 +00:00
|
|
|
assert!(file_contains!(public, "posts/page/3/index.html", "Page size: 2"));
|
|
|
|
assert!(file_contains!(public, "posts/page/3/index.html", "Current index: 3"));
|
|
|
|
assert!(file_contains!(public, "posts/page/3/index.html", "has_prev"));
|
|
|
|
assert!(file_contains!(public, "posts/page/3/index.html", "has_next"));
|
2018-10-31 07:18:57 +00:00
|
|
|
assert!(file_contains!(
|
|
|
|
public,
|
|
|
|
"posts/page/3/index.html",
|
|
|
|
"First: https://replace-this-with-your-url.com/posts/"
|
|
|
|
));
|
|
|
|
assert!(file_contains!(
|
|
|
|
public,
|
|
|
|
"posts/page/3/index.html",
|
2018-11-12 23:08:46 +00:00
|
|
|
"Last: https://replace-this-with-your-url.com/posts/page/5/"
|
2018-10-31 07:18:57 +00:00
|
|
|
));
|
2018-08-14 07:12:04 +00:00
|
|
|
|
|
|
|
assert!(file_exists!(public, "posts/page/4/index.html"));
|
2018-11-12 23:08:46 +00:00
|
|
|
assert!(file_contains!(public, "posts/page/4/index.html", "Num pagers: 5"));
|
2018-08-14 07:12:04 +00:00
|
|
|
assert!(file_contains!(public, "posts/page/4/index.html", "Page size: 2"));
|
|
|
|
assert!(file_contains!(public, "posts/page/4/index.html", "Current index: 4"));
|
|
|
|
assert!(file_contains!(public, "posts/page/4/index.html", "has_prev"));
|
2018-11-12 23:08:46 +00:00
|
|
|
assert!(file_contains!(public, "posts/page/4/index.html", "has_next"));
|
2018-10-31 07:18:57 +00:00
|
|
|
assert!(file_contains!(
|
|
|
|
public,
|
|
|
|
"posts/page/4/index.html",
|
|
|
|
"First: https://replace-this-with-your-url.com/posts/"
|
|
|
|
));
|
|
|
|
assert!(file_contains!(
|
|
|
|
public,
|
|
|
|
"posts/page/4/index.html",
|
2018-11-12 23:08:46 +00:00
|
|
|
"Last: https://replace-this-with-your-url.com/posts/page/5/"
|
2018-10-31 07:18:57 +00:00
|
|
|
));
|
2018-11-29 20:48:02 +00:00
|
|
|
|
|
|
|
// sitemap contains the pager pages
|
|
|
|
assert!(file_contains!(
|
|
|
|
public,
|
|
|
|
"sitemap.xml",
|
|
|
|
"<loc>https://replace-this-with-your-url.com/posts/page/4/</loc>"
|
|
|
|
));
|
2017-05-03 08:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2017-05-15 10:53:39 +00:00
|
|
|
fn can_build_site_with_pagination_for_index() {
|
2018-12-28 16:30:47 +00:00
|
|
|
let (_, _tmp_dir, public) = build_site_with_setup("test_site", |mut site| {
|
|
|
|
site.load().unwrap();
|
|
|
|
{
|
2018-12-29 10:17:43 +00:00
|
|
|
let index = site
|
|
|
|
.library
|
|
|
|
.get_section_mut(&site.base_path.join("content").join("_index.md"))
|
|
|
|
.unwrap();
|
2018-12-28 16:30:47 +00:00
|
|
|
index.meta.paginate_by = Some(2);
|
|
|
|
index.meta.template = Some("index_paginated.html".to_string());
|
|
|
|
}
|
|
|
|
(site, false)
|
|
|
|
});
|
2017-05-03 08:52:49 +00:00
|
|
|
|
2018-12-28 16:30:47 +00:00
|
|
|
assert!(&public.exists());
|
2017-05-03 08:52:49 +00:00
|
|
|
|
|
|
|
assert!(file_exists!(public, "index.html"));
|
|
|
|
assert!(file_exists!(public, "sitemap.xml"));
|
|
|
|
assert!(file_exists!(public, "robots.txt"));
|
|
|
|
assert!(file_exists!(public, "a-fixed-url/index.html"));
|
|
|
|
assert!(file_exists!(public, "posts/python/index.html"));
|
|
|
|
assert!(file_exists!(public, "posts/tutorials/devops/nix/index.html"));
|
|
|
|
assert!(file_exists!(public, "posts/with-assets/index.html"));
|
|
|
|
|
|
|
|
// And pagination!
|
|
|
|
assert!(file_exists!(public, "page/1/index.html"));
|
2017-05-12 11:24:44 +00:00
|
|
|
// even if there is no pages, only the section!
|
|
|
|
assert!(file_exists!(public, "paginated/page/1/index.html"));
|
|
|
|
assert!(file_exists!(public, "paginated/index.html"));
|
2017-05-03 08:52:49 +00:00
|
|
|
// should redirect to index
|
|
|
|
assert!(file_contains!(
|
|
|
|
public,
|
|
|
|
"page/1/index.html",
|
|
|
|
"http-equiv=\"refresh\" content=\"0;url=https://replace-this-with-your-url.com/\""
|
|
|
|
));
|
2017-05-08 10:29:37 +00:00
|
|
|
assert!(file_contains!(public, "index.html", "Num pages: 1"));
|
2017-05-03 08:52:49 +00:00
|
|
|
assert!(file_contains!(public, "index.html", "Current index: 1"));
|
|
|
|
assert!(file_contains!(public, "index.html", "First: https://replace-this-with-your-url.com/"));
|
2017-05-08 10:29:37 +00:00
|
|
|
assert!(file_contains!(public, "index.html", "Last: https://replace-this-with-your-url.com/"));
|
2017-05-03 08:52:49 +00:00
|
|
|
assert_eq!(file_contains!(public, "index.html", "has_prev"), false);
|
2017-05-08 10:29:37 +00:00
|
|
|
assert_eq!(file_contains!(public, "index.html", "has_next"), false);
|
2018-11-29 20:48:02 +00:00
|
|
|
|
|
|
|
// sitemap contains the pager pages
|
|
|
|
assert!(file_contains!(
|
|
|
|
public,
|
|
|
|
"sitemap.xml",
|
|
|
|
"<loc>https://replace-this-with-your-url.com/page/1/</loc>"
|
|
|
|
))
|
2017-05-03 08:52:49 +00:00
|
|
|
}
|
2017-07-15 03:51:32 +00:00
|
|
|
|
2018-11-29 19:24:45 +00:00
|
|
|
#[test]
|
|
|
|
fn can_build_site_with_pagination_for_taxonomy() {
|
2018-12-28 16:30:47 +00:00
|
|
|
let (_, _tmp_dir, public) = build_site_with_setup("test_site", |mut site| {
|
|
|
|
site.config.taxonomies.push(Taxonomy {
|
|
|
|
name: "tags".to_string(),
|
|
|
|
paginate_by: Some(2),
|
|
|
|
paginate_path: None,
|
|
|
|
rss: true,
|
2019-01-07 20:03:34 +00:00
|
|
|
lang: None,
|
2018-12-28 16:30:47 +00:00
|
|
|
});
|
|
|
|
site.load().unwrap();
|
|
|
|
|
|
|
|
for (i, (_, page)) in site.library.pages_mut().iter_mut().enumerate() {
|
|
|
|
page.meta.taxonomies = {
|
|
|
|
let mut taxonomies = HashMap::new();
|
2018-12-29 10:17:43 +00:00
|
|
|
taxonomies.insert(
|
|
|
|
"tags".to_string(),
|
|
|
|
vec![if i % 2 == 0 { "A" } else { "B" }.to_string()],
|
|
|
|
);
|
2018-12-28 16:30:47 +00:00
|
|
|
taxonomies
|
|
|
|
};
|
|
|
|
}
|
|
|
|
site.populate_taxonomies().unwrap();
|
|
|
|
(site, false)
|
2018-11-29 19:24:45 +00:00
|
|
|
});
|
|
|
|
|
2018-12-28 16:30:47 +00:00
|
|
|
assert!(&public.exists());
|
2018-11-29 19:24:45 +00:00
|
|
|
|
|
|
|
assert!(file_exists!(public, "index.html"));
|
|
|
|
assert!(file_exists!(public, "sitemap.xml"));
|
|
|
|
assert!(file_exists!(public, "robots.txt"));
|
|
|
|
assert!(file_exists!(public, "a-fixed-url/index.html"));
|
|
|
|
assert!(file_exists!(public, "posts/python/index.html"));
|
|
|
|
assert!(file_exists!(public, "posts/tutorials/devops/nix/index.html"));
|
|
|
|
assert!(file_exists!(public, "posts/with-assets/index.html"));
|
|
|
|
|
|
|
|
// Tags
|
|
|
|
assert!(file_exists!(public, "tags/index.html"));
|
|
|
|
// With RSS
|
|
|
|
assert!(file_exists!(public, "tags/a/rss.xml"));
|
|
|
|
assert!(file_exists!(public, "tags/b/rss.xml"));
|
|
|
|
// And pagination!
|
2018-11-29 20:48:02 +00:00
|
|
|
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"));
|
2018-11-29 19:24:45 +00:00
|
|
|
|
|
|
|
// should redirect to posts/
|
|
|
|
assert!(file_contains!(
|
|
|
|
public,
|
2018-11-29 20:48:02 +00:00
|
|
|
"tags/a/page/1/index.html",
|
2018-11-29 19:24:45 +00:00
|
|
|
"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", "Page size: 2"));
|
|
|
|
assert!(file_contains!(public, "tags/a/index.html", "Current index: 1"));
|
|
|
|
assert!(!file_contains!(public, "tags/a/index.html", "has_prev"));
|
|
|
|
assert!(file_contains!(public, "tags/a/index.html", "has_next"));
|
|
|
|
assert!(file_contains!(
|
|
|
|
public,
|
|
|
|
"tags/a/index.html",
|
|
|
|
"First: https://replace-this-with-your-url.com/tags/a/"
|
|
|
|
));
|
|
|
|
assert!(file_contains!(
|
|
|
|
public,
|
|
|
|
"tags/a/index.html",
|
2018-11-29 20:48:02 +00:00
|
|
|
"Last: https://replace-this-with-your-url.com/tags/a/page/6/"
|
2018-11-29 19:24:45 +00:00
|
|
|
));
|
|
|
|
assert_eq!(file_contains!(public, "tags/a/index.html", "has_prev"), false);
|
2018-11-29 20:48:02 +00:00
|
|
|
|
|
|
|
// sitemap contains the pager pages
|
|
|
|
assert!(file_contains!(
|
|
|
|
public,
|
|
|
|
"sitemap.xml",
|
|
|
|
"<loc>https://replace-this-with-your-url.com/tags/a/page/6/</loc>"
|
|
|
|
))
|
2018-11-29 19:24:45 +00:00
|
|
|
}
|
|
|
|
|
2017-07-15 03:51:32 +00:00
|
|
|
#[test]
|
|
|
|
fn can_build_rss_feed() {
|
2018-12-28 16:30:47 +00:00
|
|
|
let (_, _tmp_dir, public) = build_site("test_site");
|
2017-07-15 03:51:32 +00:00
|
|
|
|
2018-12-28 16:30:47 +00:00
|
|
|
assert!(&public.exists());
|
2017-07-15 03:51:32 +00:00
|
|
|
assert!(file_exists!(public, "rss.xml"));
|
2018-08-14 07:12:04 +00:00
|
|
|
// latest article is posts/extra-syntax.md
|
|
|
|
assert!(file_contains!(public, "rss.xml", "Extra Syntax"));
|
|
|
|
// Next is posts/simple.md
|
2017-07-15 03:51:32 +00:00
|
|
|
assert!(file_contains!(public, "rss.xml", "Simple article with shortcodes"));
|
|
|
|
}
|
2018-03-14 21:03:06 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn can_build_search_index() {
|
2018-12-28 16:30:47 +00:00
|
|
|
let (_, _tmp_dir, public) = build_site_with_setup("test_site", |mut site| {
|
|
|
|
site.config.build_search_index = true;
|
|
|
|
(site, true)
|
|
|
|
});
|
2018-03-15 17:58:32 +00:00
|
|
|
|
|
|
|
assert!(Path::new(&public).exists());
|
|
|
|
assert!(file_exists!(public, "elasticlunr.min.js"));
|
2018-03-20 22:08:20 +00:00
|
|
|
assert!(file_exists!(public, "search_index.en.js"));
|
2018-03-14 21:03:06 +00:00
|
|
|
}
|
2018-08-14 07:12:04 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn can_build_with_extra_syntaxes() {
|
2018-12-28 16:30:47 +00:00
|
|
|
let (_, _tmp_dir, public) = build_site("test_site");
|
2018-08-14 07:12:04 +00:00
|
|
|
|
|
|
|
assert!(&public.exists());
|
|
|
|
assert!(file_exists!(public, "posts/extra-syntax/index.html"));
|
2018-10-31 07:18:57 +00:00
|
|
|
assert!(file_contains!(
|
|
|
|
public,
|
|
|
|
"posts/extra-syntax/index.html",
|
|
|
|
r#"<span style="color:#d08770;">test</span>"#
|
|
|
|
));
|
2018-08-14 07:12:04 +00:00
|
|
|
}
|
2018-11-07 18:42:15 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn can_apply_page_templates() {
|
|
|
|
let mut path = env::current_dir().unwrap().parent().unwrap().parent().unwrap().to_path_buf();
|
|
|
|
path.push("test_site");
|
|
|
|
let mut site = Site::new(&path, "config.toml").unwrap();
|
|
|
|
site.load().unwrap();
|
|
|
|
|
|
|
|
let template_path = path.join("content").join("applying_page_template");
|
|
|
|
|
|
|
|
let template_section = site.library.get_section(&template_path.join("_index.md")).unwrap();
|
2018-11-07 19:48:39 +00:00
|
|
|
assert_eq!(template_section.subsections.len(), 2);
|
2018-11-07 18:42:15 +00:00
|
|
|
assert_eq!(template_section.pages.len(), 2);
|
|
|
|
|
|
|
|
let from_section_config = site.library.get_page_by_key(template_section.pages[0]);
|
|
|
|
assert_eq!(from_section_config.meta.template, Some("page_template.html".into()));
|
|
|
|
assert_eq!(from_section_config.meta.title, Some("From section config".into()));
|
|
|
|
|
|
|
|
let override_page_template = site.library.get_page_by_key(template_section.pages[1]);
|
|
|
|
assert_eq!(override_page_template.meta.template, Some("page_template_override.html".into()));
|
|
|
|
assert_eq!(override_page_template.meta.title, Some("Override".into()));
|
|
|
|
|
|
|
|
// It should have applied recursively as well
|
2018-11-14 16:34:21 +00:00
|
|
|
let another_section =
|
|
|
|
site.library.get_section(&template_path.join("another_section").join("_index.md")).unwrap();
|
2018-11-07 18:42:15 +00:00
|
|
|
assert_eq!(another_section.subsections.len(), 0);
|
|
|
|
assert_eq!(another_section.pages.len(), 1);
|
|
|
|
|
|
|
|
let changed_recursively = site.library.get_page_by_key(another_section.pages[0]);
|
|
|
|
assert_eq!(changed_recursively.meta.template, Some("page_template.html".into()));
|
|
|
|
assert_eq!(changed_recursively.meta.title, Some("Changed recursively".into()));
|
2018-11-07 19:48:39 +00:00
|
|
|
|
|
|
|
// But it should not have override a children page_template
|
2018-11-14 16:34:21 +00:00
|
|
|
let yet_another_section = site
|
|
|
|
.library
|
|
|
|
.get_section(&template_path.join("yet_another_section").join("_index.md"))
|
|
|
|
.unwrap();
|
2018-11-07 19:48:39 +00:00
|
|
|
assert_eq!(yet_another_section.subsections.len(), 0);
|
|
|
|
assert_eq!(yet_another_section.pages.len(), 1);
|
|
|
|
|
|
|
|
let child = site.library.get_page_by_key(yet_another_section.pages[0]);
|
|
|
|
assert_eq!(child.meta.template, Some("page_template_child.html".into()));
|
|
|
|
assert_eq!(child.meta.title, Some("Local section override".into()));
|
2018-11-07 18:42:15 +00:00
|
|
|
}
|