summary history branches tags files
commit:10082c20965be1507ee0f51dc4b6eff7fa3ed7de
author:Trevor Bentley
committer:Trevor Bentley
date:Fri Jan 13 17:26:38 2023 +0100
parents:f142234be0bc353a6d92eb44a03d9e4812bc3efc
fix site_assets to be a relative path
diff --git a/src/generate.rs b/src/generate.rs
line changes: +2/-2
index aa12ff7..a2657ed
--- a/src/generate.rs
+++ b/src/generate.rs
@@ -334,7 +334,7 @@ impl GitsyGenerator {
                 local_ctx.insert("site_description", site_description);
             }
             local_ctx.insert("site_dir", &self.settings.outputs.output_dir());
-            local_ctx.insert("site_assets", &self.settings.outputs.global_assets(None, None));
+            local_ctx.insert("site_assets", &self.settings.outputs.to_relative(&self.settings.outputs.global_assets(None, None)));
             local_ctx.insert("site_generated_ts", &generated_dt.timestamp());
             local_ctx.insert("site_generated_offset", &generated_dt.offset().local_minus_utc());
 
@@ -645,7 +645,7 @@ impl GitsyGenerator {
             global_ctx.insert("site_description", site_description);
         }
         global_ctx.insert("site_dir", &self.settings.outputs.output_dir());
-        global_ctx.insert("site_assets", &self.settings.outputs.global_assets(None, None));
+        global_ctx.insert("site_assets", &self.settings.outputs.to_relative(&self.settings.outputs.global_assets(None, None)));
         global_ctx.insert("site_generated_ts", &generated_dt.timestamp());
         global_ctx.insert("site_generated_offset", &generated_dt.offset().local_minus_utc());
 

diff --git a/src/settings.rs b/src/settings.rs
line changes: +9/-0
index 4e873ff..9008229
--- a/src/settings.rs
+++ b/src/settings.rs
@@ -175,6 +175,15 @@ impl GitsySettingsOutputs {
             .to_str().expect(&format!("ERROR: unable to parse output path: {}", self.path.display()))
             .to_string()
     }
+
+    pub fn to_relative(&self, path: &str) -> String {
+        let path_buf = PathBuf::from(path);
+        path_buf.strip_prefix(self.output_dir())
+            .expect(&format!("ERROR: Unable to make path relative: {}", path))
+            .to_str()
+            .expect(&format!("ERROR: Unable to make path relative: {}", path))
+            .to_string()
+    }
 }
 
 #[derive(Clone, Deserialize, Default, Debug)]