Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
Expand Down
10 changes: 8 additions & 2 deletions src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions src/info.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[derive(Debug, PartialEq)]
pub(crate) enum Info {
Link { text: String, url: String },
List(Vec<Info>),
Map(Vec<(String, Info)>),
Value(String),
Expand Down
2 changes: 1 addition & 1 deletion src/item.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;

pub(crate) trait Item {
fn info(&self) -> Info;
fn info(&self, url: String) -> Info;

fn path(&self) -> RelativePath;

Expand Down
12 changes: 12 additions & 0 deletions src/templates/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
"<a href=/bar>foo</a>\n",
);
}

#[test]
fn list() {
assert_eq!(
Expand Down
4 changes: 4 additions & 0 deletions src/templates/media.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 8 additions & 2 deletions src/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
9 changes: 9 additions & 0 deletions static/media.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dl {
display: grid;
gap: 0 1em;
grid-template-columns: max-content auto;
}

dd {
margin: 0;
}
3 changes: 3 additions & 0 deletions templates/info.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
%% match self.0 {
%% Info::Link { text, url } => {
<a href={{ url }}>{{ text }}</a>
%% }
%% Info::List(items) => {
<ol>
%% for item in items {
Expand Down
3 changes: 1 addition & 2 deletions templates/media.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ <h1 class=code><a href=/package/{{ self.fingerprint }}>{{ self.fingerprint }}</a
<ol>
%% 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)));
<li>
<a href=/package/{{ self.fingerprint }}/item/{{ Ordinal(i) }}>{{ item.path() }}</a>
{{ Trusted(InfoHtml(&info)) }}
</li>
%% }
Expand Down