From d9dbf4d5670f034f5509c8b59fd610f059dd6553 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Thu, 29 Mar 2018 14:55:25 +0200 Subject: [PATCH] Fix internal links to content dir not working Closes #275 --- CHANGELOG.md | 1 + components/content/src/file_info.rs | 6 +++++- components/utils/src/site.rs | 8 ++++++++ test_site/content/posts/draft.md | 2 ++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d3701881..069c7903 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ to the public directory want to link directly to it - Fix many shortcode parsing issues - Correctly copy themes shortcodes so they are useable in content +- Fix internal links not working for markdown files directly in `content` directory ## 0.3.2 (2018-03-05) diff --git a/components/content/src/file_info.rs b/components/content/src/file_info.rs index d3666652..b098dc64 100644 --- a/components/content/src/file_info.rs +++ b/components/content/src/file_info.rs @@ -48,7 +48,11 @@ impl FileInfo { let mut parent = file_path.parent().unwrap().to_path_buf(); let name = path.file_stem().unwrap().to_string_lossy().to_string(); let mut components = find_content_components(&file_path); - let relative = format!("{}/{}.md", components.join("/"), name); + let relative = if !components.is_empty() { + format!("{}/{}.md", components.join("/"), name) + } else { + format!("{}.md", name) + }; // If we have a folder with an asset, don't consider it as a component if !components.is_empty() && name == "index" { diff --git a/components/utils/src/site.rs b/components/utils/src/site.rs index bbf7ffd7..f73166a1 100644 --- a/components/utils/src/site.rs +++ b/components/utils/src/site.rs @@ -46,6 +46,14 @@ mod tests { assert_eq!(res, "https://vincent.is/about"); } + #[test] + fn can_resolve_valid_root_internal_link() { + let mut permalinks = HashMap::new(); + permalinks.insert("about.md".to_string(), "https://vincent.is/about".to_string()); + let res = resolve_internal_link("./about.md", &permalinks).unwrap(); + assert_eq!(res, "https://vincent.is/about"); + } + #[test] fn can_resolve_internal_links_with_anchors() { let mut permalinks = HashMap::new(); diff --git a/test_site/content/posts/draft.md b/test_site/content/posts/draft.md index 2f35fbb4..6eb9a2c8 100644 --- a/test_site/content/posts/draft.md +++ b/test_site/content/posts/draft.md @@ -6,3 +6,5 @@ date = 2016-03-01 {{ theme_shortcode() }} + +Link to [root](./hello.md).