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.

662 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!(file_contains!(public, "index.html", "/livereload.js?port=1112&mindelay=10"), false);
  140. // Both pages and sections are in the sitemap
  141. assert!(file_contains!(
  142. public,
  143. "sitemap.xml",
  144. "<loc>https%3A//replace-this-with-your-url.com/posts/simple/</loc>"
  145. ));
  146. assert!(file_contains!(
  147. public,
  148. "sitemap.xml",
  149. "<loc>https%3A//replace-this-with-your-url.com/posts/</loc>"
  150. ));
  151. // Drafts are not in the sitemap
  152. assert!(!file_contains!(public, "sitemap.xml", "draft"));
  153. // render: false sections are not in the sitemap either
  154. assert!(!file_contains!(public, "sitemap.xml", "posts/2018/</loc>"));
  155. // robots.txt has been rendered from the template
  156. assert!(file_contains!(public, "robots.txt", "User-agent: zola"));
  157. assert!(file_contains!(
  158. public,
  159. "robots.txt",
  160. "Sitemap: https://replace-this-with-your-url.com/sitemap.xml"
  161. ));
  162. }
  163. #[test]
  164. fn can_build_site_with_live_reload() {
  165. let (_, _tmp_dir, public) = build_site_with_setup("test_site", |mut site| {
  166. site.enable_live_reload(1000);
  167. (site, true)
  168. });
  169. assert!(&public.exists());
  170. assert!(file_exists!(public, "index.html"));
  171. assert!(file_exists!(public, "sitemap.xml"));
  172. assert!(file_exists!(public, "robots.txt"));
  173. assert!(file_exists!(public, "a-fixed-url/index.html"));
  174. assert!(file_exists!(public, "posts/python/index.html"));
  175. assert!(file_exists!(public, "posts/tutorials/devops/nix/index.html"));
  176. assert!(file_exists!(public, "posts/with-assets/index.html"));
  177. // Sections
  178. assert!(file_exists!(public, "posts/index.html"));
  179. assert!(file_exists!(public, "posts/tutorials/index.html"));
  180. assert!(file_exists!(public, "posts/tutorials/devops/index.html"));
  181. assert!(file_exists!(public, "posts/tutorials/programming/index.html"));
  182. // TODO: add assertion for syntax highlighting
  183. // We do have categories
  184. assert_eq!(file_exists!(public, "categories/index.html"), true);
  185. assert_eq!(file_exists!(public, "categories/a-category/index.html"), true);
  186. assert_eq!(file_exists!(public, "categories/a-category/rss.xml"), true);
  187. // But no tags
  188. assert_eq!(file_exists!(public, "tags/index.html"), false);
  189. // no live reload code
  190. assert!(file_contains!(public, "index.html", "/livereload.js"));
  191. // the summary anchor link has been created
  192. assert!(file_contains!(
  193. public,
  194. "posts/python/index.html",
  195. r#"<a name="continue-reading"></a>"#
  196. ));
  197. assert_eq!(file_exists!(public, "posts/draft/index.html"), false);
  198. }
  199. #[test]
  200. fn can_build_site_with_taxonomies() {
  201. let (site, _tmp_dir, public) = build_site_with_setup("test_site", |mut site| {
  202. site.load().unwrap();
  203. {
  204. let mut library = site.library.write().unwrap();
  205. for (i, (_, page)) in library.pages_mut().iter_mut().enumerate() {
  206. page.meta.taxonomies = {
  207. let mut taxonomies = HashMap::new();
  208. taxonomies.insert(
  209. "categories".to_string(),
  210. vec![if i % 2 == 0 { "A" } else { "B" }.to_string()],
  211. );
  212. taxonomies
  213. };
  214. }
  215. }
  216. site.populate_taxonomies().unwrap();
  217. (site, false)
  218. });
  219. assert!(&public.exists());
  220. assert_eq!(site.taxonomies.len(), 1);
  221. assert!(file_exists!(public, "index.html"));
  222. assert!(file_exists!(public, "sitemap.xml"));
  223. assert!(file_exists!(public, "robots.txt"));
  224. assert!(file_exists!(public, "a-fixed-url/index.html"));
  225. assert!(file_exists!(public, "posts/python/index.html"));
  226. assert!(file_exists!(public, "posts/tutorials/devops/nix/index.html"));
  227. assert!(file_exists!(public, "posts/with-assets/index.html"));
  228. // Sections
  229. assert!(file_exists!(public, "posts/index.html"));
  230. assert!(file_exists!(public, "posts/tutorials/index.html"));
  231. assert!(file_exists!(public, "posts/tutorials/devops/index.html"));
  232. assert!(file_exists!(public, "posts/tutorials/programming/index.html"));
  233. // Categories are there
  234. assert!(file_exists!(public, "categories/index.html"));
  235. assert!(file_exists!(public, "categories/a/index.html"));
  236. assert!(file_exists!(public, "categories/b/index.html"));
  237. assert!(file_exists!(public, "categories/a/rss.xml"));
  238. assert!(file_contains!(
  239. public,
  240. "categories/a/rss.xml",
  241. "https%3A//replace-this-with-your-url.com/categories/a/rss.xml"
  242. ));
  243. // Extending from a theme works
  244. assert!(file_contains!(public, "categories/a/index.html", "EXTENDED"));
  245. // Tags aren't
  246. assert_eq!(file_exists!(public, "tags/index.html"), false);
  247. // Categories are in the sitemap
  248. assert!(file_contains!(
  249. public,
  250. "sitemap.xml",
  251. "<loc>https%3A//replace-this-with-your-url.com/categories/</loc>"
  252. ));
  253. assert!(file_contains!(
  254. public,
  255. "sitemap.xml",
  256. "<loc>https%3A//replace-this-with-your-url.com/categories/a/</loc>"
  257. ));
  258. }
  259. #[test]
  260. fn can_build_site_and_insert_anchor_links() {
  261. let (_, _tmp_dir, public) = build_site("test_site");
  262. assert!(Path::new(&public).exists());
  263. // anchor link inserted
  264. assert!(file_contains!(
  265. public,
  266. "posts/something-else/index.html",
  267. "<h1 id=\"title\"><a class=\"zola-anchor\" href=\"#title\""
  268. ));
  269. }
  270. #[test]
  271. fn can_build_site_with_pagination_for_section() {
  272. let (_, _tmp_dir, public) = build_site_with_setup("test_site", |mut site| {
  273. site.load().unwrap();
  274. {
  275. let mut library = site.library.write().unwrap();
  276. for (_, section) in library.sections_mut() {
  277. if section.is_index() {
  278. continue;
  279. }
  280. section.meta.paginate_by = Some(2);
  281. section.meta.template = Some("section_paginated.html".to_string());
  282. }
  283. }
  284. (site, false)
  285. });
  286. assert!(&public.exists());
  287. assert!(file_exists!(public, "index.html"));
  288. assert!(file_exists!(public, "sitemap.xml"));
  289. assert!(file_exists!(public, "robots.txt"));
  290. assert!(file_exists!(public, "a-fixed-url/index.html"));
  291. assert!(file_exists!(public, "posts/python/index.html"));
  292. assert!(file_exists!(public, "posts/tutorials/devops/nix/index.html"));
  293. assert!(file_exists!(public, "posts/with-assets/index.html"));
  294. // Sections
  295. assert!(file_exists!(public, "posts/index.html"));
  296. // And pagination!
  297. assert!(file_exists!(public, "posts/page/1/index.html"));
  298. // even if there is no pages, only the section!
  299. assert!(file_exists!(public, "paginated/page/1/index.html"));
  300. assert!(file_exists!(public, "paginated/index.html"));
  301. // should redirect to posts/
  302. assert!(file_contains!(
  303. public,
  304. "posts/page/1/index.html",
  305. "http-equiv=\"refresh\" content=\"0;url=https://replace-this-with-your-url.com/posts/\""
  306. ));
  307. assert!(file_contains!(public, "posts/index.html", "Num pagers: 5"));
  308. assert!(file_contains!(public, "posts/index.html", "Page size: 2"));
  309. assert!(file_contains!(public, "posts/index.html", "Current index: 1"));
  310. assert!(!file_contains!(public, "posts/index.html", "has_prev"));
  311. assert!(file_contains!(public, "posts/index.html", "has_next"));
  312. assert!(file_contains!(
  313. public,
  314. "posts/index.html",
  315. "First: https://replace-this-with-your-url.com/posts/"
  316. ));
  317. assert!(file_contains!(
  318. public,
  319. "posts/index.html",
  320. "Last: https://replace-this-with-your-url.com/posts/page/5/"
  321. ));
  322. assert_eq!(file_contains!(public, "posts/index.html", "has_prev"), false);
  323. assert!(file_exists!(public, "posts/page/2/index.html"));
  324. assert!(file_contains!(public, "posts/page/2/index.html", "Num pagers: 5"));
  325. assert!(file_contains!(public, "posts/page/2/index.html", "Page size: 2"));
  326. assert!(file_contains!(public, "posts/page/2/index.html", "Current index: 2"));
  327. assert!(file_contains!(public, "posts/page/2/index.html", "has_prev"));
  328. assert!(file_contains!(public, "posts/page/2/index.html", "has_next"));
  329. assert!(file_contains!(
  330. public,
  331. "posts/page/2/index.html",
  332. "First: https://replace-this-with-your-url.com/posts/"
  333. ));
  334. assert!(file_contains!(
  335. public,
  336. "posts/page/2/index.html",
  337. "Last: https://replace-this-with-your-url.com/posts/page/5/"
  338. ));
  339. assert!(file_exists!(public, "posts/page/3/index.html"));
  340. assert!(file_contains!(public, "posts/page/3/index.html", "Num pagers: 5"));
  341. assert!(file_contains!(public, "posts/page/3/index.html", "Page size: 2"));
  342. assert!(file_contains!(public, "posts/page/3/index.html", "Current index: 3"));
  343. assert!(file_contains!(public, "posts/page/3/index.html", "has_prev"));
  344. assert!(file_contains!(public, "posts/page/3/index.html", "has_next"));
  345. assert!(file_contains!(
  346. public,
  347. "posts/page/3/index.html",
  348. "First: https://replace-this-with-your-url.com/posts/"
  349. ));
  350. assert!(file_contains!(
  351. public,
  352. "posts/page/3/index.html",
  353. "Last: https://replace-this-with-your-url.com/posts/page/5/"
  354. ));
  355. assert!(file_exists!(public, "posts/page/4/index.html"));
  356. assert!(file_contains!(public, "posts/page/4/index.html", "Num pagers: 5"));
  357. assert!(file_contains!(public, "posts/page/4/index.html", "Page size: 2"));
  358. assert!(file_contains!(public, "posts/page/4/index.html", "Current index: 4"));
  359. assert!(file_contains!(public, "posts/page/4/index.html", "has_prev"));
  360. assert!(file_contains!(public, "posts/page/4/index.html", "has_next"));
  361. assert!(file_contains!(
  362. public,
  363. "posts/page/4/index.html",
  364. "First: https://replace-this-with-your-url.com/posts/"
  365. ));
  366. assert!(file_contains!(
  367. public,
  368. "posts/page/4/index.html",
  369. "Last: https://replace-this-with-your-url.com/posts/page/5/"
  370. ));
  371. // sitemap contains the pager pages
  372. assert!(file_contains!(
  373. public,
  374. "sitemap.xml",
  375. "<loc>https%3A//replace-this-with-your-url.com/posts/page/4/</loc>"
  376. ));
  377. }
  378. #[test]
  379. fn can_build_site_with_pagination_for_index() {
  380. let (_, _tmp_dir, public) = build_site_with_setup("test_site", |mut site| {
  381. site.load().unwrap();
  382. {
  383. let mut library = site.library.write().unwrap();
  384. {
  385. let index = library
  386. .get_section_mut(&site.base_path.join("content").join("_index.md"))
  387. .unwrap();
  388. index.meta.paginate_by = Some(2);
  389. index.meta.template = Some("index_paginated.html".to_string());
  390. }
  391. }
  392. (site, false)
  393. });
  394. assert!(&public.exists());
  395. assert!(file_exists!(public, "index.html"));
  396. assert!(file_exists!(public, "sitemap.xml"));
  397. assert!(file_exists!(public, "robots.txt"));
  398. assert!(file_exists!(public, "a-fixed-url/index.html"));
  399. assert!(file_exists!(public, "posts/python/index.html"));
  400. assert!(file_exists!(public, "posts/tutorials/devops/nix/index.html"));
  401. assert!(file_exists!(public, "posts/with-assets/index.html"));
  402. // And pagination!
  403. assert!(file_exists!(public, "page/1/index.html"));
  404. // even if there is no pages, only the section!
  405. assert!(file_exists!(public, "paginated/page/1/index.html"));
  406. assert!(file_exists!(public, "paginated/index.html"));
  407. // should redirect to index
  408. assert!(file_contains!(
  409. public,
  410. "page/1/index.html",
  411. "http-equiv=\"refresh\" content=\"0;url=https://replace-this-with-your-url.com/\""
  412. ));
  413. assert!(file_contains!(public, "index.html", "Num pages: 1"));
  414. assert!(file_contains!(public, "index.html", "Current index: 1"));
  415. assert!(file_contains!(public, "index.html", "First: https://replace-this-with-your-url.com/"));
  416. assert!(file_contains!(public, "index.html", "Last: https://replace-this-with-your-url.com/"));
  417. assert_eq!(file_contains!(public, "index.html", "has_prev"), false);
  418. assert_eq!(file_contains!(public, "index.html", "has_next"), false);
  419. // sitemap contains the pager pages
  420. assert!(file_contains!(
  421. public,
  422. "sitemap.xml",
  423. "<loc>https%3A//replace-this-with-your-url.com/page/1/</loc>"
  424. ))
  425. }
  426. #[test]
  427. fn can_build_site_with_pagination_for_taxonomy() {
  428. let (_, _tmp_dir, public) = build_site_with_setup("test_site", |mut site| {
  429. site.config.taxonomies.push(Taxonomy {
  430. name: "tags".to_string(),
  431. paginate_by: Some(2),
  432. paginate_path: None,
  433. rss: true,
  434. lang: site.config.default_language.clone(),
  435. });
  436. site.load().unwrap();
  437. {
  438. let mut library = site.library.write().unwrap();
  439. for (i, (_, page)) in library.pages_mut().iter_mut().enumerate() {
  440. page.meta.taxonomies = {
  441. let mut taxonomies = HashMap::new();
  442. taxonomies.insert(
  443. "tags".to_string(),
  444. vec![if i % 2 == 0 { "A" } else { "B" }.to_string()],
  445. );
  446. taxonomies
  447. };
  448. }
  449. }
  450. site.populate_taxonomies().unwrap();
  451. (site, false)
  452. });
  453. assert!(&public.exists());
  454. assert!(file_exists!(public, "index.html"));
  455. assert!(file_exists!(public, "sitemap.xml"));
  456. assert!(file_exists!(public, "robots.txt"));
  457. assert!(file_exists!(public, "a-fixed-url/index.html"));
  458. assert!(file_exists!(public, "posts/python/index.html"));
  459. assert!(file_exists!(public, "posts/tutorials/devops/nix/index.html"));
  460. assert!(file_exists!(public, "posts/with-assets/index.html"));
  461. // Tags
  462. assert!(file_exists!(public, "tags/index.html"));
  463. // With RSS
  464. assert!(file_exists!(public, "tags/a/rss.xml"));
  465. assert!(file_exists!(public, "tags/b/rss.xml"));
  466. // And pagination!
  467. assert!(file_exists!(public, "tags/a/page/1/index.html"));
  468. assert!(file_exists!(public, "tags/b/page/1/index.html"));
  469. assert!(file_exists!(public, "tags/a/page/2/index.html"));
  470. assert!(file_exists!(public, "tags/b/page/2/index.html"));
  471. // should redirect to posts/
  472. assert!(file_contains!(
  473. public,
  474. "tags/a/page/1/index.html",
  475. "http-equiv=\"refresh\" content=\"0;url=https://replace-this-with-your-url.com/tags/a/\""
  476. ));
  477. assert!(file_contains!(public, "tags/a/index.html", "Num pagers: 6"));
  478. assert!(file_contains!(public, "tags/a/index.html", "Page size: 2"));
  479. assert!(file_contains!(public, "tags/a/index.html", "Current index: 1"));
  480. assert!(!file_contains!(public, "tags/a/index.html", "has_prev"));
  481. assert!(file_contains!(public, "tags/a/index.html", "has_next"));
  482. assert!(file_contains!(
  483. public,
  484. "tags/a/index.html",
  485. "First: https://replace-this-with-your-url.com/tags/a/"
  486. ));
  487. assert!(file_contains!(
  488. public,
  489. "tags/a/index.html",
  490. "Last: https://replace-this-with-your-url.com/tags/a/page/6/"
  491. ));
  492. assert_eq!(file_contains!(public, "tags/a/index.html", "has_prev"), false);
  493. // sitemap contains the pager pages
  494. assert!(file_contains!(
  495. public,
  496. "sitemap.xml",
  497. "<loc>https%3A//replace-this-with-your-url.com/tags/a/page/6/</loc>"
  498. ))
  499. }
  500. #[test]
  501. fn can_build_rss_feed() {
  502. let (_, _tmp_dir, public) = build_site("test_site");
  503. assert!(&public.exists());
  504. assert!(file_exists!(public, "rss.xml"));
  505. // latest article is posts/extra-syntax.md
  506. assert!(file_contains!(public, "rss.xml", "Extra Syntax"));
  507. // Next is posts/simple.md
  508. assert!(file_contains!(public, "rss.xml", "Simple article with shortcodes"));
  509. }
  510. #[test]
  511. fn can_build_search_index() {
  512. let (_, _tmp_dir, public) = build_site_with_setup("test_site", |mut site| {
  513. site.config.build_search_index = true;
  514. (site, true)
  515. });
  516. assert!(Path::new(&public).exists());
  517. assert!(file_exists!(public, "elasticlunr.min.js"));
  518. assert!(file_exists!(public, "search_index.en.js"));
  519. }
  520. #[test]
  521. fn can_build_with_extra_syntaxes() {
  522. let (_, _tmp_dir, public) = build_site("test_site");
  523. assert!(&public.exists());
  524. assert!(file_exists!(public, "posts/extra-syntax/index.html"));
  525. assert!(file_contains!(
  526. public,
  527. "posts/extra-syntax/index.html",
  528. r#"<span style="color:#d08770;">test</span>"#
  529. ));
  530. }
  531. #[test]
  532. fn can_apply_page_templates() {
  533. let mut path = env::current_dir().unwrap().parent().unwrap().parent().unwrap().to_path_buf();
  534. path.push("test_site");
  535. let mut site = Site::new(&path, "config.toml").unwrap();
  536. site.load().unwrap();
  537. let template_path = path.join("content").join("applying_page_template");
  538. let library = site.library.read().unwrap();
  539. let template_section = library.get_section(&template_path.join("_index.md")).unwrap();
  540. assert_eq!(template_section.subsections.len(), 2);
  541. assert_eq!(template_section.pages.len(), 2);
  542. let from_section_config = library.get_page_by_key(template_section.pages[0]);
  543. assert_eq!(from_section_config.meta.template, Some("page_template.html".into()));
  544. assert_eq!(from_section_config.meta.title, Some("From section config".into()));
  545. let override_page_template = library.get_page_by_key(template_section.pages[1]);
  546. assert_eq!(override_page_template.meta.template, Some("page_template_override.html".into()));
  547. assert_eq!(override_page_template.meta.title, Some("Override".into()));
  548. // It should have applied recursively as well
  549. let another_section =
  550. library.get_section(&template_path.join("another_section").join("_index.md")).unwrap();
  551. assert_eq!(another_section.subsections.len(), 0);
  552. assert_eq!(another_section.pages.len(), 1);
  553. let changed_recursively = library.get_page_by_key(another_section.pages[0]);
  554. assert_eq!(changed_recursively.meta.template, Some("page_template.html".into()));
  555. assert_eq!(changed_recursively.meta.title, Some("Changed recursively".into()));
  556. // But it should not have override a children page_template
  557. let yet_another_section =
  558. library.get_section(&template_path.join("yet_another_section").join("_index.md")).unwrap();
  559. assert_eq!(yet_another_section.subsections.len(), 0);
  560. assert_eq!(yet_another_section.pages.len(), 1);
  561. let child = library.get_page_by_key(yet_another_section.pages[0]);
  562. assert_eq!(child.meta.template, Some("page_template_child.html".into()));
  563. assert_eq!(child.meta.title, Some("Local section override".into()));
  564. }
  565. // https%3A//github.com/getzola/zola/issues/571
  566. #[test]
  567. fn can_build_site_custom_builtins_from_theme() {
  568. let (_, _tmp_dir, public) = build_site("test_site");
  569. assert!(&public.exists());
  570. // 404.html is a theme template.
  571. assert!(file_exists!(public, "404.html"));
  572. assert!(file_contains!(public, "404.html", "Oops"));
  573. }
  574. #[test]
  575. fn can_ignore_markdown_content() {
  576. let (_, _tmp_dir, public) = build_site("test_site");
  577. assert!(!file_exists!(public, "posts/ignored/index.html"));
  578. }