diff --git a/src/audio.rs b/src/audio.rs index d586ac5e..ecb4aadb 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -288,9 +288,15 @@ impl FromStr for Audio { } impl Item for Audio { - fn info(&self) -> Info { + fn info(&self, url: String) -> Info { Info::Map(vec![ - ("filename".into(), Info::Value(self.filename.to_string())), + ( + "filename".into(), + Info::Link { + text: self.filename.to_string(), + url, + }, + ), ("title".into(), Info::Value(self.title.to_string())), ("artist".into(), Info::Value(self.artist.to_string())), ("album".into(), Info::Value(self.album.to_string())), diff --git a/src/image.rs b/src/image.rs index 687783e2..d04947bc 100644 --- a/src/image.rs +++ b/src/image.rs @@ -133,9 +133,15 @@ impl FromStr for Image { } impl Item for Image { - fn info(&self) -> Info { + fn info(&self, url: String) -> Info { Info::Map(vec![ - ("filename".into(), Info::Value(self.filename.to_string())), + ( + "filename".into(), + Info::Link { + text: self.filename.to_string(), + url, + }, + ), ("type".into(), Info::Value(self.ty.to_string())), ( "dimensions".into(), diff --git a/src/info.rs b/src/info.rs index bae2da0f..7106644a 100644 --- a/src/info.rs +++ b/src/info.rs @@ -1,5 +1,6 @@ #[derive(Debug, PartialEq)] pub(crate) enum Info { + Link { text: String, url: String }, List(Vec), Map(Vec<(String, Info)>), Value(String), diff --git a/src/item.rs b/src/item.rs index 381afa90..f2e9f809 100644 --- a/src/item.rs +++ b/src/item.rs @@ -1,7 +1,7 @@ use super::*; pub(crate) trait Item { - fn info(&self) -> Info; + fn info(&self, url: String) -> Info; fn path(&self) -> RelativePath; diff --git a/src/templates/info.rs b/src/templates/info.rs index db2eea71..e9047d23 100644 --- a/src/templates/info.rs +++ b/src/templates/info.rs @@ -7,6 +7,18 @@ pub(crate) struct InfoHtml<'a>(pub(crate) &'a Info); mod tests { use {super::*, pretty_assertions::assert_eq}; + #[test] + fn link() { + assert_eq!( + InfoHtml(&Info::Link { + text: "foo".into(), + url: "/bar".into(), + }) + .to_string(), + "foo\n", + ); + } + #[test] fn list() { assert_eq!( diff --git a/src/templates/media.rs b/src/templates/media.rs index fdd4d008..5b2d92f2 100644 --- a/src/templates/media.rs +++ b/src/templates/media.rs @@ -13,6 +13,10 @@ impl MediaHtml { } impl Page for MediaHtml { + fn stylesheet(&self) -> Option<&'static str> { + Some("/static/media.css") + } + fn title(&self) -> String { if let Some(title) = self.title() { format!("{title} media ยท filepack") diff --git a/src/video.rs b/src/video.rs index e98acd6c..8e6b0779 100644 --- a/src/video.rs +++ b/src/video.rs @@ -532,9 +532,15 @@ impl FromStr for Video { } impl Item for Video { - fn info(&self) -> Info { + fn info(&self, url: String) -> Info { Info::Map(vec![ - ("filename".into(), Info::Value(self.filename.to_string())), + ( + "filename".into(), + Info::Link { + text: self.filename.to_string(), + url, + }, + ), ("type".into(), Info::Value(self.ty.to_string())), ( "duration".into(), diff --git a/static/media.css b/static/media.css new file mode 100644 index 00000000..9a457356 --- /dev/null +++ b/static/media.css @@ -0,0 +1,9 @@ +dl { + display: grid; + gap: 0 1em; + grid-template-columns: max-content auto; +} + +dd { + margin: 0; +} diff --git a/templates/info.html b/templates/info.html index a86bea9d..f68173e1 100644 --- a/templates/info.html +++ b/templates/info.html @@ -1,4 +1,7 @@ %% match self.0 { +%% Info::Link { text, url } => { +{{ text }} +%% } %% Info::List(items) => {
    %% for item in items { diff --git a/templates/media.html b/templates/media.html index 680ded60..5ae40a5d 100644 --- a/templates/media.html +++ b/templates/media.html @@ -7,9 +7,8 @@

    {{ self.fingerprint }} %% for i in 0..media.items() { %% let item = media.item(i).unwrap(); -%% let info = item.info(); +%% let info = item.info(format!("/package/{}/item/{}", self.fingerprint, Ordinal(i)));
  1. - {{ item.path() }} {{ Trusted(InfoHtml(&info)) }}
  2. %% }