Browse Source

url -> path in page front-matter

index-subcmd
Vincent Prouillet 6 years ago
parent
commit
f26b9d53bd
5 changed files with 49 additions and 15 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +34
    -2
      components/content/src/page.rs
  3. +8
    -8
      components/front_matter/src/page.rs
  4. +1
    -1
      components/site/test_site/content/posts/fixed-url.md
  5. +5
    -4
      docs/content/documentation/content/page.md

+ 1
- 0
CHANGELOG.md View File

@@ -21,6 +21,7 @@
- Add 1337 color scheme
- Defaults to compressed Sass output
- 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)



+ 34
- 2
components/content/src/page.rs View File

@@ -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 {
page.path = if page.file.components.is_empty() {
page.slug.clone()
@@ -110,6 +111,7 @@ impl Page {
if !page.path.ends_with('/') {
page.path = format!("{}/", page.path);
}

page.permalink = config.make_permalink(&page.path);

Ok(page)
@@ -281,6 +283,36 @@ 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]
fn errors_on_invalid_front_matter_format() {
// missing starting +++


+ 8
- 8
components/front_matter/src/page.rs View File

@@ -20,10 +20,10 @@ pub struct PageFrontMatter {
/// The page slug. Will be used instead of the filename if present
/// Can't be an empty string if present
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
/// Can't be an empty string if present
pub url: Option<String>,
pub path: Option<String>,
/// Tags, not to be confused with categories
pub tags: Option<Vec<String>>,
/// 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,
draft: None,
slug: None,
url: None,
path: None,
tags: None,
category: None,
order: None,
@@ -189,11 +189,11 @@ mod tests {
}

#[test]
fn errors_on_present_but_empty_url() {
fn errors_on_present_but_empty_path() {
let content = r#"
title = "Hello"
description = "hey there"
url = """#;
path = """#;
let res = PageFrontMatter::parse(content);
assert!(res.is_err());
}


+ 1
- 1
components/site/test_site/content/posts/fixed-url.md View File

@@ -1,7 +1,7 @@
+++
title = "Fixed URL"
description = ""
url = "a-fixed-url"
path = "a-fixed-url"
date = "2017-02-01"
+++



+ 5
- 4
docs/content/documentation/content/page.md View File

@@ -32,10 +32,11 @@ draft = false
# It will still use the section path though
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
tags = []


Loading…
Cancel
Save