From aa57541c21bc060c7e49b152b30842932b284fc3 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Tue, 2 Feb 2021 21:53:36 +0100 Subject: [PATCH] Force newline after front-matter Closes #1287 --- CHANGELOG.md | 6 +++++- components/front_matter/src/lib.rs | 10 ++++++---- components/library/src/content/page.rs | 4 ++-- components/templates/src/global_fns/load_data.rs | 3 +-- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c486611..c147c306 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,11 @@ ## unreleased -### Features +### Breaking + +- Newlines are now required after the closing `+++` of front-matter + +### Other - internal links are now resolved in the `markdown` filter in the templates (#1296 #1316) - Add a `required` argument to `load_data` so it can be allowed to fail diff --git a/components/front_matter/src/lib.rs b/components/front_matter/src/lib.rs index 5b54fd51..9397af89 100644 --- a/components/front_matter/src/lib.rs +++ b/components/front_matter/src/lib.rs @@ -15,9 +15,9 @@ pub use section::SectionFrontMatter; lazy_static! { static ref TOML_RE: Regex = - Regex::new(r"^[[:space:]]*\+\+\+(\r?\n(?s).*?(?-s))\+\+\+\r?\n?((?s).*(?-s))$").unwrap(); + Regex::new(r"^[[:space:]]*\+\+\+(\r?\n(?s).*?(?-s))\+\+\+\r?\n((?s).*(?-s))$").unwrap(); static ref YAML_RE: Regex = - Regex::new(r"^[[:space:]]*---(\r?\n(?s).*?(?-s))---\r?\n?((?s).*(?-s))$").unwrap(); + Regex::new(r"^[[:space:]]*---(\r?\n(?s).*?(?-s))---\r?\n((?s).*(?-s))$").unwrap(); } pub enum RawFrontMatter<'a> { @@ -174,13 +174,15 @@ Hello title = "Title" description = "hey there" date = 2002-10-12 -+++"#; "toml")] ++++ +"#; "toml")] #[test_case(r#" --- title: Title description: hey there date: 2002-10-12 ----"#; "yaml")] +--- +"#; "yaml")] fn can_split_content_with_only_frontmatter_valid(content: &str) { let (front_matter, content) = split_page_content(Path::new(""), content).unwrap(); assert_eq!(content, ""); diff --git a/components/library/src/content/page.rs b/components/library/src/content/page.rs index c453b87f..13034158 100644 --- a/components/library/src/content/page.rs +++ b/components/library/src/content/page.rs @@ -490,7 +490,7 @@ Hello world"#; let mut config = Config::default(); config.slugify.paths = SlugifyStrategy::On; let res = - Page::parse(Path::new(" file with space.md"), "+++\n+++", &config, &PathBuf::new()); + Page::parse(Path::new(" file with space.md"), "+++\n+++\n", &config, &PathBuf::new()); assert!(res.is_ok()); let page = res.unwrap(); assert_eq!(page.slug, "file-with-space"); @@ -501,7 +501,7 @@ Hello world"#; fn can_make_path_from_utf8_filename() { let mut config = Config::default(); config.slugify.paths = SlugifyStrategy::Safe; - let res = Page::parse(Path::new("日本.md"), "+++\n++++", &config, &PathBuf::new()); + let res = Page::parse(Path::new("日本.md"), "+++\n+++\n", &config, &PathBuf::new()); assert!(res.is_ok()); let page = res.unwrap(); assert_eq!(page.slug, "日本"); diff --git a/components/templates/src/global_fns/load_data.rs b/components/templates/src/global_fns/load_data.rs index a5b929fa..286b63c5 100644 --- a/components/templates/src/global_fns/load_data.rs +++ b/components/templates/src/global_fns/load_data.rs @@ -255,8 +255,7 @@ impl TeraFn for LoadData { .into()) } } - } - // Now that we have discarded recoverable errors, we can unwrap the result + } // Now that we have discarded recoverable errors, we can unwrap the result }?; let result_value: Result = match file_format {