Merge pull request #1682 from getzola/next

Next version
This commit is contained in:
Vincent Prouillet 2021-12-08 20:08:58 +01:00 committed by GitHub
commit 24007b2559
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 93 additions and 27 deletions

View file

@ -1,5 +1,9 @@
# Changelog # 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) ## 0.15.0 (2021-12-05)

2
Cargo.lock generated
View file

@ -3575,7 +3575,7 @@ dependencies = [
[[package]] [[package]]
name = "zola" name = "zola"
version = "0.15.0" version = "0.15.1"
dependencies = [ dependencies = [
"atty", "atty",
"chrono", "chrono",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "zola" name = "zola"
version = "0.15.0" version = "0.15.1"
authors = ["Vincent Prouillet <hello@vincentprouillet.com>"] authors = ["Vincent Prouillet <hello@vincentprouillet.com>"]
edition = "2018" edition = "2018"
license = "MIT" license = "MIT"

View file

@ -14,7 +14,7 @@ stages:
imageName: 'vs2017-win2016' imageName: 'vs2017-win2016'
rustup_toolchain: stable rustup_toolchain: stable
mac-stable: mac-stable:
imageName: 'macos-10.15' imageName: 'macos-11'
rustup_toolchain: stable rustup_toolchain: stable
linux-stable: linux-stable:
imageName: 'ubuntu-20.04' imageName: 'ubuntu-20.04'

View file

@ -332,7 +332,7 @@ pub fn merge(into: &mut Toml, from: &Toml) -> Result<()> {
impl Default for Config { impl Default for Config {
fn default() -> Config { fn default() -> Config {
let mut conf = Config { Config {
base_url: DEFAULT_BASE_URL.to_string(), base_url: DEFAULT_BASE_URL.to_string(),
title: None, title: None,
description: None, description: None,
@ -357,9 +357,7 @@ impl Default for Config {
search: search::Search::default(), search: search::Search::default(),
markdown: markup::Markdown::default(), markdown: markup::Markdown::default(),
extra: HashMap::new(), extra: HashMap::new(),
}; }
conf.add_default_language();
conf
} }
} }
@ -707,4 +705,17 @@ highlight_themes_css = [
let config = Config::parse(config); let config = Config::parse(config);
assert_eq!(config.is_err(), true); 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);
}
} }

View file

@ -39,7 +39,7 @@ pub fn insert_md_shortcodes(
for (md_sc_span, rendered_length) in &transforms { for (md_sc_span, rendered_length) in &transforms {
sc.update_range(md_sc_span, *rendered_length); sc.update_range(md_sc_span, *rendered_length);
} }
// It has been checked before that this exist
if sc.file_type() == ShortcodeFileType::Html { if sc.file_type() == ShortcodeFileType::Html {
html_shortcodes.push(sc); html_shortcodes.push(sc);
continue; continue;

View file

@ -50,18 +50,21 @@ impl Shortcode {
} }
pub fn update_range(&mut self, sc_span: &Range<usize>, rendered_length: usize) { pub fn update_range(&mut self, sc_span: &Range<usize>, rendered_length: usize) {
if self.span.start > sc_span.start { if self.span.start < sc_span.start {
let delta = if sc_span.end < rendered_length { return;
rendered_length - sc_span.end }
} else {
sc_span.end - rendered_length
};
if sc_span.end < rendered_length { let rendered_end = sc_span.start + rendered_length;
self.span = (self.span.start + delta)..(self.span.end + delta); let delta = if sc_span.end < rendered_end {
} else { rendered_end - sc_span.end
self.span = (self.span.start - delta)..(self.span.end - delta); } 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, nth: 0,
tera_name: String::new(), tera_name: String::new(),
}; };
// 6 -> 10 in length so +4 on both sides of the range
sc.update_range(&(2..8), 10); sc.update_range(&(2..8), 10);
assert_eq!(sc.span, 12..22); assert_eq!(sc.span, 14..24);
sc.update_range(&(24..30), 30); // After the shortcode so no impact
assert_eq!(sc.span, 12..22); sc.update_range(&(25..30), 30);
sc.update_range(&(5..11), 6); assert_eq!(sc.span, 14..24);
assert_eq!(sc.span, 7..17); // +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] #[test]

View file

@ -1625,3 +1625,34 @@ fn can_use_smart_punctuation() {
let res = render_content(r#"This -- is "it"..."#, &context).unwrap(); let res = render_content(r#"This -- is "it"..."#, &context).unwrap();
assert_eq!(res.body, "<p>This is “it”…</p>\n"); 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");
}

View file

@ -111,6 +111,8 @@ fn can_build_site_without_live_reload() {
assert!(file_exists!(public, "sitemap.xml")); assert!(file_exists!(public, "sitemap.xml"));
assert!(file_exists!(public, "robots.txt")); assert!(file_exists!(public, "robots.txt"));
assert!(file_exists!(public, "a-fixed-url/index.html")); 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")); assert!(file_exists!(public, "posts/python/index.html"));
// Shortcodes work // Shortcodes work

View file

@ -1,5 +1,5 @@
name: zola name: zola
version: 0.15.0 version: 0.15.1
summary: A fast static site generator in a single binary with everything built-in. summary: A fast static site generator in a single binary with everything built-in.
description: | description: |
A fast static site generator in a single binary with everything built-in. A fast static site generator in a single binary with everything built-in.
@ -21,7 +21,7 @@ parts:
zola: zola:
source-type: git source-type: git
source: https://github.com/getzola/zola.git source: https://github.com/getzola/zola.git
source-tag: v0.15.0 source-tag: v0.15.1
plugin: rust plugin: rust
rust-channel: stable rust-channel: stable
build-packages: build-packages:

View file

@ -1,4 +1,4 @@
title = "My site" title = "My Integration Testing site"
base_url = "https://replace-this-with-your-url.com" base_url = "https://replace-this-with-your-url.com"
compile_sass = true compile_sass = true
generate_feed = true generate_feed = true