@@ -21,6 +21,7 @@ | |||||
- Add 1337 color scheme | - Add 1337 color scheme | ||||
- Defaults to compressed Sass output | - Defaults to compressed Sass output | ||||
- Fix regression wrt co-located assets slug detecting | - Fix regression wrt co-located assets slug detecting | ||||
- Rename `url` from page front-matter to `path` to be consistent | |||||
## 0.1.3 (2017-08-31) | ## 0.1.3 (2017-08-31) | ||||
@@ -98,8 +98,9 @@ impl Page { | |||||
} | } | ||||
}; | }; | ||||
if let Some(ref u) = page.meta.url { | |||||
page.path = u.trim().to_string(); | |||||
if let Some(ref p) = page.meta.path { | |||||
page.path = p.trim().trim_left_matches('/').to_string(); | |||||
} else { | } else { | ||||
page.path = if page.file.components.is_empty() { | page.path = if page.file.components.is_empty() { | ||||
page.slug.clone() | page.slug.clone() | ||||
@@ -110,6 +111,7 @@ impl Page { | |||||
if !page.path.ends_with('/') { | if !page.path.ends_with('/') { | ||||
page.path = format!("{}/", page.path); | page.path = format!("{}/", page.path); | ||||
} | } | ||||
page.permalink = config.make_permalink(&page.path); | page.permalink = config.make_permalink(&page.path); | ||||
Ok(page) | Ok(page) | ||||
@@ -281,6 +283,36 @@ Hello world"#; | |||||
assert_eq!(page.permalink, config.make_permalink("hello-world")); | assert_eq!(page.permalink, config.make_permalink("hello-world")); | ||||
} | } | ||||
#[test] | |||||
fn can_make_url_from_path() { | |||||
let content = r#" | |||||
+++ | |||||
path = "hello-world" | |||||
+++ | |||||
Hello world"#; | |||||
let config = Config::default(); | |||||
let res = Page::parse(Path::new("content/posts/intro/start.md"), content, &config); | |||||
assert!(res.is_ok()); | |||||
let page = res.unwrap(); | |||||
assert_eq!(page.path, "hello-world/"); | |||||
assert_eq!(page.permalink, config.make_permalink("hello-world")); | |||||
} | |||||
#[test] | |||||
fn can_make_url_from_path_starting_slash() { | |||||
let content = r#" | |||||
+++ | |||||
path = "/hello-world" | |||||
+++ | |||||
Hello world"#; | |||||
let config = Config::default(); | |||||
let res = Page::parse(Path::new("content/posts/intro/start.md"), content, &config); | |||||
assert!(res.is_ok()); | |||||
let page = res.unwrap(); | |||||
assert_eq!(page.path, "hello-world/"); | |||||
assert_eq!(page.permalink, config.make_permalink("hello-world")); | |||||
} | |||||
#[test] | #[test] | ||||
fn errors_on_invalid_front_matter_format() { | fn errors_on_invalid_front_matter_format() { | ||||
// missing starting +++ | // missing starting +++ | ||||
@@ -20,10 +20,10 @@ pub struct PageFrontMatter { | |||||
/// The page slug. Will be used instead of the filename if present | /// The page slug. Will be used instead of the filename if present | ||||
/// Can't be an empty string if present | /// Can't be an empty string if present | ||||
pub slug: Option<String>, | pub slug: Option<String>, | ||||
/// The url the page appears at, overrides the slug if set in the front-matter | |||||
/// The path the page appears at, overrides the slug if set in the front-matter | |||||
/// otherwise is set after parsing front matter and sections | /// otherwise is set after parsing front matter and sections | ||||
/// Can't be an empty string if present | /// Can't be an empty string if present | ||||
pub url: Option<String>, | |||||
pub path: Option<String>, | |||||
/// Tags, not to be confused with categories | /// Tags, not to be confused with categories | ||||
pub tags: Option<Vec<String>>, | pub tags: Option<Vec<String>>, | ||||
/// Only one category allowed. Can't be an empty string if present | /// Only one category allowed. Can't be an empty string if present | ||||
@@ -56,9 +56,9 @@ impl PageFrontMatter { | |||||
} | } | ||||
} | } | ||||
if let Some(ref url) = f.url { | |||||
if url == "" { | |||||
bail!("`url` can't be empty if present") | |||||
if let Some(ref path) = f.path { | |||||
if path == "" { | |||||
bail!("`path` can't be empty if present") | |||||
} | } | ||||
} | } | ||||
@@ -109,7 +109,7 @@ impl Default for PageFrontMatter { | |||||
date: None, | date: None, | ||||
draft: None, | draft: None, | ||||
slug: None, | slug: None, | ||||
url: None, | |||||
path: None, | |||||
tags: None, | tags: None, | ||||
category: None, | category: None, | ||||
order: None, | order: None, | ||||
@@ -189,11 +189,11 @@ mod tests { | |||||
} | } | ||||
#[test] | #[test] | ||||
fn errors_on_present_but_empty_url() { | |||||
fn errors_on_present_but_empty_path() { | |||||
let content = r#" | let content = r#" | ||||
title = "Hello" | title = "Hello" | ||||
description = "hey there" | description = "hey there" | ||||
url = """#; | |||||
path = """#; | |||||
let res = PageFrontMatter::parse(content); | let res = PageFrontMatter::parse(content); | ||||
assert!(res.is_err()); | assert!(res.is_err()); | ||||
} | } | ||||
@@ -1,7 +1,7 @@ | |||||
+++ | +++ | ||||
title = "Fixed URL" | title = "Fixed URL" | ||||
description = "" | description = "" | ||||
url = "a-fixed-url" | |||||
path = "a-fixed-url" | |||||
date = "2017-02-01" | date = "2017-02-01" | ||||
+++ | +++ | ||||
@@ -32,10 +32,11 @@ draft = false | |||||
# It will still use the section path though | # It will still use the section path though | ||||
slug = "" | slug = "" | ||||
# The URL the content will appear at | |||||
# If set, it cannot be an empty string and will override both `slug` and the filename | |||||
# and the sections' path won't be used | |||||
url = "" | |||||
# The path the content will appear at | |||||
# If set, it cannot be an empty string and will override both `slug` and the filename. | |||||
# The sections' path won't be used. | |||||
# It should not start with a `/` and the slash will be removed if it does | |||||
path = "" | |||||
# An array of strings allowing you to group pages with them | # An array of strings allowing you to group pages with them | ||||
tags = [] | tags = [] | ||||