diff options
author | gennyble <gen@nyble.dev> | 2024-05-03 10:43:53 -0500 |
---|---|---|
committer | gennyble <gen@nyble.dev> | 2024-05-03 10:43:53 -0500 |
commit | b0f6242b8b936d47b32c227cab5b18b4902cf9c4 (patch) | |
tree | 07645afa7286b3fa7f9555742a1ddba1bb6ba126 /src/fs.rs | |
parent | 71a9330b728c1b7d7688d3aac2c6b4e8adffb1b0 (diff) | |
download | awake-b0f6242b8b936d47b32c227cab5b18b4902cf9c4.tar.gz awake-b0f6242b8b936d47b32c227cab5b18b4902cf9c4.zip |
opengraph embeds :)
Diffstat (limited to 'src/fs.rs')
-rw-r--r-- | src/fs.rs | 12 |
1 files changed, 12 insertions, 0 deletions
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 { |