You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

688 lines
26KB

  1. extern crate config;
  2. extern crate site;
  3. mod common;
  4. use std::collections::HashMap;
  5. use std::env;
  6. use std::path::Path;
  7. use common::{build_site, build_site_with_setup};
  8. use config::Taxonomy;
  9. use site::Site;
  10. #[test]
  11. fn can_parse_site() {
  12. let mut path = env::current_dir().unwrap().parent().unwrap().parent().unwrap().to_path_buf();
  13. path.push("test_site");
  14. let mut site = Site::new(&path, "config.toml").unwrap();
  15. site.load().unwrap();
  16. let library = site.library.read().unwrap();
  17. // Correct number of pages (sections do not count as pages, draft are ignored)
  18. assert_eq!(library.pages().len(), 21);
  19. let posts_path = path.join("content").join("posts");
  20. // Make sure the page with a url doesn't have any sections
  21. let url_post = library.get_page(&posts_path.join("fixed-url.md")).unwrap();
  22. assert_eq!(url_post.path, "a-fixed-url/");
  23. // Make sure the article in a folder with only asset doesn't get counted as a section
  24. let asset_folder_post =
  25. library.get_page(&posts_path.join("with-assets").join("index.md")).unwrap();
  26. assert_eq!(asset_folder_post.file.components, vec!["posts".to_string()]);
  27. // That we have the right number of sections
  28. assert_eq!(library.sections().len(), 11);
  29. // And that the sections are correct
  30. let index_section = library.get_section(&path.join("content").join("_index.md")).unwrap();
  31. assert_eq!(index_section.subsections.len(), 4);
  32. assert_eq!(index_section.pages.len(), 1);
  33. assert!(index_section.ancestors.is_empty());
  34. let posts_section = library.get_section(&posts_path.join("_index.md")).unwrap();
  35. assert_eq!(posts_section.subsections.len(), 2);
  36. assert_eq!(posts_section.pages.len(), 9); // 10 with 1 draft == 9
  37. assert_eq!(
  38. posts_section.ancestors,
  39. vec![*library.get_section_key(&index_section.file.path).unwrap()]
  40. );
  41. // Make sure we remove all the pwd + content from the sections
  42. let basic = library.get_page(&posts_path.join("simple.md")).unwrap();
  43. assert_eq!(basic.file.components, vec!["posts".to_string()]);
  44. assert_eq!(
  45. basic.ancestors,
  46. vec![
  47. *library.get_section_key(&index_section.file.path).unwrap(),
  48. *library.get_section_key(&posts_section.file.path).unwrap(),
  49. ]
  50. );
  51. let tutorials_section =
  52. library.get_section(&posts_path.join("tutorials").join("_index.md")).unwrap();
  53. assert_eq!(tutorials_section.subsections.len(), 2);
  54. let sub1 = library.get_section_by_key(tutorials_section.subsections[0]);
  55. let sub2 = library.get_section_by_key(tutorials_section.subsections[1]);
  56. assert_eq!(sub1.clone().meta.title.unwrap(), "Programming");
  57. assert_eq!(sub2.clone().meta.title.unwrap(), "DevOps");
  58. assert_eq!(tutorials_section.pages.len(), 0);
  59. let devops_section = library
  60. .get_section(&posts_path.join("tutorials").join("devops").join("_index.md"))
  61. .unwrap();
  62. assert_eq!(devops_section.subsections.len(), 0);
  63. assert_eq!(devops_section.pages.len(), 2);
  64. assert_eq!(
  65. devops_section.ancestors,
  66. vec![
  67. *library.get_section_key(&index_section.file.path).unwrap(),
  68. *library.get_section_key(&posts_section.file.path).unwrap(),
  69. *library.get_section_key(&tutorials_section.file.path).unwrap(),
  70. ]
  71. );
  72. let prog_section = library
  73. .get_section(&posts_path.join("tutorials").join("programming").join("_index.md"))
  74. .unwrap();
  75. assert_eq!(prog_section.subsections.len(), 0);
  76. assert_eq!(prog_section.pages.len(), 2);
  77. }
  78. #[test]
  79. fn can_build_site_without_live_reload() {
  80. let (_, _tmp_dir, public) = build_site("test_site");
  81. assert!(&public.exists());
  82. assert!(file_exists!(public, "index.html"));
  83. assert!(file_exists!(public, "sitemap.xml"));
  84. assert!(file_exists!(public, "robots.txt"));
  85. assert!(file_exists!(public, "a-fixed-url/index.html"));
  86. assert!(file_exists!(public, "posts/python/index.html"));
  87. // Shortcodes work
  88. assert!(file_contains!(public, "posts/python/index.html", "Basic shortcode"));
  89. assert!(file_contains!(public, "posts/python/index.html", "Arrrh Bob"));
  90. assert!(file_contains!(public, "posts/python/index.html", "Arrrh Bob_Sponge"));
  91. assert!(file_exists!(public, "posts/tutorials/devops/nix/index.html"));
  92. assert!(file_exists!(public, "posts/with-assets/index.html"));
  93. assert!(file_exists!(public, "posts/no-section/simple/index.html"));
  94. // Sections
  95. assert!(file_exists!(public, "posts/index.html"));
  96. assert!(file_exists!(public, "posts/tutorials/index.html"));
  97. assert!(file_exists!(public, "posts/tutorials/devops/index.html"));
  98. assert!(file_exists!(public, "posts/tutorials/programming/index.html"));
  99. // Ensure subsection pages are correctly filled
  100. assert!(file_contains!(public, "posts/tutorials/index.html", "Sub-pages: 2"));
  101. // Pages and section get their relative path
  102. assert!(file_contains!(public, "posts/tutorials/index.html", "posts/tutorials/_index.md"));
  103. assert!(file_contains!(
  104. public,
  105. "posts/tutorials/devops/nix/index.html",
  106. "posts/tutorials/devops/nix.md"
  107. ));
  108. // aliases work
  109. assert!(file_exists!(public, "an-old-url/old-page/index.html"));
  110. assert!(file_contains!(public, "an-old-url/old-page/index.html", "something-else"));
  111. assert!(file_contains!(public, "another-old-url/index.html", "posts/"));
  112. // html aliases work
  113. assert!(file_exists!(public, "an-old-url/an-old-alias.html"));
  114. assert!(file_contains!(public, "an-old-url/an-old-alias.html", "something-else"));
  115. // redirect_to works
  116. assert!(file_exists!(public, "posts/tutorials/devops/index.html"));
  117. assert!(file_contains!(public, "posts/tutorials/devops/index.html", "docker"));
  118. // We do have categories
  119. assert_eq!(file_exists!(public, "categories/index.html"), true);
  120. assert_eq!(file_exists!(public, "categories/a-category/index.html"), true);
  121. assert_eq!(file_exists!(public, "categories/a-category/rss.xml"), true);
  122. // But no tags
  123. assert_eq!(file_exists!(public, "tags/index.html"), false);
  124. // Theme files are there
  125. assert!(file_exists!(public, "sample.css"));
  126. assert!(file_exists!(public, "some.js"));
  127. // SASS and SCSS files compile correctly
  128. assert!(file_exists!(public, "blog.css"));
  129. assert!(file_contains!(public, "blog.css", "red"));
  130. assert!(file_contains!(public, "blog.css", "blue"));
  131. assert!(!file_contains!(public, "blog.css", "@import \"included\""));
  132. assert!(file_contains!(public, "blog.css", "2rem")); // check include
  133. assert!(!file_exists!(public, "_included.css"));
  134. assert!(file_exists!(public, "scss.css"));
  135. assert!(file_exists!(public, "sass.css"));
  136. assert!(file_exists!(public, "nested_sass/sass.css"));
  137. assert!(file_exists!(public, "nested_sass/scss.css"));
  138. // no live reload code
  139. assert_eq!(
  140. file_contains!(public, "index.html", "/livereload.js?port=1112&mindelay=10"),
  141. false
  142. );
  143. // Both pages and sections are in the sitemap
  144. assert!(file_contains!(
  145. public,
  146. "sitemap.xml",
  147. "<loc>https://replace-this-with-your-url.com/posts/simple/</loc>"
  148. ));
  149. assert!(file_contains!(
  150. public,
  151. "sitemap.xml",
  152. "<loc>https://replace-this-with-your-url.com/posts/</loc>"
  153. ));
  154. // Drafts are not in the sitemap
  155. assert!(!file_contains!(public, "sitemap.xml", "draft"));
  156. // render: false sections are not in the sitemap either
  157. assert!(!file_contains!(public, "sitemap.xml", "posts/2018/</loc>"));
  158. // robots.txt has been rendered from the template
  159. assert!(file_contains!(public, "robots.txt", "User-agent: zola"));
  160. assert!(file_contains!(
  161. public,
  162. "robots.txt",
  163. "Sitemap: https://replace-this-with-your-url.com/sitemap.xml"
  164. ));
  165. }
  166. #[test]
  167. fn can_build_site_with_live_reload_and_drafts() {
  168. let (_, _tmp_dir, public) = build_site_with_setup("test_site", |mut site| {
  169. site.enable_live_reload(1000);
  170. site.include_drafts();
  171. (site, true)
  172. });
  173. assert!(&public.exists());
  174. assert!(file_exists!(public, "index.html"));
  175. assert!(file_exists!(public, "sitemap.xml"));
  176. assert!(file_exists!(public, "robots.txt"));
  177. assert!(file_exists!(public, "a-fixed-url/index.html"));
  178. assert!(file_exists!(public, "posts/python/index.html"));
  179. assert!(file_exists!(public, "posts/tutorials/devops/nix/index.html"));
  180. assert!(file_exists!(public, "posts/with-assets/index.html"));
  181. // Sections
  182. assert!(file_exists!(public, "posts/index.html"));
  183. assert!(file_exists!(public, "posts/tutorials/index.html"));
  184. assert!(file_exists!(public, "posts/tutorials/devops/index.html"));
  185. assert!(file_exists!(public, "posts/tutorials/programming/index.html"));
  186. // TODO: add assertion for syntax highlighting
  187. // We do have categories
  188. assert_eq!(file_exists!(public, "categories/index.html"), true);
  189. assert_eq!(file_exists!(public, "categories/a-category/index.html"), true);
  190. assert_eq!(file_exists!(public, "categories/a-category/rss.xml"), true);
  191. // But no tags
  192. assert_eq!(file_exists!(public, "tags/index.html"), false);
  193. // no live reload code
  194. assert!(file_contains!(public, "index.html", "/livereload.js"));
  195. // the summary anchor link has been created
  196. assert!(file_contains!(
  197. public,
  198. "posts/python/index.html",
  199. r#"<a name="continue-reading"></a>"#
  200. ));
  201. // Drafts are included
  202. assert!(file_exists!(public, "posts/draft/index.html"));
  203. assert!(file_contains!(public, "sitemap.xml", "draft"));
  204. }
  205. #[test]
  206. fn can_build_site_with_taxonomies() {
  207. let (site, _tmp_dir, public) = build_site_with_setup("test_site", |mut site| {
  208. site.load().unwrap();
  209. {
  210. let mut library = site.library.write().unwrap();
  211. for (i, (_, page)) in library.pages_mut().iter_mut().enumerate() {
  212. page.meta.taxonomies = {
  213. let mut taxonomies = HashMap::new();
  214. taxonomies.insert(
  215. "categories".to_string(),
  216. vec![if i % 2 == 0 { "A" } else { "B" }.to_string()],
  217. );
  218. taxonomies
  219. };
  220. }
  221. }
  222. site.populate_taxonomies().unwrap();
  223. (site, false)
  224. });
  225. assert!(&public.exists());
  226. assert_eq!(site.taxonomies.len(), 1);
  227. assert!(file_exists!(public, "index.html"));
  228. assert!(file_exists!(public, "sitemap.xml"));
  229. assert!(file_exists!(public, "robots.txt"));
  230. assert!(file_exists!(public, "a-fixed-url/index.html"));
  231. assert!(file_exists!(public, "posts/python/index.html"));
  232. assert!(file_exists!(public, "posts/tutorials/devops/nix/index.html"));
  233. assert!(file_exists!(public, "posts/with-assets/index.html"));
  234. // Sections
  235. assert!(file_exists!(public, "posts/index.html"));
  236. assert!(file_exists!(public, "posts/tutorials/index.html"));
  237. assert!(file_exists!(public, "posts/tutorials/devops/index.html"));
  238. assert!(file_exists!(public, "posts/tutorials/programming/index.html"));
  239. // Categories are there
  240. assert!(file_exists!(public, "categories/index.html"));
  241. assert!(file_exists!(public, "categories/a/index.html"));
  242. assert!(file_exists!(public, "categories/b/index.html"));
  243. assert!(file_exists!(public, "categories/a/rss.xml"));
  244. assert!(file_contains!(
  245. public,
  246. "categories/a/rss.xml",
  247. "https://replace-this-with-your-url.com/categories/a/rss.xml"
  248. ));
  249. // Extending from a theme works
  250. assert!(file_contains!(public, "categories/a/index.html", "EXTENDED"));
  251. // Tags aren't
  252. assert_eq!(file_exists!(public, "tags/index.html"), false);
  253. // Categories are in the sitemap
  254. assert!(file_contains!(
  255. public,
  256. "sitemap.xml",
  257. "<loc>https://replace-this-with-your-url.com/categories/</loc>"
  258. ));
  259. assert!(file_contains!(
  260. public,
  261. "sitemap.xml",
  262. "<loc>https://replace-this-with-your-url.com/categories/a/</loc>"
  263. ));
  264. }
  265. #[test]
  266. fn can_build_site_and_insert_anchor_links() {
  267. let (_, _tmp_dir, public) = build_site("test_site");
  268. assert!(Path::new(&public).exists());
  269. // anchor link inserted
  270. assert!(file_contains!(
  271. public,
  272. "posts/something-else/index.html",
  273. "<h1 id=\"title\"><a class=\"zola-anchor\" href=\"#title\""
  274. ));
  275. }
  276. #[test]
  277. fn can_build_site_with_pagination_for_section() {
  278. let (_, _tmp_dir, public) = build_site_with_setup("test_site", |mut site| {
  279. site.load().unwrap();
  280. {
  281. let mut library = site.library.write().unwrap();
  282. for (_, section) in library.sections_mut() {
  283. if section.is_index() {
  284. continue;
  285. }
  286. section.meta.paginate_by = Some(2);
  287. section.meta.template = Some("section_paginated.html".to_string());
  288. }
  289. }
  290. (site, false)
  291. });
  292. assert!(&public.exists());
  293. assert!(file_exists!(public, "index.html"));
  294. assert!(file_exists!(public, "sitemap.xml"));
  295. assert!(file_exists!(public, "robots.txt"));
  296. assert!(file_exists!(public, "a-fixed-url/index.html"));
  297. assert!(file_exists!(public, "posts/python/index.html"));
  298. assert!(file_exists!(public, "posts/tutorials/devops/nix/index.html"));
  299. assert!(file_exists!(public, "posts/with-assets/index.html"));
  300. // Sections
  301. assert!(file_exists!(public, "posts/index.html"));
  302. // And pagination!
  303. assert!(file_exists!(public, "posts/page/1/index.html"));
  304. // even if there is no pages, only the section!
  305. assert!(file_exists!(public, "paginated/page/1/index.html"));
  306. assert!(file_exists!(public, "paginated/index.html"));
  307. // should redirect to posts/
  308. assert!(file_contains!(
  309. public,
  310. "posts/page/1/index.html",
  311. "http-equiv=\"refresh\" content=\"0;url=https://replace-this-with-your-url.com/posts/\""
  312. ));
  313. assert!(file_contains!(public, "posts/index.html", "Num pagers: 5"));
  314. assert!(file_contains!(public, "posts/index.html", "Page size: 2"));
  315. assert!(file_contains!(public, "posts/index.html", "Current index: 1"));
  316. assert!(!file_contains!(public, "posts/index.html", "has_prev"));
  317. assert!(file_contains!(public, "posts/index.html", "has_next"));
  318. assert!(file_contains!(
  319. public,
  320. "posts/index.html",
  321. "First: https://replace-this-with-your-url.com/posts/"
  322. ));
  323. assert!(file_contains!(
  324. public,
  325. "posts/index.html",
  326. "Last: https://replace-this-with-your-url.com/posts/page/5/"
  327. ));
  328. assert_eq!(file_contains!(public, "posts/index.html", "has_prev"), false);
  329. assert!(file_exists!(public, "posts/page/2/index.html"));
  330. assert!(file_contains!(public, "posts/page/2/index.html", "Num pagers: 5"));
  331. assert!(file_contains!(public, "posts/page/2/index.html", "Page size: 2"));
  332. assert!(file_contains!(public, "posts/page/2/index.html", "Current index: 2"));
  333. assert!(file_contains!(public, "posts/page/2/index.html", "has_prev"));
  334. assert!(file_contains!(public, "posts/page/2/index.html", "has_next"));
  335. assert!(file_contains!(
  336. public,
  337. "posts/page/2/index.html",
  338. "First: https://replace-this-with-your-url.com/posts/"
  339. ));
  340. assert!(file_contains!(
  341. public,
  342. "posts/page/2/index.html",
  343. "Last: https://replace-this-with-your-url.com/posts/page/5/"
  344. ));
  345. assert!(file_exists!(public, "posts/page/3/index.html"));
  346. assert!(file_contains!(public, "posts/page/3/index.html", "Num pagers: 5"));
  347. assert!(file_contains!(public, "posts/page/3/index.html", "Page size: 2"));
  348. assert!(file_contains!(public, "posts/page/3/index.html", "Current index: 3"));
  349. assert!(file_contains!(public, "posts/page/3/index.html", "has_prev"));
  350. assert!(file_contains!(public, "posts/page/3/index.html", "has_next"));
  351. assert!(file_contains!(
  352. public,
  353. "posts/page/3/index.html",
  354. "First: https://replace-this-with-your-url.com/posts/"
  355. ));
  356. assert!(file_contains!(
  357. public,
  358. "posts/page/3/index.html",
  359. "Last: https://replace-this-with-your-url.com/posts/page/5/"
  360. ));
  361. assert!(file_exists!(public, "posts/page/4/index.html"));
  362. assert!(file_contains!(public, "posts/page/4/index.html", "Num pagers: 5"));
  363. assert!(file_contains!(public, "posts/page/4/index.html", "Page size: 2"));
  364. assert!(file_contains!(public, "posts/page/4/index.html", "Current index: 4"));
  365. assert!(file_contains!(public, "posts/page/4/index.html", "has_prev"));
  366. assert!(file_contains!(public, "posts/page/4/index.html", "has_next"));
  367. assert!(file_contains!(
  368. public,
  369. "posts/page/4/index.html",
  370. "First: https://replace-this-with-your-url.com/posts/"
  371. ));
  372. assert!(file_contains!(
  373. public,
  374. "posts/page/4/index.html",
  375. "Last: https://replace-this-with-your-url.com/posts/page/5/"
  376. ));
  377. // sitemap contains the pager pages
  378. assert!(file_contains!(
  379. public,
  380. "sitemap.xml",
  381. "<loc>https://replace-this-with-your-url.com/posts/page/4/</loc>"
  382. ));
  383. }
  384. #[test]
  385. fn can_build_site_with_pagination_for_index() {
  386. let (_, _tmp_dir, public) = build_site_with_setup("test_site", |mut site| {
  387. site.load().unwrap();
  388. {
  389. let mut library = site.library.write().unwrap();
  390. {
  391. let index = library
  392. .get_section_mut(&site.base_path.join("content").join("_index.md"))
  393. .unwrap();
  394. index.meta.paginate_by = Some(2);
  395. index.meta.template = Some("index_paginated.html".to_string());
  396. }
  397. }
  398. (site, false)
  399. });
  400. assert!(&public.exists());
  401. assert!(file_exists!(public, "index.html"));
  402. assert!(file_exists!(public, "sitemap.xml"));
  403. assert!(file_exists!(public, "robots.txt"));
  404. assert!(file_exists!(public, "a-fixed-url/index.html"));
  405. assert!(file_exists!(public, "posts/python/index.html"));
  406. assert!(file_exists!(public, "posts/tutorials/devops/nix/index.html"));
  407. assert!(file_exists!(public, "posts/with-assets/index.html"));
  408. // And pagination!
  409. assert!(file_exists!(public, "page/1/index.html"));
  410. // even if there is no pages, only the section!
  411. assert!(file_exists!(public, "paginated/page/1/index.html"));
  412. assert!(file_exists!(public, "paginated/index.html"));
  413. // should redirect to index
  414. assert!(file_contains!(
  415. public,
  416. "page/1/index.html",
  417. "http-equiv=\"refresh\" content=\"0;url=https://replace-this-with-your-url.com/\""
  418. ));
  419. assert!(file_contains!(public, "page/1/index.html", "<title>Redirect</title>"));
  420. assert!(file_contains!(
  421. public,
  422. "page/1/index.html",
  423. "<a href=\"https://replace-this-with-your-url.com/\">Click here</a>"
  424. ));
  425. assert!(file_contains!(public, "index.html", "Num pages: 1"));
  426. assert!(file_contains!(public, "index.html", "Current index: 1"));
  427. assert!(file_contains!(public, "index.html", "First: https://replace-this-with-your-url.com/"));
  428. assert!(file_contains!(public, "index.html", "Last: https://replace-this-with-your-url.com/"));
  429. assert_eq!(file_contains!(public, "index.html", "has_prev"), false);
  430. assert_eq!(file_contains!(public, "index.html", "has_next"), false);
  431. // sitemap contains the pager pages
  432. assert!(file_contains!(
  433. public,
  434. "sitemap.xml",
  435. "<loc>https://replace-this-with-your-url.com/page/1/</loc>"
  436. ))
  437. }
  438. #[test]
  439. fn can_build_site_with_pagination_for_taxonomy() {
  440. let (_, _tmp_dir, public) = build_site_with_setup("test_site", |mut site| {
  441. site.config.taxonomies.push(Taxonomy {
  442. name: "tags".to_string(),
  443. paginate_by: Some(2),
  444. paginate_path: None,
  445. rss: true,
  446. lang: site.config.default_language.clone(),
  447. });
  448. site.load().unwrap();
  449. {
  450. let mut library = site.library.write().unwrap();
  451. for (i, (_, page)) in library.pages_mut().iter_mut().enumerate() {
  452. page.meta.taxonomies = {
  453. let mut taxonomies = HashMap::new();
  454. taxonomies.insert(
  455. "tags".to_string(),
  456. vec![if i % 2 == 0 { "A" } else { "B" }.to_string()],
  457. );
  458. taxonomies
  459. };
  460. }
  461. }
  462. site.populate_taxonomies().unwrap();
  463. (site, false)
  464. });
  465. assert!(&public.exists());
  466. assert!(file_exists!(public, "index.html"));
  467. assert!(file_exists!(public, "sitemap.xml"));
  468. assert!(file_exists!(public, "robots.txt"));
  469. assert!(file_exists!(public, "a-fixed-url/index.html"));
  470. assert!(file_exists!(public, "posts/python/index.html"));
  471. assert!(file_exists!(public, "posts/tutorials/devops/nix/index.html"));
  472. assert!(file_exists!(public, "posts/with-assets/index.html"));
  473. // Tags
  474. assert!(file_exists!(public, "tags/index.html"));
  475. // With RSS
  476. assert!(file_exists!(public, "tags/a/rss.xml"));
  477. assert!(file_exists!(public, "tags/b/rss.xml"));
  478. // And pagination!
  479. assert!(file_exists!(public, "tags/a/page/1/index.html"));
  480. assert!(file_exists!(public, "tags/b/page/1/index.html"));
  481. assert!(file_exists!(public, "tags/a/page/2/index.html"));
  482. assert!(file_exists!(public, "tags/b/page/2/index.html"));
  483. // should redirect to posts/
  484. assert!(file_contains!(
  485. public,
  486. "tags/a/page/1/index.html",
  487. "http-equiv=\"refresh\" content=\"0;url=https://replace-this-with-your-url.com/tags/a/\""
  488. ));
  489. assert!(file_contains!(public, "tags/a/index.html", "Num pagers: 6"));
  490. assert!(file_contains!(public, "tags/a/index.html", "Page size: 2"));
  491. assert!(file_contains!(public, "tags/a/index.html", "Current index: 1"));
  492. assert!(!file_contains!(public, "tags/a/index.html", "has_prev"));
  493. assert!(file_contains!(public, "tags/a/index.html", "has_next"));
  494. assert!(file_contains!(
  495. public,
  496. "tags/a/index.html",
  497. "First: https://replace-this-with-your-url.com/tags/a/"
  498. ));
  499. assert!(file_contains!(
  500. public,
  501. "tags/a/index.html",
  502. "Last: https://replace-this-with-your-url.com/tags/a/page/6/"
  503. ));
  504. assert_eq!(file_contains!(public, "tags/a/index.html", "has_prev"), false);
  505. // sitemap contains the pager pages
  506. assert!(file_contains!(
  507. public,
  508. "sitemap.xml",
  509. "<loc>https://replace-this-with-your-url.com/tags/a/page/6/</loc>"
  510. ))
  511. }
  512. #[test]
  513. fn can_build_rss_feed() {
  514. let (_, _tmp_dir, public) = build_site("test_site");
  515. assert!(&public.exists());
  516. assert!(file_exists!(public, "rss.xml"));
  517. // latest article is posts/extra-syntax.md
  518. assert!(file_contains!(public, "rss.xml", "Extra Syntax"));
  519. // Next is posts/simple.md
  520. assert!(file_contains!(public, "rss.xml", "Simple article with shortcodes"));
  521. }
  522. #[test]
  523. fn can_build_search_index() {
  524. let (_, _tmp_dir, public) = build_site_with_setup("test_site", |mut site| {
  525. site.config.build_search_index = true;
  526. (site, true)
  527. });
  528. assert!(Path::new(&public).exists());
  529. assert!(file_exists!(public, "elasticlunr.min.js"));
  530. assert!(file_exists!(public, "search_index.en.js"));
  531. }
  532. #[test]
  533. fn can_build_with_extra_syntaxes() {
  534. let (_, _tmp_dir, public) = build_site("test_site");
  535. assert!(&public.exists());
  536. assert!(file_exists!(public, "posts/extra-syntax/index.html"));
  537. assert!(file_contains!(
  538. public,
  539. "posts/extra-syntax/index.html",
  540. r#"<span style="color:#d08770;">test</span>"#
  541. ));
  542. }
  543. #[test]
  544. fn can_apply_page_templates() {
  545. let mut path = env::current_dir().unwrap().parent().unwrap().parent().unwrap().to_path_buf();
  546. path.push("test_site");
  547. let mut site = Site::new(&path, "config.toml").unwrap();
  548. site.load().unwrap();
  549. let template_path = path.join("content").join("applying_page_template");
  550. let library = site.library.read().unwrap();
  551. let template_section = library.get_section(&template_path.join("_index.md")).unwrap();
  552. assert_eq!(template_section.subsections.len(), 2);
  553. assert_eq!(template_section.pages.len(), 2);
  554. let from_section_config = library.get_page_by_key(template_section.pages[0]);
  555. assert_eq!(from_section_config.meta.template, Some("page_template.html".into()));
  556. assert_eq!(from_section_config.meta.title, Some("From section config".into()));
  557. let override_page_template = library.get_page_by_key(template_section.pages[1]);
  558. assert_eq!(override_page_template.meta.template, Some("page_template_override.html".into()));
  559. assert_eq!(override_page_template.meta.title, Some("Override".into()));
  560. // It should have applied recursively as well
  561. let another_section =
  562. library.get_section(&template_path.join("another_section").join("_index.md")).unwrap();
  563. assert_eq!(another_section.subsections.len(), 0);
  564. assert_eq!(another_section.pages.len(), 1);
  565. let changed_recursively = library.get_page_by_key(another_section.pages[0]);
  566. assert_eq!(changed_recursively.meta.template, Some("page_template.html".into()));
  567. assert_eq!(changed_recursively.meta.title, Some("Changed recursively".into()));
  568. // But it should not have override a children page_template
  569. let yet_another_section =
  570. library.get_section(&template_path.join("yet_another_section").join("_index.md")).unwrap();
  571. assert_eq!(yet_another_section.subsections.len(), 0);
  572. assert_eq!(yet_another_section.pages.len(), 1);
  573. let child = library.get_page_by_key(yet_another_section.pages[0]);
  574. assert_eq!(child.meta.template, Some("page_template_child.html".into()));
  575. assert_eq!(child.meta.title, Some("Local section override".into()));
  576. }
  577. // https://github.com/getzola/zola/issues/571
  578. #[test]
  579. fn can_build_site_custom_builtins_from_theme() {
  580. let (_, _tmp_dir, public) = build_site("test_site");
  581. assert!(&public.exists());
  582. // 404.html is a theme template.
  583. assert!(file_exists!(public, "404.html"));
  584. assert!(file_contains!(public, "404.html", "Oops"));
  585. }
  586. #[test]
  587. fn can_ignore_markdown_content() {
  588. let (_, _tmp_dir, public) = build_site("test_site");
  589. assert!(!file_exists!(public, "posts/ignored/index.html"));
  590. }
  591. #[test]
  592. fn check_site() {
  593. let (mut site, _tmp_dir, _public) = build_site("test_site");
  594. assert_eq!(
  595. site.config.link_checker.skip_anchor_prefixes,
  596. vec!["https://github.com/rust-lang/rust/blob/"]
  597. );
  598. assert_eq!(site.config.link_checker.skip_prefixes, vec!["http://[2001:db8::]/"]);
  599. site.config.enable_check_mode();
  600. site.load().expect("link check test_site");
  601. }