From 3dbf8117407cf6c6fb3171fef12ba5f2654e2ee7 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Mon, 6 Dec 2021 08:58:05 +0100 Subject: [PATCH 1/5] Update macos ci image --- CHANGELOG.md | 2 ++ azure-pipelines.yml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bfbb17fb..07bd01eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.16.0 (unreleased) + ## 0.15.0 (2021-12-05) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 6763de5e..717f256e 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -14,7 +14,7 @@ stages: imageName: 'vs2017-win2016' rustup_toolchain: stable mac-stable: - imageName: 'macos-10.15' + imageName: 'macos-11' rustup_toolchain: stable linux-stable: imageName: 'ubuntu-20.04' From 9191a2726cbc65e5422461e1ee8ad6a76c2d719a Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Tue, 7 Dec 2021 20:22:34 +0100 Subject: [PATCH 2/5] Fix markdown shortcodes --- CHANGELOG.md | 3 +- components/rendering/src/shortcode/mod.rs | 2 +- components/rendering/src/shortcode/parser.rs | 50 +++++++++++++------- components/rendering/tests/markdown.rs | 31 ++++++++++++ 4 files changed, 68 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07bd01eb..5af3d9e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # Changelog -## 0.16.0 (unreleased) +## 0.15.1 (unreleased) +- Fix markdown shortcodes not being rendered correctly ## 0.15.0 (2021-12-05) diff --git a/components/rendering/src/shortcode/mod.rs b/components/rendering/src/shortcode/mod.rs index a19375ae..7c142f89 100644 --- a/components/rendering/src/shortcode/mod.rs +++ b/components/rendering/src/shortcode/mod.rs @@ -39,7 +39,7 @@ pub fn insert_md_shortcodes( for (md_sc_span, rendered_length) in &transforms { sc.update_range(md_sc_span, *rendered_length); } - // It has been checked before that this exist + if sc.file_type() == ShortcodeFileType::Html { html_shortcodes.push(sc); continue; diff --git a/components/rendering/src/shortcode/parser.rs b/components/rendering/src/shortcode/parser.rs index 301904c2..a2478f0b 100644 --- a/components/rendering/src/shortcode/parser.rs +++ b/components/rendering/src/shortcode/parser.rs @@ -50,18 +50,21 @@ impl Shortcode { } pub fn update_range(&mut self, sc_span: &Range, rendered_length: usize) { - if self.span.start > sc_span.start { - let delta = if sc_span.end < rendered_length { - rendered_length - sc_span.end - } else { - sc_span.end - rendered_length - }; + if self.span.start < sc_span.start { + return; + } - if sc_span.end < rendered_length { - self.span = (self.span.start + delta)..(self.span.end + delta); - } else { - self.span = (self.span.start - delta)..(self.span.end - delta); - } + let rendered_end = sc_span.start + rendered_length; + let delta = if sc_span.end < rendered_end { + rendered_end - sc_span.end + } else { + sc_span.end - rendered_end + }; + + if sc_span.end < rendered_end { + self.span = (self.span.start + delta)..(self.span.end + delta); + } else { + self.span = (self.span.start - delta)..(self.span.end - delta); } } } @@ -373,12 +376,27 @@ mod tests { nth: 0, tera_name: String::new(), }; + // 6 -> 10 in length so +4 on both sides of the range sc.update_range(&(2..8), 10); - assert_eq!(sc.span, 12..22); - sc.update_range(&(24..30), 30); - assert_eq!(sc.span, 12..22); - sc.update_range(&(5..11), 6); - assert_eq!(sc.span, 7..17); + assert_eq!(sc.span, 14..24); + // After the shortcode so no impact + sc.update_range(&(25..30), 30); + assert_eq!(sc.span, 14..24); + // +4 again + sc.update_range(&(5..11), 10); + assert_eq!(sc.span, 18..28); + + // buggy case from https://zola.discourse.group/t/zola-0-15-md-shortcode-stopped-working/1099/3 + let mut sc = Shortcode { + name: "a".to_string(), + args: Value::Null, + span: 42..65, + body: None, + nth: 0, + tera_name: String::new(), + }; + sc.update_range(&(9..32), 3); + assert_eq!(sc.span, 22..45); } #[test] diff --git a/components/rendering/tests/markdown.rs b/components/rendering/tests/markdown.rs index 76d013bd..f158a8e2 100644 --- a/components/rendering/tests/markdown.rs +++ b/components/rendering/tests/markdown.rs @@ -1625,3 +1625,34 @@ fn can_use_smart_punctuation() { let res = render_content(r#"This -- is "it"..."#, &context).unwrap(); assert_eq!(res.body, "

This – is β€œit”…

