zola/components/site/tests/site.rs

788 lines
30 KiB
Rust
Raw Normal View History

mod common;
2018-07-16 08:54:05 +00:00
use std::collections::HashMap;
use std::env;
2018-10-31 07:18:57 +00:00
use std::path::Path;
2018-12-29 10:17:43 +00:00
use common::{build_site, build_site_with_setup};
use config::Taxonomy;
2019-11-26 19:36:52 +00:00
use site::sitemap;
2017-07-01 07:47:41 +00:00
use site::Site;
#[test]
fn can_parse_site() {
let mut path = env::current_dir().unwrap().parent().unwrap().parent().unwrap().to_path_buf();
path.push("test_site");
let config_file = path.join("config.toml");
let mut site = Site::new(&path, &config_file).unwrap();
2017-03-21 07:57:00 +00:00
site.load().unwrap();
2019-01-27 17:57:07 +00:00
let library = site.library.read().unwrap();
// Correct number of pages (sections do not count as pages, draft are ignored)
assert_eq!(library.pages().len(), 32);
let posts_path = path.join("content").join("posts");
// Make sure the page with a url doesn't have any sections
2019-01-27 17:57:07 +00:00
let url_post = library.get_page(&posts_path.join("fixed-url.md")).unwrap();
assert_eq!(url_post.path, "/a-fixed-url/");
// 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 =
2019-01-27 17:57:07 +00:00
library.get_page(&posts_path.join("with-assets").join("index.md")).unwrap();
assert_eq!(asset_folder_post.file.components, vec!["posts".to_string()]);
// That we have the right number of sections
assert_eq!(library.sections().len(), 12);
// And that the sections are correct
2019-01-27 17:57:07 +00:00
let index_section = library.get_section(&path.join("content").join("_index.md")).unwrap();
assert_eq!(index_section.subsections.len(), 5);
assert_eq!(index_section.pages.len(), 3);
assert!(index_section.ancestors.is_empty());
2017-05-08 10:29:37 +00:00
2019-01-27 17:57:07 +00:00
let posts_section = library.get_section(&posts_path.join("_index.md")).unwrap();
assert_eq!(posts_section.subsections.len(), 2);
2019-07-19 09:10:28 +00:00
assert_eq!(posts_section.pages.len(), 9); // 10 with 1 draft == 9
2018-10-31 07:18:57 +00:00
assert_eq!(
posts_section.ancestors,
2019-01-27 17:57:07 +00:00
vec![*library.get_section_key(&index_section.file.path).unwrap()]
2018-10-31 07:18:57 +00:00
);
// Make sure we remove all the pwd + content from the sections
2019-01-27 17:57:07 +00:00
let basic = library.get_page(&posts_path.join("simple.md")).unwrap();
assert_eq!(basic.file.components, vec!["posts".to_string()]);
assert_eq!(
basic.ancestors,
vec![
2019-01-27 17:57:07 +00:00
*library.get_section_key(&index_section.file.path).unwrap(),
*library.get_section_key(&posts_section.file.path).unwrap(),
]
);
2018-10-31 07:18:57 +00:00
let tutorials_section =
2019-01-27 17:57:07 +00:00
library.get_section(&posts_path.join("tutorials").join("_index.md")).unwrap();
assert_eq!(tutorials_section.subsections.len(), 2);
2019-01-27 17:57:07 +00:00
let sub1 = library.get_section_by_key(tutorials_section.subsections[0]);
let sub2 = library.get_section_by_key(tutorials_section.subsections[1]);
2018-10-02 14:42:34 +00:00
assert_eq!(sub1.clone().meta.title.unwrap(), "Programming");
assert_eq!(sub2.clone().meta.title.unwrap(), "DevOps");
assert_eq!(tutorials_section.pages.len(), 0);
2019-01-27 17:57:07 +00:00
let devops_section = library
2018-10-31 07:18:57 +00:00
.get_section(&posts_path.join("tutorials").join("devops").join("_index.md"))
.unwrap();
assert_eq!(devops_section.subsections.len(), 0);
assert_eq!(devops_section.pages.len(), 2);
assert_eq!(
devops_section.ancestors,
vec![
2019-01-27 17:57:07 +00:00
*library.get_section_key(&index_section.file.path).unwrap(),
*library.get_section_key(&posts_section.file.path).unwrap(),
*library.get_section_key(&tutorials_section.file.path).unwrap(),
]
);
2019-01-27 17:57:07 +00:00
let prog_section = library
2018-10-31 07:18:57 +00:00
.get_section(&posts_path.join("tutorials").join("programming").join("_index.md"))
.unwrap();
assert_eq!(prog_section.subsections.len(), 0);
assert_eq!(prog_section.pages.len(), 2);
2019-11-26 19:36:52 +00:00
// Testing extra variables in sections & sitemaps
// Regression test for #https://github.com/getzola/zola/issues/842
assert_eq!(
prog_section.meta.extra.get("we_have_extra").and_then(|s| s.as_str()),
Some("variables")
);
let sitemap_entries = sitemap::find_entries(&library, &site.taxonomies[..], &site.config);
let sitemap_entry = sitemap_entries
.iter()
.find(|e| e.permalink.ends_with("tutorials/programming/"))
.expect("expected to find programming section in sitemap");
assert_eq!(Some(&prog_section.meta.extra), sitemap_entry.extra);
}
#[test]
fn can_build_site_without_live_reload() {
let (_, _tmp_dir, public) = build_site("test_site");
assert!(&public.exists());
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"));
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"));
assert!(file_contains!(public, "posts/python/index.html", "Arrrh Bob_Sponge"));
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"));
// 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"));
// Ensure subsection pages are correctly filled
assert!(file_contains!(public, "posts/tutorials/index.html", "Sub-pages: 2"));
// 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-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"));
2019-06-02 18:21:06 +00:00
assert!(file_contains!(public, "another-old-url/index.html", "posts/"));
2017-06-16 14:09:01 +00:00
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"));
// 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);
Support and default to generating Atom feeds This includes several breaking changes, but they’re easy to adjust for. Atom 1.0 is superior to RSS 2.0 in a number of ways, both technical and legal, though information from the last decade is hard to find. http://www.intertwingly.net/wiki/pie/Rss20AndAtom10Compared has some info which is probably still mostly correct. How do RSS and Atom compare in terms of implementation support? The impression I get is that proper Atom support in normal content websites has been universal for over twelve years, but that support in podcasts was not quite so good, but getting there, over twelve years ago. I have no more recent facts or figures; no one talks about this stuff these days. I remember investigating this stuff back in 2011–2013 and coming to the same conclusion. At that time, I went with Atom on websites and RSS in podcasts. Now I’d just go full Atom and hang any podcast tools that don’t support Atom, because Atom’s semantics truly are much better. In light of all this, I make the bold recommendation to default to Atom. Nonetheless, for compatibility for existing users, and for those that have Opinions, I’ve retained the RSS template, so that you can escape the breaking change easily. I personally prefer to give feeds a basename that doesn’t mention “Atom” or “RSS”, e.g. “feed.xml”. I’ll be doing that myself, as I’ll be using my own template with more Atom features anyway, like author information, taxonomies and making the title field HTML. Some notes about the Atom feed template: - I went with atom.xml rather than something like feed.atom (the .atom file format being registered for this purpose by RFC4287) due to lack of confidence that it’ll be served with the right MIME type. .xml is a safer default. - It might be nice to get Zola’s version number into the <generator> tag. Not for any particularly good reason, y’know. Just picture it: <generator uri="https://www.getzola.org/" version="0.10.0"> Zola </generator> - I’d like to get taxonomies into the feed, but this requires exposing a little more info than is currently exposed. I think it’d require `TaxonomyConfig` to preferably have a new member `permalink` added (which should be equivalent to something like `config.base_url ~ "/" ~ taxonomy.slug ~ "/"`), and for the feed to get all the taxonomies passed into it (`taxonomies: HashMap<String, TaxonomyTerm>`). Then, the template could be like this, inside the entry: {% for taxonomy, terms in page.taxonomies %} {% for term in terms %} <category scheme="{{ taxonomies[taxonomy].permalink }}" term="{{ term.slug }}" label="{{ term.name }}" /> {% endfor %} {% endfor %} Other remarks: - I have added a date field `extra.updated` to my posts and include that in the feed; I’ve observed others with a similar field. I believe this should be included as an official field. I’m inclined to add author to at least config.toml, too, for feeds. - We need to have a link from the docs to the source of the built-in templates, to help people that wish to alter it.
2019-08-11 10:25:24 +00:00
assert_eq!(file_exists!(public, "categories/a-category/atom.xml"), true);
// and podcast_authors (https://github.com/getzola/zola/issues/1177)
assert_eq!(file_exists!(public, "podcast-authors/index.html"), true);
assert_eq!(file_exists!(public, "podcast-authors/some-person/index.html"), true);
assert_eq!(file_exists!(public, "podcast-authors/some-person/atom.xml"), true);
2018-11-16 22:51:11 +00:00
// But no tags
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"));
// 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"));
assert!(file_exists!(public, "sass.css"));
assert!(file_exists!(public, "nested_sass/sass.css"));
assert!(file_exists!(public, "nested_sass/scss.css"));
assert!(!file_exists!(public, "secret_section/index.html"));
assert!(!file_exists!(public, "secret_section/page.html"));
assert!(!file_exists!(public, "secret_section/secret_sub_section/hello.html"));
// no live reload code
assert_eq!(
file_contains!(public, "index.html", "/livereload.js?port=1112&amp;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",
2019-08-04 14:13:07 +00:00
"<loc>https://replace-this-with-your-url.com/posts/simple/</loc>"
2018-10-31 07:18:57 +00:00
));
assert!(file_contains!(
public,
"sitemap.xml",
2019-08-04 14:13:07 +00:00
"<loc>https://replace-this-with-your-url.com/posts/</loc>"
2018-10-31 07:18:57 +00:00
));
2017-09-25 09:55:43 +00:00
// Drafts are not in the sitemap
assert!(!file_contains!(public, "sitemap.xml", "draft"));
// render: false sections are not in the sitemap either
assert!(!file_contains!(public, "sitemap.xml", "posts/2018/</loc>"));
// robots.txt has been rendered from the template
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"
));
}
#[test]
2019-08-24 20:23:08 +00:00
fn can_build_site_with_live_reload_and_drafts() {
let (site, _tmp_dir, public) = build_site_with_setup("test_site", |mut site| {
site.enable_live_reload(1000);
2019-08-24 20:23:08 +00:00
site.include_drafts();
(site, true)
});
assert!(&public.exists());
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"));
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);
Support and default to generating Atom feeds This includes several breaking changes, but they’re easy to adjust for. Atom 1.0 is superior to RSS 2.0 in a number of ways, both technical and legal, though information from the last decade is hard to find. http://www.intertwingly.net/wiki/pie/Rss20AndAtom10Compared has some info which is probably still mostly correct. How do RSS and Atom compare in terms of implementation support? The impression I get is that proper Atom support in normal content websites has been universal for over twelve years, but that support in podcasts was not quite so good, but getting there, over twelve years ago. I have no more recent facts or figures; no one talks about this stuff these days. I remember investigating this stuff back in 2011–2013 and coming to the same conclusion. At that time, I went with Atom on websites and RSS in podcasts. Now I’d just go full Atom and hang any podcast tools that don’t support Atom, because Atom’s semantics truly are much better. In light of all this, I make the bold recommendation to default to Atom. Nonetheless, for compatibility for existing users, and for those that have Opinions, I’ve retained the RSS template, so that you can escape the breaking change easily. I personally prefer to give feeds a basename that doesn’t mention “Atom” or “RSS”, e.g. “feed.xml”. I’ll be doing that myself, as I’ll be using my own template with more Atom features anyway, like author information, taxonomies and making the title field HTML. Some notes about the Atom feed template: - I went with atom.xml rather than something like feed.atom (the .atom file format being registered for this purpose by RFC4287) due to lack of confidence that it’ll be served with the right MIME type. .xml is a safer default. - It might be nice to get Zola’s version number into the <generator> tag. Not for any particularly good reason, y’know. Just picture it: <generator uri="https://www.getzola.org/" version="0.10.0"> Zola </generator> - I’d like to get taxonomies into the feed, but this requires exposing a little more info than is currently exposed. I think it’d require `TaxonomyConfig` to preferably have a new member `permalink` added (which should be equivalent to something like `config.base_url ~ "/" ~ taxonomy.slug ~ "/"`), and for the feed to get all the taxonomies passed into it (`taxonomies: HashMap<String, TaxonomyTerm>`). Then, the template could be like this, inside the entry: {% for taxonomy, terms in page.taxonomies %} {% for term in terms %} <category scheme="{{ taxonomies[taxonomy].permalink }}" term="{{ term.slug }}" label="{{ term.name }}" /> {% endfor %} {% endfor %} Other remarks: - I have added a date field `extra.updated` to my posts and include that in the feed; I’ve observed others with a similar field. I believe this should be included as an official field. I’m inclined to add author to at least config.toml, too, for feeds. - We need to have a link from the docs to the source of the built-in templates, to help people that wish to alter it.
2019-08-11 10:25:24 +00:00
assert_eq!(file_exists!(public, "categories/a-category/atom.xml"), true);
2018-11-16 22:51:11 +00:00
// But no tags
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"));
// the summary target has been created
2018-10-31 07:18:57 +00:00
assert!(file_contains!(
public,
"posts/python/index.html",
r#"<span id="continue-reading"></span>"#
2018-10-31 07:18:57 +00:00
));
2019-08-24 20:23:08 +00:00
// Drafts are included
assert!(file_exists!(public, "posts/draft/index.html"));
assert!(file_contains!(public, "sitemap.xml", "draft"));
// drafted sections are included
let library = site.library.read().unwrap();
assert_eq!(library.sections().len(), 14);
assert!(file_exists!(public, "secret_section/index.html"));
assert!(file_exists!(public, "secret_section/draft-page/index.html"));
assert!(file_exists!(public, "secret_section/page/index.html"));
assert!(file_exists!(public, "secret_section/secret_sub_section/hello/index.html"));
}
#[test]
2018-07-16 08:54:05 +00:00
fn can_build_site_with_taxonomies() {
let (site, _tmp_dir, public) = build_site_with_setup("test_site", |mut site| {
site.load().unwrap();
2019-01-27 17:57:07 +00:00
{
let mut library = site.library.write().unwrap();
for (i, (_, page)) in 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
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"));
Support and default to generating Atom feeds This includes several breaking changes, but they’re easy to adjust for. Atom 1.0 is superior to RSS 2.0 in a number of ways, both technical and legal, though information from the last decade is hard to find. http://www.intertwingly.net/wiki/pie/Rss20AndAtom10Compared has some info which is probably still mostly correct. How do RSS and Atom compare in terms of implementation support? The impression I get is that proper Atom support in normal content websites has been universal for over twelve years, but that support in podcasts was not quite so good, but getting there, over twelve years ago. I have no more recent facts or figures; no one talks about this stuff these days. I remember investigating this stuff back in 2011–2013 and coming to the same conclusion. At that time, I went with Atom on websites and RSS in podcasts. Now I’d just go full Atom and hang any podcast tools that don’t support Atom, because Atom’s semantics truly are much better. In light of all this, I make the bold recommendation to default to Atom. Nonetheless, for compatibility for existing users, and for those that have Opinions, I’ve retained the RSS template, so that you can escape the breaking change easily. I personally prefer to give feeds a basename that doesn’t mention “Atom” or “RSS”, e.g. “feed.xml”. I’ll be doing that myself, as I’ll be using my own template with more Atom features anyway, like author information, taxonomies and making the title field HTML. Some notes about the Atom feed template: - I went with atom.xml rather than something like feed.atom (the .atom file format being registered for this purpose by RFC4287) due to lack of confidence that it’ll be served with the right MIME type. .xml is a safer default. - It might be nice to get Zola’s version number into the <generator> tag. Not for any particularly good reason, y’know. Just picture it: <generator uri="https://www.getzola.org/" version="0.10.0"> Zola </generator> - I’d like to get taxonomies into the feed, but this requires exposing a little more info than is currently exposed. I think it’d require `TaxonomyConfig` to preferably have a new member `permalink` added (which should be equivalent to something like `config.base_url ~ "/" ~ taxonomy.slug ~ "/"`), and for the feed to get all the taxonomies passed into it (`taxonomies: HashMap<String, TaxonomyTerm>`). Then, the template could be like this, inside the entry: {% for taxonomy, terms in page.taxonomies %} {% for term in terms %} <category scheme="{{ taxonomies[taxonomy].permalink }}" term="{{ term.slug }}" label="{{ term.name }}" /> {% endfor %} {% endfor %} Other remarks: - I have added a date field `extra.updated` to my posts and include that in the feed; I’ve observed others with a similar field. I believe this should be included as an official field. I’m inclined to add author to at least config.toml, too, for feeds. - We need to have a link from the docs to the source of the built-in templates, to help people that wish to alter it.
2019-08-11 10:25:24 +00:00
assert!(file_exists!(public, "categories/a/atom.xml"));
2018-10-31 07:18:57 +00:00
assert!(file_contains!(
public,
Support and default to generating Atom feeds This includes several breaking changes, but they’re easy to adjust for. Atom 1.0 is superior to RSS 2.0 in a number of ways, both technical and legal, though information from the last decade is hard to find. http://www.intertwingly.net/wiki/pie/Rss20AndAtom10Compared has some info which is probably still mostly correct. How do RSS and Atom compare in terms of implementation support? The impression I get is that proper Atom support in normal content websites has been universal for over twelve years, but that support in podcasts was not quite so good, but getting there, over twelve years ago. I have no more recent facts or figures; no one talks about this stuff these days. I remember investigating this stuff back in 2011–2013 and coming to the same conclusion. At that time, I went with Atom on websites and RSS in podcasts. Now I’d just go full Atom and hang any podcast tools that don’t support Atom, because Atom’s semantics truly are much better. In light of all this, I make the bold recommendation to default to Atom. Nonetheless, for compatibility for existing users, and for those that have Opinions, I’ve retained the RSS template, so that you can escape the breaking change easily. I personally prefer to give feeds a basename that doesn’t mention “Atom” or “RSS”, e.g. “feed.xml”. I’ll be doing that myself, as I’ll be using my own template with more Atom features anyway, like author information, taxonomies and making the title field HTML. Some notes about the Atom feed template: - I went with atom.xml rather than something like feed.atom (the .atom file format being registered for this purpose by RFC4287) due to lack of confidence that it’ll be served with the right MIME type. .xml is a safer default. - It might be nice to get Zola’s version number into the <generator> tag. Not for any particularly good reason, y’know. Just picture it: <generator uri="https://www.getzola.org/" version="0.10.0"> Zola </generator> - I’d like to get taxonomies into the feed, but this requires exposing a little more info than is currently exposed. I think it’d require `TaxonomyConfig` to preferably have a new member `permalink` added (which should be equivalent to something like `config.base_url ~ "/" ~ taxonomy.slug ~ "/"`), and for the feed to get all the taxonomies passed into it (`taxonomies: HashMap<String, TaxonomyTerm>`). Then, the template could be like this, inside the entry: {% for taxonomy, terms in page.taxonomies %} {% for term in terms %} <category scheme="{{ taxonomies[taxonomy].permalink }}" term="{{ term.slug }}" label="{{ term.name }}" /> {% endfor %} {% endfor %} Other remarks: - I have added a date field `extra.updated` to my posts and include that in the feed; I’ve observed others with a similar field. I believe this should be included as an official field. I’m inclined to add author to at least config.toml, too, for feeds. - We need to have a link from the docs to the source of the built-in templates, to help people that wish to alter it.
2019-08-11 10:25:24 +00:00
"categories/a/atom.xml",
"https://replace-this-with-your-url.com/categories/a/atom.xml"
2018-10-31 07:18:57 +00:00
));
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",
2019-08-04 14:13:07 +00:00
"<loc>https://replace-this-with-your-url.com/categories/</loc>"
2018-10-31 07:18:57 +00:00
));
assert!(file_contains!(
public,
"sitemap.xml",
2019-08-04 14:13:07 +00:00
"<loc>https://replace-this-with-your-url.com/categories/a/</loc>"
2018-10-31 07:18:57 +00:00
));
}
2017-04-10 11:26:35 +00:00
#[test]
fn can_build_site_and_insert_anchor_links() {
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]
fn can_build_site_with_pagination_for_section() {
let (_, _tmp_dir, public) = build_site_with_setup("test_site", |mut site| {
site.load().unwrap();
2019-01-27 17:57:07 +00:00
{
let mut library = site.library.write().unwrap();
for (_, section) in library.sections_mut() {
if section.is_index() {
continue;
}
section.meta.paginate_by = Some(2);
section.meta.template = Some("section_paginated.html".to_string());
}
}
(site, false)
});
2017-05-03 08:52:49 +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"));
// 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",
2020-05-27 20:05:56 +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"));
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
));
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"));
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
));
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"));
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
));
// sitemap contains the pager pages
assert!(file_contains!(
public,
"sitemap.xml",
2019-08-04 14:13:07 +00:00
"<loc>https://replace-this-with-your-url.com/posts/page/4/</loc>"
));
// current_path
assert!(file_contains!(public, "posts/index.html", &current_path("/posts/")));
assert!(file_contains!(public, "posts/page/2/index.html", &current_path("/posts/page/2/")));
assert!(file_contains!(public, "posts/python/index.html", &current_path("/posts/python/")));
assert!(file_contains!(
public,
"posts/tutorials/index.html",
&current_path("/posts/tutorials/")
));
2017-05-03 08:52:49 +00:00
}
#[test]
fn can_build_site_with_pagination_for_index() {
let (_, _tmp_dir, public) = build_site_with_setup("test_site", |mut site| {
site.load().unwrap();
{
2019-01-27 17:57:07 +00:00
let mut library = site.library.write().unwrap();
{
let index = library
.get_section_mut(&site.base_path.join("content").join("_index.md"))
.unwrap();
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
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"));
// 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",
2020-05-27 20:05:56 +00:00
"http-equiv=\"refresh\" content=\"0; url=https://replace-this-with-your-url.com/\""
2017-05-03 08:52:49 +00:00
));
assert!(file_contains!(public, "page/1/index.html", "<title>Redirect</title>"));
assert!(file_contains!(
public,
"page/1/index.html",
"<a href=\"https://replace-this-with-your-url.com/\">Click here</a>"
));
assert!(file_contains!(public, "index.html", "Num pages: 2"));
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/"));
assert!(file_contains!(
public,
"index.html",
"Last: https://replace-this-with-your-url.com/page/2/"
));
2017-05-03 08:52:49 +00:00
assert_eq!(file_contains!(public, "index.html", "has_prev"), false);
assert_eq!(file_contains!(public, "index.html", "has_next"), true);
// sitemap contains the pager pages
assert!(file_contains!(
public,
"sitemap.xml",
2019-08-04 14:13:07 +00:00
"<loc>https://replace-this-with-your-url.com/page/1/</loc>"
));
// current_path
assert!(file_contains!(public, "index.html", &current_path("/")));
assert!(file_contains!(public, "page/2/index.html", &current_path("/page/2/")));
assert!(file_contains!(public, "paginated/index.html", &current_path("/paginated/")));
2017-05-03 08:52:49 +00:00
}
2017-07-15 03:51:32 +00:00
#[test]
fn can_build_site_with_pagination_for_taxonomy() {
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,
Support and default to generating Atom feeds This includes several breaking changes, but they’re easy to adjust for. Atom 1.0 is superior to RSS 2.0 in a number of ways, both technical and legal, though information from the last decade is hard to find. http://www.intertwingly.net/wiki/pie/Rss20AndAtom10Compared has some info which is probably still mostly correct. How do RSS and Atom compare in terms of implementation support? The impression I get is that proper Atom support in normal content websites has been universal for over twelve years, but that support in podcasts was not quite so good, but getting there, over twelve years ago. I have no more recent facts or figures; no one talks about this stuff these days. I remember investigating this stuff back in 2011–2013 and coming to the same conclusion. At that time, I went with Atom on websites and RSS in podcasts. Now I’d just go full Atom and hang any podcast tools that don’t support Atom, because Atom’s semantics truly are much better. In light of all this, I make the bold recommendation to default to Atom. Nonetheless, for compatibility for existing users, and for those that have Opinions, I’ve retained the RSS template, so that you can escape the breaking change easily. I personally prefer to give feeds a basename that doesn’t mention “Atom” or “RSS”, e.g. “feed.xml”. I’ll be doing that myself, as I’ll be using my own template with more Atom features anyway, like author information, taxonomies and making the title field HTML. Some notes about the Atom feed template: - I went with atom.xml rather than something like feed.atom (the .atom file format being registered for this purpose by RFC4287) due to lack of confidence that it’ll be served with the right MIME type. .xml is a safer default. - It might be nice to get Zola’s version number into the <generator> tag. Not for any particularly good reason, y’know. Just picture it: <generator uri="https://www.getzola.org/" version="0.10.0"> Zola </generator> - I’d like to get taxonomies into the feed, but this requires exposing a little more info than is currently exposed. I think it’d require `TaxonomyConfig` to preferably have a new member `permalink` added (which should be equivalent to something like `config.base_url ~ "/" ~ taxonomy.slug ~ "/"`), and for the feed to get all the taxonomies passed into it (`taxonomies: HashMap<String, TaxonomyTerm>`). Then, the template could be like this, inside the entry: {% for taxonomy, terms in page.taxonomies %} {% for term in terms %} <category scheme="{{ taxonomies[taxonomy].permalink }}" term="{{ term.slug }}" label="{{ term.name }}" /> {% endfor %} {% endfor %} Other remarks: - I have added a date field `extra.updated` to my posts and include that in the feed; I’ve observed others with a similar field. I believe this should be included as an official field. I’m inclined to add author to at least config.toml, too, for feeds. - We need to have a link from the docs to the source of the built-in templates, to help people that wish to alter it.
2019-08-11 10:25:24 +00:00
feed: true,
});
site.load().unwrap();
2019-01-27 17:57:07 +00:00
{
let mut library = site.library.write().unwrap();
for (i, (_, page)) in library.pages_mut().iter_mut().enumerate() {
page.meta.taxonomies = {
let mut taxonomies = HashMap::new();
taxonomies.insert(
"tags".to_string(),
vec![if i % 2 == 0 { "A" } else { "B" }.to_string()],
);
taxonomies
};
}
}
site.populate_taxonomies().unwrap();
(site, false)
});
assert!(&public.exists());
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"));
Support and default to generating Atom feeds This includes several breaking changes, but they’re easy to adjust for. Atom 1.0 is superior to RSS 2.0 in a number of ways, both technical and legal, though information from the last decade is hard to find. http://www.intertwingly.net/wiki/pie/Rss20AndAtom10Compared has some info which is probably still mostly correct. How do RSS and Atom compare in terms of implementation support? The impression I get is that proper Atom support in normal content websites has been universal for over twelve years, but that support in podcasts was not quite so good, but getting there, over twelve years ago. I have no more recent facts or figures; no one talks about this stuff these days. I remember investigating this stuff back in 2011–2013 and coming to the same conclusion. At that time, I went with Atom on websites and RSS in podcasts. Now I’d just go full Atom and hang any podcast tools that don’t support Atom, because Atom’s semantics truly are much better. In light of all this, I make the bold recommendation to default to Atom. Nonetheless, for compatibility for existing users, and for those that have Opinions, I’ve retained the RSS template, so that you can escape the breaking change easily. I personally prefer to give feeds a basename that doesn’t mention “Atom” or “RSS”, e.g. “feed.xml”. I’ll be doing that myself, as I’ll be using my own template with more Atom features anyway, like author information, taxonomies and making the title field HTML. Some notes about the Atom feed template: - I went with atom.xml rather than something like feed.atom (the .atom file format being registered for this purpose by RFC4287) due to lack of confidence that it’ll be served with the right MIME type. .xml is a safer default. - It might be nice to get Zola’s version number into the <generator> tag. Not for any particularly good reason, y’know. Just picture it: <generator uri="https://www.getzola.org/" version="0.10.0"> Zola </generator> - I’d like to get taxonomies into the feed, but this requires exposing a little more info than is currently exposed. I think it’d require `TaxonomyConfig` to preferably have a new member `permalink` added (which should be equivalent to something like `config.base_url ~ "/" ~ taxonomy.slug ~ "/"`), and for the feed to get all the taxonomies passed into it (`taxonomies: HashMap<String, TaxonomyTerm>`). Then, the template could be like this, inside the entry: {% for taxonomy, terms in page.taxonomies %} {% for term in terms %} <category scheme="{{ taxonomies[taxonomy].permalink }}" term="{{ term.slug }}" label="{{ term.name }}" /> {% endfor %} {% endfor %} Other remarks: - I have added a date field `extra.updated` to my posts and include that in the feed; I’ve observed others with a similar field. I believe this should be included as an official field. I’m inclined to add author to at least config.toml, too, for feeds. - We need to have a link from the docs to the source of the built-in templates, to help people that wish to alter it.
2019-08-11 10:25:24 +00:00
// With Atom
assert!(file_exists!(public, "tags/a/atom.xml"));
assert!(file_exists!(public, "tags/b/atom.xml"));
// And pagination!
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/
assert!(file_contains!(
public,
"tags/a/page/1/index.html",
2020-05-27 20:05:56 +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: 8"));
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",
"Last: https://replace-this-with-your-url.com/tags/a/page/8/"
));
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/8/</loc>"
));
// current_path
assert!(file_contains!(public, "tags/index.html", &current_path("/tags/")));
assert!(file_contains!(public, "tags/a/index.html", &current_path("/tags/a/")));
assert!(file_contains!(public, "tags/a/page/2/index.html", &current_path("/tags/a/page/2/")));
}
2017-07-15 03:51:32 +00:00
#[test]
fn can_build_feeds() {
let (_, _tmp_dir, public) = build_site("test_site");
2017-07-15 03:51:32 +00:00
assert!(&public.exists());
Support and default to generating Atom feeds This includes several breaking changes, but they’re easy to adjust for. Atom 1.0 is superior to RSS 2.0 in a number of ways, both technical and legal, though information from the last decade is hard to find. http://www.intertwingly.net/wiki/pie/Rss20AndAtom10Compared has some info which is probably still mostly correct. How do RSS and Atom compare in terms of implementation support? The impression I get is that proper Atom support in normal content websites has been universal for over twelve years, but that support in podcasts was not quite so good, but getting there, over twelve years ago. I have no more recent facts or figures; no one talks about this stuff these days. I remember investigating this stuff back in 2011–2013 and coming to the same conclusion. At that time, I went with Atom on websites and RSS in podcasts. Now I’d just go full Atom and hang any podcast tools that don’t support Atom, because Atom’s semantics truly are much better. In light of all this, I make the bold recommendation to default to Atom. Nonetheless, for compatibility for existing users, and for those that have Opinions, I’ve retained the RSS template, so that you can escape the breaking change easily. I personally prefer to give feeds a basename that doesn’t mention “Atom” or “RSS”, e.g. “feed.xml”. I’ll be doing that myself, as I’ll be using my own template with more Atom features anyway, like author information, taxonomies and making the title field HTML. Some notes about the Atom feed template: - I went with atom.xml rather than something like feed.atom (the .atom file format being registered for this purpose by RFC4287) due to lack of confidence that it’ll be served with the right MIME type. .xml is a safer default. - It might be nice to get Zola’s version number into the <generator> tag. Not for any particularly good reason, y’know. Just picture it: <generator uri="https://www.getzola.org/" version="0.10.0"> Zola </generator> - I’d like to get taxonomies into the feed, but this requires exposing a little more info than is currently exposed. I think it’d require `TaxonomyConfig` to preferably have a new member `permalink` added (which should be equivalent to something like `config.base_url ~ "/" ~ taxonomy.slug ~ "/"`), and for the feed to get all the taxonomies passed into it (`taxonomies: HashMap<String, TaxonomyTerm>`). Then, the template could be like this, inside the entry: {% for taxonomy, terms in page.taxonomies %} {% for term in terms %} <category scheme="{{ taxonomies[taxonomy].permalink }}" term="{{ term.slug }}" label="{{ term.name }}" /> {% endfor %} {% endfor %} Other remarks: - I have added a date field `extra.updated` to my posts and include that in the feed; I’ve observed others with a similar field. I believe this should be included as an official field. I’m inclined to add author to at least config.toml, too, for feeds. - We need to have a link from the docs to the source of the built-in templates, to help people that wish to alter it.
2019-08-11 10:25:24 +00:00
assert!(file_exists!(public, "atom.xml"));
// latest article is posts/extra-syntax.md
Support and default to generating Atom feeds This includes several breaking changes, but they’re easy to adjust for. Atom 1.0 is superior to RSS 2.0 in a number of ways, both technical and legal, though information from the last decade is hard to find. http://www.intertwingly.net/wiki/pie/Rss20AndAtom10Compared has some info which is probably still mostly correct. How do RSS and Atom compare in terms of implementation support? The impression I get is that proper Atom support in normal content websites has been universal for over twelve years, but that support in podcasts was not quite so good, but getting there, over twelve years ago. I have no more recent facts or figures; no one talks about this stuff these days. I remember investigating this stuff back in 2011–2013 and coming to the same conclusion. At that time, I went with Atom on websites and RSS in podcasts. Now I’d just go full Atom and hang any podcast tools that don’t support Atom, because Atom’s semantics truly are much better. In light of all this, I make the bold recommendation to default to Atom. Nonetheless, for compatibility for existing users, and for those that have Opinions, I’ve retained the RSS template, so that you can escape the breaking change easily. I personally prefer to give feeds a basename that doesn’t mention “Atom” or “RSS”, e.g. “feed.xml”. I’ll be doing that myself, as I’ll be using my own template with more Atom features anyway, like author information, taxonomies and making the title field HTML. Some notes about the Atom feed template: - I went with atom.xml rather than something like feed.atom (the .atom file format being registered for this purpose by RFC4287) due to lack of confidence that it’ll be served with the right MIME type. .xml is a safer default. - It might be nice to get Zola’s version number into the <generator> tag. Not for any particularly good reason, y’know. Just picture it: <generator uri="https://www.getzola.org/" version="0.10.0"> Zola </generator> - I’d like to get taxonomies into the feed, but this requires exposing a little more info than is currently exposed. I think it’d require `TaxonomyConfig` to preferably have a new member `permalink` added (which should be equivalent to something like `config.base_url ~ "/" ~ taxonomy.slug ~ "/"`), and for the feed to get all the taxonomies passed into it (`taxonomies: HashMap<String, TaxonomyTerm>`). Then, the template could be like this, inside the entry: {% for taxonomy, terms in page.taxonomies %} {% for term in terms %} <category scheme="{{ taxonomies[taxonomy].permalink }}" term="{{ term.slug }}" label="{{ term.name }}" /> {% endfor %} {% endfor %} Other remarks: - I have added a date field `extra.updated` to my posts and include that in the feed; I’ve observed others with a similar field. I believe this should be included as an official field. I’m inclined to add author to at least config.toml, too, for feeds. - We need to have a link from the docs to the source of the built-in templates, to help people that wish to alter it.
2019-08-11 10:25:24 +00:00
assert!(file_contains!(public, "atom.xml", "Extra Syntax"));
// Next is posts/simple.md
Support and default to generating Atom feeds This includes several breaking changes, but they’re easy to adjust for. Atom 1.0 is superior to RSS 2.0 in a number of ways, both technical and legal, though information from the last decade is hard to find. http://www.intertwingly.net/wiki/pie/Rss20AndAtom10Compared has some info which is probably still mostly correct. How do RSS and Atom compare in terms of implementation support? The impression I get is that proper Atom support in normal content websites has been universal for over twelve years, but that support in podcasts was not quite so good, but getting there, over twelve years ago. I have no more recent facts or figures; no one talks about this stuff these days. I remember investigating this stuff back in 2011–2013 and coming to the same conclusion. At that time, I went with Atom on websites and RSS in podcasts. Now I’d just go full Atom and hang any podcast tools that don’t support Atom, because Atom’s semantics truly are much better. In light of all this, I make the bold recommendation to default to Atom. Nonetheless, for compatibility for existing users, and for those that have Opinions, I’ve retained the RSS template, so that you can escape the breaking change easily. I personally prefer to give feeds a basename that doesn’t mention “Atom” or “RSS”, e.g. “feed.xml”. I’ll be doing that myself, as I’ll be using my own template with more Atom features anyway, like author information, taxonomies and making the title field HTML. Some notes about the Atom feed template: - I went with atom.xml rather than something like feed.atom (the .atom file format being registered for this purpose by RFC4287) due to lack of confidence that it’ll be served with the right MIME type. .xml is a safer default. - It might be nice to get Zola’s version number into the <generator> tag. Not for any particularly good reason, y’know. Just picture it: <generator uri="https://www.getzola.org/" version="0.10.0"> Zola </generator> - I’d like to get taxonomies into the feed, but this requires exposing a little more info than is currently exposed. I think it’d require `TaxonomyConfig` to preferably have a new member `permalink` added (which should be equivalent to something like `config.base_url ~ "/" ~ taxonomy.slug ~ "/"`), and for the feed to get all the taxonomies passed into it (`taxonomies: HashMap<String, TaxonomyTerm>`). Then, the template could be like this, inside the entry: {% for taxonomy, terms in page.taxonomies %} {% for term in terms %} <category scheme="{{ taxonomies[taxonomy].permalink }}" term="{{ term.slug }}" label="{{ term.name }}" /> {% endfor %} {% endfor %} Other remarks: - I have added a date field `extra.updated` to my posts and include that in the feed; I’ve observed others with a similar field. I believe this should be included as an official field. I’m inclined to add author to at least config.toml, too, for feeds. - We need to have a link from the docs to the source of the built-in templates, to help people that wish to alter it.
2019-08-11 10:25:24 +00:00
assert!(file_contains!(public, "atom.xml", "Simple article with shortcodes"));
// Test section feeds
assert!(file_exists!(public, "posts/tutorials/programming/atom.xml"));
// It contains both sections articles
assert!(file_contains!(public, "posts/tutorials/programming/atom.xml", "Python tutorial"));
assert!(file_contains!(public, "posts/tutorials/programming/atom.xml", "Rust"));
// It doesn't contain articles from other sections
assert!(!file_contains!(public, "posts/tutorials/programming/atom.xml", "Extra Syntax"));
2017-07-15 03:51:32 +00:00
}
2018-03-14 21:03:06 +00:00
#[test]
fn can_build_search_index() {
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
}
#[test]
fn can_build_with_extra_syntaxes() {
let (_, _tmp_dir, public) = build_site("test_site");
assert!(&public.exists());
assert!(file_exists!(public, "posts/extra-syntax/index.html"));
2021-01-02 08:29:28 +00:00
assert!(file_contains!(public, "posts/extra-syntax/index.html", r#"<span style="color:"#));
}
#[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 config_file = path.join("config.toml");
let mut site = Site::new(&path, &config_file).unwrap();
site.load().unwrap();
let template_path = path.join("content").join("applying_page_template");
2019-01-27 17:57:07 +00:00
let library = site.library.read().unwrap();
2019-01-27 17:57:07 +00:00
let template_section = library.get_section(&template_path.join("_index.md")).unwrap();
2018-11-07 19:48:39 +00:00
assert_eq!(template_section.subsections.len(), 2);
assert_eq!(template_section.pages.len(), 2);
2019-01-27 17:57:07 +00:00
let from_section_config = 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()));
2019-01-27 17:57:07 +00:00
let override_page_template = 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 =
2019-01-27 17:57:07 +00:00
library.get_section(&template_path.join("another_section").join("_index.md")).unwrap();
assert_eq!(another_section.subsections.len(), 0);
assert_eq!(another_section.pages.len(), 1);
2019-01-27 17:57:07 +00:00
let changed_recursively = 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
let yet_another_section =
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);
2019-01-27 17:57:07 +00:00
let child = library.get_page_by_key(yet_another_section.pages[0]);
2018-11-07 19:48:39 +00:00
assert_eq!(child.meta.template, Some("page_template_child.html".into()));
assert_eq!(child.meta.title, Some("Local section override".into()));
}
2019-08-04 14:13:07 +00:00
// https://github.com/getzola/zola/issues/571
#[test]
fn can_build_site_custom_builtins_from_theme() {
let (_, _tmp_dir, public) = build_site("test_site");
assert!(&public.exists());
// 404.html is a theme template.
assert!(file_exists!(public, "404.html"));
assert!(file_contains!(public, "404.html", "Oops"));
}
#[test]
fn can_build_site_with_html_minified() {
let (_, _tmp_dir, public) = build_site_with_setup("test_site", |mut site| {
site.config.minify_html = true;
(site, true)
});
assert!(&public.exists());
assert!(file_exists!(public, "index.html"));
assert!(file_contains!(
public,
"index.html",
"<!DOCTYPE html><html lang=en><head><meta charset=UTF-8>"
));
}
#[test]
fn can_ignore_markdown_content() {
let (_, _tmp_dir, public) = build_site("test_site");
assert!(!file_exists!(public, "posts/ignored/index.html"));
}
#[test]
fn can_cachebust_static_files() {
let (_, _tmp_dir, public) = build_site("test_site");
assert!(file_contains!(public, "index.html",
"<link href=\"https://replace-this-with-your-url.com/site.css?h=83bd983e8899946ee33d0fde18e82b04d7bca1881d10846c769b486640da3de9\" rel=\"stylesheet\">"));
}
#[test]
fn can_get_hash_for_static_files() {
let (_, _tmp_dir, public) = build_site("test_site");
assert!(file_contains!(
public,
"index.html",
"src=\"https://replace-this-with-your-url.com/scripts/hello.js\""
));
assert!(file_contains!(
public,
"index.html",
"integrity=\"sha384-AUIvMeqnIabErIxvoJon3ZJZ4N/PPHWT14ENkSqd5covWC35eFN7zRD3aJbbYfu5\""
));
}
#[test]
fn check_site() {
let (mut site, _tmp_dir, _public) = build_site("test_site");
assert_eq!(
site.config.link_checker.skip_anchor_prefixes,
vec!["https://github.com/rust-lang/rust/blob/"]
);
assert_eq!(site.config.link_checker.skip_prefixes, vec!["http://[2001:db8::]/"]);
site.config.enable_check_mode();
site.load().expect("link check test_site");
}
// Follows test_site/themes/sample/templates/current_path.html
fn current_path(path: &str) -> String {
format!("[current_path]({})", path)
}