Fix internal links to content dir not working

Closes #275
This commit is contained in:
Vincent Prouillet 2018-03-29 14:55:25 +02:00
parent 9c0dd95bdb
commit d9dbf4d567
4 changed files with 16 additions and 1 deletions

View file

@ -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)

View file

@ -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" {

View file

@ -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();

View file

@ -6,3 +6,5 @@ date = 2016-03-01
{{ theme_shortcode() }}
Link to [root](./hello.md).