From e62664b4ff067aca4771122139854b4326a803e5 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Thu, 24 Jun 2021 22:22:49 +0200 Subject: [PATCH] Unify {page,section}.assets Closes #1510 --- CHANGELOG.md | 1 + components/library/src/content/page.rs | 3 ++- components/library/src/content/section.rs | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76fbae35..e14db44b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ 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 5. `resize_image` return value has changed + 6. `page.assets` now start with a `/` to match `section.assets` and other paths ### Other diff --git a/components/library/src/content/page.rs b/components/library/src/content/page.rs index 9fa4c2a1..852156a4 100644 --- a/components/library/src/content/page.rs +++ b/components/library/src/content/page.rs @@ -299,7 +299,7 @@ impl Page { .to_path_buf(); path }) - .map(|path| path.to_string_lossy().to_string()) + .map(|path| format!("/{}", path.display())) .collect() } @@ -567,6 +567,7 @@ And here's another. [^2] assert_eq!(page.file.parent, path.join("content").join("posts")); assert_eq!(page.slug, "with-assets"); assert_eq!(page.assets.len(), 3); + assert!(section.serialized_assets[0].starts_with('/')); assert_eq!(page.permalink, "http://a-website.com/posts/with-assets/"); } diff --git a/components/library/src/content/section.rs b/components/library/src/content/section.rs index a2d693ad..b7bafa46 100644 --- a/components/library/src/content/section.rs +++ b/components/library/src/content/section.rs @@ -197,7 +197,7 @@ impl Section { .iter() .filter_map(|asset| asset.file_name()) .filter_map(|filename| filename.to_str()) - .map(|filename| self.path.clone() + filename) + .map(|filename| format!("{}{}", self.path, filename)) .collect() } @@ -258,6 +258,7 @@ mod tests { assert!(res.is_ok()); let section = res.unwrap(); assert_eq!(section.assets.len(), 3); + assert!(section.serialized_assets[0].starts_with('/')); assert_eq!(section.permalink, "http://a-website.com/posts/with-assets/"); }