Some more tweaks

This commit is contained in:
Vincent Prouillet 2021-05-17 20:26:50 +02:00
parent a736d33afb
commit ae916eb6c5
5 changed files with 22 additions and 1 deletions

View file

@ -5,7 +5,7 @@
### Breaking
- Newlines are now required after the closing `+++` of front-matter
- `resize_image` now returns a map: `{url, static_path}` instead of just the URL so you can follow up with other functions
- `resize_image` now returns an object: `{url, static_path}` instead of just the URL so you can follow up with other functions on the new file if needed
- `get_file_hash` now has the `base64` option set to `true` by default (from `false`) since it's mainly used for integrity hashes which are base64
- `get_url` does not automatically strip leading `/` from paths anymore
- i18n rework: languages now have their sections in `config.toml` to set up all their options
@ -30,6 +30,8 @@
- Allow using POST for `load_data`, along with a body to POST and allow it to fail
- Add Zig and Protobuf syntax highlighting
- Footnotes links are now stripped from summaries - they were not linking to anything.
- `get_url` and `get_taxonomy_url` are now marked as safe, no need to call `| safe` on their output
- Add `allow_missing` optional argument to `get_image_metadata` to not error if the file is not found
## 0.13.0 (2021-01-09)

View file

@ -58,6 +58,10 @@ impl TeraFn for GetTaxonomyUrl {
Err(format!("`get_taxonomy_url`: couldn't find `{}` in `{}` taxonomy", name, kind).into())
}
fn is_safe(&self) -> bool {
true
}
}
#[derive(Debug)]

View file

@ -130,6 +130,10 @@ impl TeraFn for GetUrl {
Ok(to_value(permalink).unwrap())
}
}
fn is_safe(&self) -> bool {
true
}
}
#[derive(Debug)]

View file

@ -6,6 +6,7 @@ use std::path::{Path, PathBuf};
/// 1. base_path + path
/// 2. base_path + static + path
/// 3. base_path + content + path
/// A path starting with @/ will replace it with `content/`
pub fn search_for_file(base_path: &Path, path: &str) -> Option<PathBuf> {
let search_paths = [base_path.join("static"), base_path.join("content")];
let actual_path = if path.starts_with("@/") {

View file

@ -123,9 +123,19 @@ impl TeraFn for GetImageMetadata {
args.get("path"),
"`get_image_metadata` requires a `path` argument with a string value"
);
let allow_missing = optional_arg!(
bool,
args.get("allow_missing"),
"`get_image_metadata`: `allow_missing` must be a boolean (true or false)"
)
.unwrap_or(false);
let src_path = match search_for_file(&self.base_path, &path) {
Some(f) => f,
None => {
if allow_missing {
println!("Image at path {} could not be found or loaded", path);
return Ok(Value::Null);
}
return Err(format!("`resize_image`: Cannot find path: {}", path).into());
}
};