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.

695 lines
25KB

  1. use std::collections::HashMap;
  2. use std::fs::{remove_dir_all, copy, create_dir_all};
  3. use std::path::{Path, PathBuf};
  4. use glob::glob;
  5. use tera::{Tera, Context};
  6. use walkdir::WalkDir;
  7. use errors::{Result, ResultExt};
  8. use config::{Config, get_config};
  9. use fs::{create_file, create_directory, ensure_directory_exists};
  10. use content::{Page, Section, Paginator, SortBy, Taxonomy, populate_previous_and_next_pages, sort_pages};
  11. use templates::{GUTENBERG_TERA, global_fns, render_redirect_template};
  12. use front_matter::InsertAnchor;
  13. use rayon::prelude::*;
  14. #[derive(Debug)]
  15. pub struct Site {
  16. /// The base path of the gutenberg site
  17. pub base_path: PathBuf,
  18. /// The parsed config for the site
  19. pub config: Config,
  20. pub pages: HashMap<PathBuf, Page>,
  21. pub sections: HashMap<PathBuf, Section>,
  22. pub tera: Tera,
  23. live_reload: bool,
  24. output_path: PathBuf,
  25. static_path: PathBuf,
  26. pub tags: Option<Taxonomy>,
  27. pub categories: Option<Taxonomy>,
  28. /// A map of all .md files (section and pages) and their permalink
  29. /// We need that if there are relative links in the content that need to be resolved
  30. pub permalinks: HashMap<String, String>,
  31. }
  32. impl Site {
  33. /// Parse a site at the given path. Defaults to the current dir
  34. /// Passing in a path is only used in tests
  35. pub fn new<P: AsRef<Path>>(path: P, config_file: &str) -> Result<Site> {
  36. let path = path.as_ref();
  37. let tpl_glob = format!("{}/{}", path.to_string_lossy().replace("\\", "/"), "templates/**/*.*ml");
  38. let mut tera = Tera::new(&tpl_glob).chain_err(|| "Error parsing templates")?;
  39. tera.extend(&GUTENBERG_TERA)?;
  40. let site = Site {
  41. base_path: path.to_path_buf(),
  42. config: get_config(path, config_file),
  43. pages: HashMap::new(),
  44. sections: HashMap::new(),
  45. tera: tera,
  46. live_reload: false,
  47. output_path: path.join("public"),
  48. static_path: path.join("static"),
  49. tags: None,
  50. categories: None,
  51. permalinks: HashMap::new(),
  52. };
  53. Ok(site)
  54. }
  55. /// What the function name says
  56. pub fn enable_live_reload(&mut self) {
  57. self.live_reload = true;
  58. }
  59. /// Get all the orphan (== without section) pages in the site
  60. pub fn get_all_orphan_pages(&self) -> Vec<&Page> {
  61. let mut pages_in_sections = vec![];
  62. let mut orphans = vec![];
  63. for s in self.sections.values() {
  64. pages_in_sections.extend(s.all_pages_path());
  65. }
  66. for page in self.pages.values() {
  67. if !pages_in_sections.contains(&page.file.path) {
  68. orphans.push(page);
  69. }
  70. }
  71. orphans
  72. }
  73. /// Used by tests to change the output path to a tmp dir
  74. #[doc(hidden)]
  75. pub fn set_output_path<P: AsRef<Path>>(&mut self, path: P) {
  76. self.output_path = path.as_ref().to_path_buf();
  77. }
  78. /// Reads all .md files in the `content` directory and create pages/sections
  79. /// out of them
  80. pub fn load(&mut self) -> Result<()> {
  81. let base_path = self.base_path.to_string_lossy().replace("\\", "/");
  82. let content_glob = format!("{}/{}", base_path, "content/**/*.md");
  83. let (section_entries, page_entries): (Vec<_>, Vec<_>) = glob(&content_glob)
  84. .unwrap()
  85. .filter_map(|e| e.ok())
  86. .partition(|ref entry| entry.as_path().file_name().unwrap() == "_index.md");
  87. let sections = {
  88. let config = &self.config;
  89. section_entries
  90. .into_par_iter()
  91. .filter(|entry| entry.as_path().file_name().unwrap() == "_index.md")
  92. .map(|entry| {
  93. let path = entry.as_path();
  94. Section::from_file(path, &config)
  95. }).collect::<Vec<_>>()
  96. };
  97. let pages = {
  98. let config = &self.config;
  99. page_entries
  100. .into_par_iter()
  101. .filter(|entry| entry.as_path().file_name().unwrap() != "_index.md")
  102. .map(|entry| {
  103. let path = entry.as_path();
  104. Page::from_file(path, &config)
  105. }).collect::<Vec<_>>()
  106. };
  107. // Kinda duplicated code for add_section/add_page but necessary to do it that
  108. // way because of the borrow checker
  109. for section in sections {
  110. let s = section?;
  111. self.add_section(s, false)?;
  112. }
  113. for page in pages {
  114. let p = page?;
  115. self.add_page(p, false)?;
  116. }
  117. // Insert a default index section if necessary so we don't need to create
  118. // a _index.md to render the index page
  119. let index_path = self.base_path.join("content").join("_index.md");
  120. if !self.sections.contains_key(&index_path) {
  121. let mut index_section = Section::default();
  122. index_section.permalink = self.config.make_permalink("");
  123. self.sections.insert(index_path, index_section);
  124. }
  125. // Silly thing needed to make the borrow checker happy
  126. let mut pages_insert_anchors = HashMap::new();
  127. for page in self.pages.values() {
  128. pages_insert_anchors.insert(page.file.path.clone(), self.find_parent_section_insert_anchor(&page.file.parent.clone()));
  129. }
  130. {
  131. // Another silly thing needed to not borrow &self in parallel and
  132. // make the borrow checker happy
  133. let permalinks = &self.permalinks;
  134. let tera = &self.tera;
  135. let config = &self.config;
  136. self.pages.par_iter_mut()
  137. .map(|(_, page)| page)
  138. .map(|page| {
  139. let insert_anchor = pages_insert_anchors[&page.file.path];
  140. page.render_markdown(&permalinks, &tera, &config, insert_anchor)
  141. })
  142. .fold(|| Ok(()), Result::and)
  143. .reduce(|| Ok(()), Result::and)?;
  144. self.sections.par_iter_mut()
  145. .map(|(_, section)| section)
  146. .map(|section| section.render_markdown(permalinks, tera, config))
  147. .fold(|| Ok(()), Result::and)
  148. .reduce(|| Ok(()), Result::and)?;
  149. }
  150. self.populate_sections();
  151. self.populate_tags_and_categories();
  152. self.tera.register_global_function("get_page", global_fns::make_get_page(&self.pages));
  153. self.tera.register_global_function("get_section", global_fns::make_get_section(&self.sections));
  154. self.register_get_url_fn();
  155. Ok(())
  156. }
  157. /// Separate fn as it can be called in the serve command
  158. pub fn register_get_url_fn(&mut self) {
  159. self.tera.register_global_function("get_url", global_fns::make_get_url(self.permalinks.clone()));
  160. }
  161. /// Add a page to the site
  162. /// The `render` parameter is used in the serve command, when rebuilding a page.
  163. /// If `true`, it will also render the markdown for that page
  164. /// Returns the previous page struct if there was one
  165. pub fn add_page(&mut self, page: Page, render: bool) -> Result<Option<Page>> {
  166. let path = page.file.path.clone();
  167. self.permalinks.insert(page.file.relative.clone(), page.permalink.clone());
  168. let prev = self.pages.insert(page.file.path.clone(), page);
  169. if render {
  170. let insert_anchor = self.find_parent_section_insert_anchor(&self.pages[&path].file.parent);
  171. let mut page = self.pages.get_mut(&path).unwrap();
  172. page.render_markdown(&self.permalinks, &self.tera, &self.config, insert_anchor)?;
  173. }
  174. Ok(prev)
  175. }
  176. /// Add a section to the site
  177. /// The `render` parameter is used in the serve command, when rebuilding a page.
  178. /// If `true`, it will also render the markdown for that page
  179. /// Returns the previous section struct if there was one
  180. pub fn add_section(&mut self, section: Section, render: bool) -> Result<Option<Section>> {
  181. let path = section.file.path.clone();
  182. self.permalinks.insert(section.file.relative.clone(), section.permalink.clone());
  183. let prev = self.sections.insert(section.file.path.clone(), section);
  184. if render {
  185. let mut section = self.sections.get_mut(&path).unwrap();
  186. section.render_markdown(&self.permalinks, &self.tera, &self.config)?;
  187. }
  188. Ok(prev)
  189. }
  190. /// Finds the insert_anchor for the parent section of the directory at `path`.
  191. /// Defaults to `AnchorInsert::None` if no parent section found
  192. pub fn find_parent_section_insert_anchor(&self, parent_path: &PathBuf) -> InsertAnchor {
  193. match self.sections.get(&parent_path.join("_index.md")) {
  194. Some(s) => s.meta.insert_anchor.unwrap(),
  195. None => InsertAnchor::None
  196. }
  197. }
  198. /// Find out the direct subsections of each subsection if there are some
  199. /// as well as the pages for each section
  200. pub fn populate_sections(&mut self) {
  201. let mut grandparent_paths = HashMap::new();
  202. for section in self.sections.values_mut() {
  203. if let Some(ref grand_parent) = section.file.grand_parent {
  204. grandparent_paths.entry(grand_parent.to_path_buf()).or_insert_with(|| vec![]).push(section.clone());
  205. }
  206. // Make sure the pages of a section are empty since we can call that many times on `serve`
  207. section.pages = vec![];
  208. section.ignored_pages = vec![];
  209. }
  210. for page in self.pages.values() {
  211. let parent_section_path = page.file.parent.join("_index.md");
  212. if self.sections.contains_key(&parent_section_path) {
  213. self.sections.get_mut(&parent_section_path).unwrap().pages.push(page.clone());
  214. }
  215. }
  216. for section in self.sections.values_mut() {
  217. match grandparent_paths.get(&section.file.parent) {
  218. Some(paths) => section.subsections.extend(paths.clone()),
  219. None => continue,
  220. };
  221. }
  222. self.sort_sections_pages(None);
  223. }
  224. /// Sorts the pages of the section at the given path
  225. /// By default will sort all sections but can be made to only sort a single one by providing a path
  226. pub fn sort_sections_pages(&mut self, only: Option<&Path>) {
  227. for (path, section) in &mut self.sections {
  228. if let Some(p) = only {
  229. if p != path {
  230. continue;
  231. }
  232. }
  233. let (sorted_pages, cannot_be_sorted_pages) = sort_pages(section.pages.clone(), section.meta.sort_by());
  234. section.pages = populate_previous_and_next_pages(&sorted_pages);
  235. section.ignored_pages = cannot_be_sorted_pages;
  236. }
  237. }
  238. /// Find all the tags and categories if it's asked in the config
  239. pub fn populate_tags_and_categories(&mut self) {
  240. let generate_tags_pages = self.config.generate_tags_pages.unwrap();
  241. let generate_categories_pages = self.config.generate_categories_pages.unwrap();
  242. if !generate_tags_pages && !generate_categories_pages {
  243. return;
  244. }
  245. // TODO: can we pass a reference?
  246. let (tags, categories) = Taxonomy::find_tags_and_categories(
  247. self.pages.values().cloned().collect::<Vec<_>>()
  248. );
  249. if generate_tags_pages {
  250. self.tags = Some(tags);
  251. }
  252. if generate_categories_pages {
  253. self.categories = Some(categories);
  254. }
  255. }
  256. /// Inject live reload script tag if in live reload mode
  257. fn inject_livereload(&self, html: String) -> String {
  258. if self.live_reload {
  259. return html.replace(
  260. "</body>",
  261. r#"<script src="/livereload.js?port=1112&mindelay=10"></script></body>"#
  262. );
  263. }
  264. html
  265. }
  266. /// Copy static file to public directory.
  267. pub fn copy_static_file<P: AsRef<Path>>(&self, path: P) -> Result<()> {
  268. let relative_path = path.as_ref().strip_prefix(&self.static_path).unwrap();
  269. let target_path = self.output_path.join(relative_path);
  270. if let Some(parent_directory) = target_path.parent() {
  271. create_dir_all(parent_directory)?;
  272. }
  273. copy(path.as_ref(), &target_path)?;
  274. Ok(())
  275. }
  276. /// Copy the content of the `static` folder into the `public` folder
  277. pub fn copy_static_directory(&self) -> Result<()> {
  278. for entry in WalkDir::new(&self.static_path).into_iter().filter_map(|e| e.ok()) {
  279. let relative_path = entry.path().strip_prefix(&self.static_path).unwrap();
  280. let target_path = self.output_path.join(relative_path);
  281. if entry.path().is_dir() {
  282. if !target_path.exists() {
  283. create_directory(&target_path)?;
  284. }
  285. } else {
  286. let entry_fullpath = self.base_path.join(entry.path());
  287. self.copy_static_file(entry_fullpath)?;
  288. }
  289. }
  290. Ok(())
  291. }
  292. /// Deletes the `public` directory if it exists
  293. pub fn clean(&self) -> Result<()> {
  294. if self.output_path.exists() {
  295. // Delete current `public` directory so we can start fresh
  296. remove_dir_all(&self.output_path).chain_err(|| "Couldn't delete `public` directory")?;
  297. }
  298. Ok(())
  299. }
  300. /// Renders a single content page
  301. pub fn render_page(&self, page: &Page, section: Option<&Section>) -> Result<()> {
  302. ensure_directory_exists(&self.output_path)?;
  303. // Copy the nesting of the content directory if we have sections for that page
  304. let mut current_path = self.output_path.to_path_buf();
  305. for component in page.path.split('/') {
  306. current_path.push(component);
  307. if !current_path.exists() {
  308. create_directory(&current_path)?;
  309. }
  310. }
  311. // Make sure the folder exists
  312. create_directory(&current_path)?;
  313. // Finally, create a index.html file there with the page rendered
  314. let output = page.render_html(&self.tera, &self.config, section)?;
  315. create_file(&current_path.join("index.html"), &self.inject_livereload(output))?;
  316. // Copy any asset we found previously into the same directory as the index.html
  317. for asset in &page.assets {
  318. let asset_path = asset.as_path();
  319. copy(&asset_path, &current_path.join(asset_path.file_name().unwrap()))?;
  320. }
  321. Ok(())
  322. }
  323. /// Deletes the `public` directory and builds the site
  324. pub fn build(&self) -> Result<()> {
  325. self.clean()?;
  326. // Render aliases first to allow overwriting
  327. self.render_aliases()?;
  328. self.render_sections()?;
  329. self.render_orphan_pages()?;
  330. self.render_sitemap()?;
  331. if self.config.generate_rss.unwrap() {
  332. self.render_rss_feed()?;
  333. }
  334. self.render_robots()?;
  335. // `render_categories` and `render_tags` will check whether the config allows
  336. // them to render or not
  337. self.render_categories()?;
  338. self.render_tags()?;
  339. self.copy_static_directory()
  340. }
  341. pub fn render_aliases(&self) -> Result<()> {
  342. for page in self.pages.values() {
  343. if let Some(ref aliases) = page.meta.aliases {
  344. for alias in aliases {
  345. let mut output_path = self.output_path.to_path_buf();
  346. for component in alias.split("/") {
  347. output_path.push(&component);
  348. if !output_path.exists() {
  349. create_directory(&output_path)?;
  350. }
  351. }
  352. create_file(&output_path.join("index.html"), &render_redirect_template(&page.permalink, &self.tera)?)?;
  353. }
  354. }
  355. }
  356. Ok(())
  357. }
  358. /// Renders robots.txt
  359. pub fn render_robots(&self) -> Result<()> {
  360. ensure_directory_exists(&self.output_path)?;
  361. create_file(
  362. &self.output_path.join("robots.txt"),
  363. &self.tera.render("robots.txt", &Context::new())?
  364. )
  365. }
  366. /// Renders all categories and the single category pages if there are some
  367. pub fn render_categories(&self) -> Result<()> {
  368. if let Some(ref categories) = self.categories {
  369. self.render_taxonomy(categories)?;
  370. }
  371. Ok(())
  372. }
  373. /// Renders all tags and the single tag pages if there are some
  374. pub fn render_tags(&self) -> Result<()> {
  375. if let Some(ref tags) = self.tags {
  376. self.render_taxonomy(tags)?;
  377. }
  378. Ok(())
  379. }
  380. fn render_taxonomy(&self, taxonomy: &Taxonomy) -> Result<()> {
  381. if taxonomy.items.is_empty() {
  382. return Ok(())
  383. }
  384. ensure_directory_exists(&self.output_path)?;
  385. let output_path = self.output_path.join(&taxonomy.get_list_name());
  386. let list_output = taxonomy.render_list(&self.tera, &self.config)?;
  387. create_directory(&output_path)?;
  388. create_file(&output_path.join("index.html"), &self.inject_livereload(list_output))?;
  389. for item in &taxonomy.items {
  390. let single_output = taxonomy.render_single_item(item, &self.tera, &self.config)?;
  391. create_directory(&output_path.join(&item.slug))?;
  392. create_file(
  393. &output_path.join(&item.slug).join("index.html"),
  394. &self.inject_livereload(single_output)
  395. )?;
  396. }
  397. Ok(())
  398. }
  399. /// What it says on the tin
  400. pub fn render_sitemap(&self) -> Result<()> {
  401. ensure_directory_exists(&self.output_path)?;
  402. let mut context = Context::new();
  403. context.add("pages", &self.pages.values().collect::<Vec<&Page>>());
  404. context.add("sections", &self.sections.values().collect::<Vec<&Section>>());
  405. let mut categories = vec![];
  406. if let Some(ref c) = self.categories {
  407. let name = c.get_list_name();
  408. categories.push(self.config.make_permalink(&name));
  409. for item in &c.items {
  410. categories.push(
  411. self.config.make_permalink(&format!("{}/{}", &name, item.slug))
  412. );
  413. }
  414. }
  415. context.add("categories", &categories);
  416. let mut tags = vec![];
  417. if let Some(ref t) = self.tags {
  418. let name = t.get_list_name();
  419. tags.push(self.config.make_permalink(&name));
  420. for item in &t.items {
  421. tags.push(
  422. self.config.make_permalink(&format!("{}/{}", &name, item.slug))
  423. );
  424. }
  425. }
  426. context.add("tags", &tags);
  427. let sitemap = self.tera.render("sitemap.xml", &context)?;
  428. create_file(&self.output_path.join("sitemap.xml"), &sitemap)?;
  429. Ok(())
  430. }
  431. pub fn render_rss_feed(&self) -> Result<()> {
  432. ensure_directory_exists(&self.output_path)?;
  433. let mut context = Context::new();
  434. let pages = self.pages.values()
  435. .filter(|p| p.meta.date.is_some())
  436. .take(self.config.rss_limit.unwrap()) // limit to the last n elements
  437. .cloned()
  438. .collect::<Vec<Page>>();
  439. // Don't generate a RSS feed if none of the pages has a date
  440. if pages.is_empty() {
  441. return Ok(());
  442. }
  443. context.add("last_build_date", &pages[0].meta.date);
  444. let (sorted_pages, _) = sort_pages(pages, SortBy::Date);
  445. context.add("pages", &sorted_pages);
  446. context.add("config", &self.config);
  447. let rss_feed_url = if self.config.base_url.ends_with('/') {
  448. format!("{}{}", self.config.base_url, "rss.xml")
  449. } else {
  450. format!("{}/{}", self.config.base_url, "rss.xml")
  451. };
  452. context.add("feed_url", &rss_feed_url);
  453. let sitemap = self.tera.render("rss.xml", &context)?;
  454. create_file(&self.output_path.join("rss.xml"), &sitemap)?;
  455. Ok(())
  456. }
  457. /// Create a hashmap of paths to section
  458. /// For example `content/posts/_index.md` key will be `posts`
  459. /// The index section will always be called `index` so don't use a path such as
  460. /// `content/index/_index.md` yourself
  461. fn get_sections_map(&self) -> HashMap<String, Section> {
  462. self.sections
  463. .values()
  464. .map(|s| (if s.is_index() { "index".to_string() } else { s.file.components.join("/") }, s.clone()))
  465. .collect()
  466. }
  467. /// Renders a single section
  468. pub fn render_section(&self, section: &Section, render_pages: bool) -> Result<()> {
  469. ensure_directory_exists(&self.output_path)?;
  470. let public = self.output_path.clone();
  471. let mut output_path = public.to_path_buf();
  472. for component in &section.file.components {
  473. output_path.push(component);
  474. if !output_path.exists() {
  475. create_directory(&output_path)?;
  476. }
  477. }
  478. if render_pages {
  479. for page in &section.pages {
  480. self.render_page(page, Some(section))?;
  481. }
  482. }
  483. if !section.meta.should_render() {
  484. return Ok(());
  485. }
  486. if section.meta.is_paginated() {
  487. self.render_paginated(&output_path, section)?;
  488. } else {
  489. let output = section.render_html(
  490. if section.is_index() { self.get_sections_map() } else { HashMap::new() },
  491. &self.tera,
  492. &self.config,
  493. )?;
  494. create_file(&output_path.join("index.html"), &self.inject_livereload(output))?;
  495. }
  496. Ok(())
  497. }
  498. pub fn render_index(&self) -> Result<()> {
  499. self.render_section(&self.sections[&self.base_path.join("content").join("_index.md")], false)
  500. }
  501. /// Renders all sections
  502. pub fn render_sections(&self) -> Result<()> {
  503. for section in self.sections.values() {
  504. self.render_section(section, true)?;
  505. }
  506. Ok(())
  507. }
  508. /// Renders all pages that do not belong to any sections
  509. pub fn render_orphan_pages(&self) -> Result<()> {
  510. ensure_directory_exists(&self.output_path)?;
  511. for page in self.get_all_orphan_pages() {
  512. self.render_page(page, None)?;
  513. }
  514. Ok(())
  515. }
  516. /// Renders a list of pages when the section/index is wanting pagination.
  517. fn render_paginated(&self, output_path: &Path, section: &Section) -> Result<()> {
  518. ensure_directory_exists(&self.output_path)?;
  519. let paginate_path = match section.meta.paginate_path {
  520. Some(ref s) => s.clone(),
  521. None => unreachable!()
  522. };
  523. let paginator = Paginator::new(&section.pages, section);
  524. for (i, pager) in paginator.pagers.iter().enumerate() {
  525. let folder_path = output_path.join(&paginate_path);
  526. let page_path = folder_path.join(&format!("{}", i + 1));
  527. create_directory(&folder_path)?;
  528. create_directory(&page_path)?;
  529. let output = paginator.render_pager(pager, self)?;
  530. if i > 0 {
  531. create_file(&page_path.join("index.html"), &self.inject_livereload(output))?;
  532. } else {
  533. create_file(&output_path.join("index.html"), &self.inject_livereload(output))?;
  534. create_file(&page_path.join("index.html"), &render_redirect_template(&section.permalink, &self.tera)?)?;
  535. }
  536. }
  537. Ok(())
  538. }
  539. }
  540. /// Resolves an internal link (of the `./posts/something.md#hey` sort) to its absolute link
  541. pub fn resolve_internal_link(link: &str, permalinks: &HashMap<String, String>) -> Result<String> {
  542. // First we remove the ./ since that's gutenberg specific
  543. let clean_link = link.replacen("./", "", 1);
  544. // Then we remove any potential anchor
  545. // parts[0] will be the file path and parts[1] the anchor if present
  546. let parts = clean_link.split('#').collect::<Vec<_>>();
  547. match permalinks.get(parts[0]) {
  548. Some(p) => {
  549. if parts.len() > 1 {
  550. Ok(format!("{}#{}", p, parts[1]))
  551. } else {
  552. Ok(p.to_string())
  553. }
  554. },
  555. None => bail!(format!("Relative link {} not found.", link)),
  556. }
  557. }
  558. #[cfg(test)]
  559. mod tests {
  560. use std::collections::HashMap;
  561. use super::resolve_internal_link;
  562. #[test]
  563. fn can_resolve_valid_internal_link() {
  564. let mut permalinks = HashMap::new();
  565. permalinks.insert("pages/about.md".to_string(), "https://vincent.is/about".to_string());
  566. let res = resolve_internal_link("./pages/about.md", &permalinks).unwrap();
  567. assert_eq!(res, "https://vincent.is/about");
  568. }
  569. #[test]
  570. fn can_resolve_internal_links_with_anchors() {
  571. let mut permalinks = HashMap::new();
  572. permalinks.insert("pages/about.md".to_string(), "https://vincent.is/about".to_string());
  573. let res = resolve_internal_link("./pages/about.md#hello", &permalinks).unwrap();
  574. assert_eq!(res, "https://vincent.is/about#hello");
  575. }
  576. #[test]
  577. fn errors_resolve_inexistant_internal_link() {
  578. let res = resolve_internal_link("./pages/about.md#hello", &HashMap::new());
  579. assert!(res.is_err());
  580. }
  581. }