Make title and description optional in frontmatter
This commit is contained in:
parent
dd9bab3142
commit
03aa83af6a
|
@ -3,6 +3,7 @@
|
||||||
## 0.0.5 (unreleased)
|
## 0.0.5 (unreleased)
|
||||||
|
|
||||||
- Fix XML templates overriding and reloading
|
- Fix XML templates overriding and reloading
|
||||||
|
- `title` and `description` are now optional in the front matter
|
||||||
|
|
||||||
## 0.0.4 (2017-04-23)
|
## 0.0.4 (2017-04-23)
|
||||||
|
|
||||||
|
|
12
README.md
12
README.md
|
@ -80,8 +80,10 @@ description = "Some meta info"
|
||||||
A simple page with fixed url
|
A simple page with fixed url
|
||||||
```
|
```
|
||||||
|
|
||||||
A front-matter requires a title, a description and has the following optional variables:
|
A front-matter has only optional variables:
|
||||||
|
|
||||||
|
- title
|
||||||
|
- description
|
||||||
- date: a YYYY-MM-DD or RFC339 formatted date
|
- date: a YYYY-MM-DD or RFC339 formatted date
|
||||||
- slug: what slug to use in the url
|
- slug: what slug to use in the url
|
||||||
- url: this overrides the slug and make this page accessible at `{config.base_url}/{url}`
|
- url: this overrides the slug and make this page accessible at `{config.base_url}/{url}`
|
||||||
|
@ -90,6 +92,7 @@ A front-matter requires a title, a description and has the following optional va
|
||||||
- draft: whether the post is a draft or not
|
- draft: whether the post is a draft or not
|
||||||
- template: if you want to change the template used to render that specific page
|
- template: if you want to change the template used to render that specific page
|
||||||
|
|
||||||
|
Even if your front-matter is empty, you will need to put the `+++`.
|
||||||
You can also, like in the config, add your own variables in a `[extra]` table.
|
You can also, like in the config, add your own variables in a `[extra]` table.
|
||||||
The front-matter will be accessible in templates at the `page.meta` field.
|
The front-matter will be accessible in templates at the `page.meta` field.
|
||||||
|
|
||||||
|
@ -114,11 +117,9 @@ This `_index.md` file needs to include a front-matter as well, but won't have co
|
||||||
```md
|
```md
|
||||||
+++
|
+++
|
||||||
title = "Tutorials"
|
title = "Tutorials"
|
||||||
description = ""
|
|
||||||
+++
|
+++
|
||||||
```
|
```
|
||||||
Both `title` and `description` are mandatory, you can also set the `template` variable to change
|
You can also set the `template` variable to change which template will be used to render that section.
|
||||||
which template will be used to render that section.
|
|
||||||
|
|
||||||
Sections will also automatically pick up their subsections, allowing you to make some complex pages layout and
|
Sections will also automatically pick up their subsections, allowing you to make some complex pages layout and
|
||||||
table of contents.
|
table of contents.
|
||||||
|
@ -152,8 +153,7 @@ built-in:
|
||||||
- solarized-dark
|
- solarized-dark
|
||||||
- solarized-light
|
- solarized-light
|
||||||
|
|
||||||
### Internal
|
### Internal links
|
||||||
s
|
|
||||||
You can have internal links in your markdown that will be replaced with the full URL when rendering.
|
You can have internal links in your markdown that will be replaced with the full URL when rendering.
|
||||||
To do so, use the normal markdown link syntax, start the link with `./` and point to the `.md` file you want
|
To do so, use the normal markdown link syntax, start the link with `./` and point to the `.md` file you want
|
||||||
to link to. The path to the file starts from the `content` directory.
|
to link to. The path to the file starts from the `content` directory.
|
||||||
|
|
|
@ -18,15 +18,10 @@ lazy_static! {
|
||||||
/// The front matter of every page
|
/// The front matter of every page
|
||||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct FrontMatter {
|
pub struct FrontMatter {
|
||||||
// Mandatory fields
|
|
||||||
|
|
||||||
/// <title> of the page
|
/// <title> of the page
|
||||||
pub title: String,
|
pub title: Option<String>,
|
||||||
/// Description that appears when linked, e.g. on twitter
|
/// Description in <meta> that appears when linked, e.g. on twitter
|
||||||
pub description: String,
|
pub description: Option<String>,
|
||||||
|
|
||||||
// Optional stuff
|
|
||||||
|
|
||||||
/// Date if we want to order pages (ie blog post)
|
/// Date if we want to order pages (ie blog post)
|
||||||
pub date: Option<String>,
|
pub date: Option<String>,
|
||||||
/// The page slug. Will be used instead of the filename if present
|
/// The page slug. Will be used instead of the filename if present
|
||||||
|
|
|
@ -16,8 +16,8 @@ description = "hey there""#;
|
||||||
println!("{:?}", res);
|
println!("{:?}", res);
|
||||||
assert!(res.is_ok());
|
assert!(res.is_ok());
|
||||||
let res = res.unwrap();
|
let res = res.unwrap();
|
||||||
assert_eq!(res.title, "Hello".to_string());
|
assert_eq!(res.title.unwrap(), "Hello".to_string());
|
||||||
assert_eq!(res.description, "hey there".to_string());
|
assert_eq!(res.description.unwrap(), "hey there".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -31,7 +31,7 @@ tags = ["rust", "html"]"#;
|
||||||
assert!(res.is_ok());
|
assert!(res.is_ok());
|
||||||
let res = res.unwrap();
|
let res = res.unwrap();
|
||||||
|
|
||||||
assert_eq!(res.title, "Hello".to_string());
|
assert_eq!(res.title.unwrap(), "Hello".to_string());
|
||||||
assert_eq!(res.slug.unwrap(), "hello-world".to_string());
|
assert_eq!(res.slug.unwrap(), "hello-world".to_string());
|
||||||
assert_eq!(res.tags.unwrap(), ["rust".to_string(), "html".to_string()]);
|
assert_eq!(res.tags.unwrap(), ["rust".to_string(), "html".to_string()]);
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ authors = ["Bob", "Alice"]"#;
|
||||||
assert!(res.is_ok());
|
assert!(res.is_ok());
|
||||||
let res = res.unwrap();
|
let res = res.unwrap();
|
||||||
|
|
||||||
assert_eq!(res.title, "Hello".to_string());
|
assert_eq!(res.title.unwrap(), "Hello".to_string());
|
||||||
assert_eq!(res.slug.unwrap(), "hello-world".to_string());
|
assert_eq!(res.slug.unwrap(), "hello-world".to_string());
|
||||||
let extra = res.extra.unwrap();
|
let extra = res.extra.unwrap();
|
||||||
assert_eq!(extra["language"], to_value("en").unwrap());
|
assert_eq!(extra["language"], to_value("en").unwrap());
|
||||||
|
@ -87,13 +87,6 @@ fn test_errors_with_invalid_front_matter() {
|
||||||
assert!(res.is_err());
|
assert!(res.is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_errors_with_missing_required_value_front_matter() {
|
|
||||||
let content = r#"title = """#;
|
|
||||||
let res = FrontMatter::parse(content);
|
|
||||||
assert!(res.is_err());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_errors_on_non_string_tag() {
|
fn test_errors_on_non_string_tag() {
|
||||||
let content = r#"
|
let content = r#"
|
||||||
|
@ -168,7 +161,7 @@ Hello
|
||||||
"#;
|
"#;
|
||||||
let (front_matter, content) = split_content(Path::new(""), content).unwrap();
|
let (front_matter, content) = split_content(Path::new(""), content).unwrap();
|
||||||
assert_eq!(content, "Hello\n");
|
assert_eq!(content, "Hello\n");
|
||||||
assert_eq!(front_matter.title, "Title");
|
assert_eq!(front_matter.title.unwrap(), "Title");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -181,7 +174,7 @@ date = "2002/10/12"
|
||||||
+++"#;
|
+++"#;
|
||||||
let (front_matter, content) = split_content(Path::new(""), content).unwrap();
|
let (front_matter, content) = split_content(Path::new(""), content).unwrap();
|
||||||
assert_eq!(content, "");
|
assert_eq!(content, "");
|
||||||
assert_eq!(front_matter.title, "Title");
|
assert_eq!(front_matter.title.unwrap(), "Title");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -195,7 +188,7 @@ date = "2002-10-02T15:00:00Z"
|
||||||
+++"#;
|
+++"#;
|
||||||
let (front_matter, content) = split_content(Path::new(""), content).unwrap();
|
let (front_matter, content) = split_content(Path::new(""), content).unwrap();
|
||||||
assert_eq!(content, "+++");
|
assert_eq!(content, "+++");
|
||||||
assert_eq!(front_matter.title, "Title");
|
assert_eq!(front_matter.title.unwrap(), "Title");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -26,7 +26,7 @@ Hello world"#;
|
||||||
let mut page = res.unwrap();
|
let mut page = res.unwrap();
|
||||||
page.render_markdown(&HashMap::default(), &Tera::default(), &Config::default()).unwrap();
|
page.render_markdown(&HashMap::default(), &Tera::default(), &Config::default()).unwrap();
|
||||||
|
|
||||||
assert_eq!(page.meta.title, "Hello".to_string());
|
assert_eq!(page.meta.title.unwrap(), "Hello".to_string());
|
||||||
assert_eq!(page.meta.slug.unwrap(), "hello-world".to_string());
|
assert_eq!(page.meta.slug.unwrap(), "hello-world".to_string());
|
||||||
assert_eq!(page.raw_content, "Hello world".to_string());
|
assert_eq!(page.raw_content, "Hello world".to_string());
|
||||||
assert_eq!(page.content, "<p>Hello world</p>\n".to_string());
|
assert_eq!(page.content, "<p>Hello world</p>\n".to_string());
|
||||||
|
|
Loading…
Reference in a new issue