Skip to content

Commit

Permalink
Merge pull request getzola#1682 from getzola/next
Browse files Browse the repository at this point in the history
Next version
  • Loading branch information
Keats committed Dec 8, 2021
2 parents d305c6c + 46027ec commit 24007b2
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 28 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 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)

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zola"
version = "0.15.0"
version = "0.15.1"
authors = ["Vincent Prouillet <[email protected]>"]
edition = "2018"
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
19 changes: 15 additions & 4 deletions components/config/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -357,9 +357,7 @@ impl Default for Config {
search: search::Search::default(),
markdown: markup::Markdown::default(),
extra: HashMap::new(),
};
conf.add_default_language();
conf
}
}
}

Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion components/rendering/src/shortcode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
52 changes: 35 additions & 17 deletions components/rendering/src/shortcode/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,21 @@ impl Shortcode {
}

pub fn update_range(&mut self, sc_span: &Range<usize>, 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 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);
}
if self.span.start < sc_span.start {
return;
}

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);
}
}
}
Expand Down Expand Up @@ -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]
Expand Down
31 changes: 31 additions & 0 deletions components/rendering/tests/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1625,3 +1625,34 @@ fn can_use_smart_punctuation() {
let res = render_content(r#"This -- is "it"..."#, &context).unwrap();
assert_eq!(res.body, "<p>This – is “it”…</p>\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, "<p>ttest1</p>\n<p>123</p>\n<p>ttest2</p>\n<p>123</p>\n");
}
2 changes: 2 additions & 0 deletions components/site/tests/site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion test_site/config.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 24007b2

Please sign in to comment.