\n"); } + +// https://zola.discourse.group/t/zola-0-15-md-shortcode-stopped-working/1099/2 +#[test] +fn md_shortcode_regression() { + let permalinks_ctx = HashMap::new(); + let mut tera = Tera::default(); + tera.extend(&ZOLA_TERA).unwrap(); + tera.add_raw_template("shortcodes/code.md", "123").unwrap(); + let config = Config::default_for_test(); + let mut context = RenderContext::new( + &tera, + &config, + &config.default_language, + "", + &permalinks_ctx, + InsertAnchor::None, + ); + let shortcode_def = utils::templates::get_shortcodes(&tera); + context.set_shortcode_definitions(&shortcode_def); + + let markdown_string = r#" +ttest1 + +{{ code(path = "content/software/supercollider/pakt-februari/pakt29.scd", syntax = "supercollider") }} + +ttest2 + +{{ code(path = "content/software/supercollider/pakt-februari/pakt29.scd", syntax = "supercollider") }}"#; + let res = render_content(markdown_string, &context).unwrap(); + assert_eq!(res.body, "

ttest1

\n

123

\n

ttest2

\n

123

\n"); +} From 7ce4f75d09d81678e16dce3e7d5fdee7d634691c Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Tue, 7 Dec 2021 20:54:38 +0100 Subject: [PATCH 3/5] Fix config data not getting to the templates Closes #1687 --- CHANGELOG.md | 1 + components/config/src/config/mod.rs | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5af3d9e9..340948e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 0.15.1 (unreleased) - Fix markdown shortcodes not being rendered correctly +- Fix config data not getting to the templates ## 0.15.0 (2021-12-05) diff --git a/components/config/src/config/mod.rs b/components/config/src/config/mod.rs index e68c4ac9..d0b779c7 100644 --- a/components/config/src/config/mod.rs +++ b/components/config/src/config/mod.rs @@ -332,7 +332,7 @@ pub fn merge(into: &mut Toml, from: &Toml) -> Result<()> { impl Default for Config { fn default() -> Config { - let mut conf = Config { + Config { base_url: DEFAULT_BASE_URL.to_string(), title: None, description: None, @@ -357,9 +357,7 @@ impl Default for Config { search: search::Search::default(), markdown: markup::Markdown::default(), extra: HashMap::new(), - }; - conf.add_default_language(); - conf + } } } @@ -707,4 +705,17 @@ highlight_themes_css = [ let config = Config::parse(config); assert_eq!(config.is_err(), true); } + + // https://github.com/getzola/zola/issues/1687 + #[test] + fn regression_config_default_lang_data() { + let config = r#" +base_url = "https://www.getzola.org/" +title = "Zola" + "#; + + let config = Config::parse(config).unwrap(); + let serialised = config.serialize(&config.default_language); + assert_eq!(serialised.title, &config.title); + } } From 22dcfb963efb6da6d16b3758028db3603d339ebd Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Tue, 7 Dec 2021 21:04:16 +0100 Subject: [PATCH 4/5] Test config.title in integration tests --- components/site/tests/site.rs | 2 ++ test_site/config.toml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/components/site/tests/site.rs b/components/site/tests/site.rs index 461a767b..2511af0c 100644 --- a/components/site/tests/site.rs +++ b/components/site/tests/site.rs @@ -111,6 +111,8 @@ fn can_build_site_without_live_reload() { assert!(file_exists!(public, "sitemap.xml")); assert!(file_exists!(public, "robots.txt")); assert!(file_exists!(public, "a-fixed-url/index.html")); + // the config.title is there + assert!(file_contains!(public, "index.html", "My Integration Testing site")); assert!(file_exists!(public, "posts/python/index.html")); // Shortcodes work diff --git a/test_site/config.toml b/test_site/config.toml index 7093a779..58f650ed 100644 --- a/test_site/config.toml +++ b/test_site/config.toml @@ -1,4 +1,4 @@ -title = "My site" +title = "My Integration Testing site" base_url = "https://replace-this-with-your-url.com" compile_sass = true generate_feed = true From 46027ecdb74d9f790c2127f842bd55a84c02ade1 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Tue, 7 Dec 2021 21:47:10 +0100 Subject: [PATCH 5/5] Update version --- Cargo.lock | 2 +- Cargo.toml | 2 +- snapcraft.yaml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f126700f..2dc0ed2a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3575,7 +3575,7 @@ dependencies = [ [[package]] name = "zola" -version = "0.15.0" +version = "0.15.1" dependencies = [ "atty", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 8175ddda..9cd71d70 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zola" -version = "0.15.0" +version = "0.15.1" authors = ["Vincent Prouillet "] edition = "2018" license = "MIT" diff --git a/snapcraft.yaml b/snapcraft.yaml index 5d849da9..9e999b66 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -1,5 +1,5 @@ name: zola -version: 0.15.0 +version: 0.15.1 summary: A fast static site generator in a single binary with everything built-in. description: | A fast static site generator in a single binary with everything built-in. @@ -21,7 +21,7 @@ parts: zola: source-type: git source: https://github.com/getzola/zola.git - source-tag: v0.15.0 + source-tag: v0.15.1 plugin: rust rust-channel: stable build-packages: