Unify {page,section}.assets

Closes #1510
This commit is contained in:
Vincent Prouillet 2021-06-24 22:22:49 +02:00
parent 8e9b779fc6
commit e62664b4ff
3 changed files with 5 additions and 2 deletions

View file

@ -20,6 +20,7 @@
3. `get_file_hash` now returns base64 encoded hash by default 3. `get_file_hash` now returns base64 encoded hash by default
4. all functions working on files can now only load files in the Zola directory 4. all functions working on files can now only load files in the Zola directory
5. `resize_image` return value has changed 5. `resize_image` return value has changed
6. `page.assets` now start with a `/` to match `section.assets` and other paths
### Other ### Other

View file

@ -299,7 +299,7 @@ impl Page {
.to_path_buf(); .to_path_buf();
path path
}) })
.map(|path| path.to_string_lossy().to_string()) .map(|path| format!("/{}", path.display()))
.collect() .collect()
} }
@ -567,6 +567,7 @@ And here's another. [^2]
assert_eq!(page.file.parent, path.join("content").join("posts")); assert_eq!(page.file.parent, path.join("content").join("posts"));
assert_eq!(page.slug, "with-assets"); assert_eq!(page.slug, "with-assets");
assert_eq!(page.assets.len(), 3); assert_eq!(page.assets.len(), 3);
assert!(section.serialized_assets[0].starts_with('/'));
assert_eq!(page.permalink, "http://a-website.com/posts/with-assets/"); assert_eq!(page.permalink, "http://a-website.com/posts/with-assets/");
} }

View file

@ -197,7 +197,7 @@ impl Section {
.iter() .iter()
.filter_map(|asset| asset.file_name()) .filter_map(|asset| asset.file_name())
.filter_map(|filename| filename.to_str()) .filter_map(|filename| filename.to_str())
.map(|filename| self.path.clone() + filename) .map(|filename| format!("{}{}", self.path, filename))
.collect() .collect()
} }
@ -258,6 +258,7 @@ mod tests {
assert!(res.is_ok()); assert!(res.is_ok());
let section = res.unwrap(); let section = res.unwrap();
assert_eq!(section.assets.len(), 3); assert_eq!(section.assets.len(), 3);
assert!(section.serialized_assets[0].starts_with('/'));
assert_eq!(section.permalink, "http://a-website.com/posts/with-assets/"); assert_eq!(section.permalink, "http://a-website.com/posts/with-assets/");
} }