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.

631 lines
24KB

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