From b0f6242b8b936d47b32c227cab5b18b4902cf9c4 Mon Sep 17 00:00:00 2001 From: gennyble Date: Fri, 3 May 2024 10:43:53 -0500 Subject: opengraph embeds :) --- src/fs.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/fs.rs') diff --git a/src/fs.rs b/src/fs.rs index 7dc94d3..831aa86 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -57,6 +57,18 @@ impl Webpath { pub fn as_dir(&self) -> String { format!("/{}/", self.webcanon) } + + /// Returns the first directory of the Webpath. Assumes the path is a + /// directory if it ends in a `/`, otherwise pops the last component. + pub fn first_dir(&self) -> String { + if self.is_dir { + self.webcanon.to_string() + } else { + let mut dir = self.webcanon.clone(); + dir.pop(); + dir.to_string() + } + } } impl Deref for Webpath { -- cgit 1.4.1-3-g733a5