Skip to content

Commit

Permalink
show covers
Browse files Browse the repository at this point in the history
  • Loading branch information
ngalaiko committed Jan 7, 2024
1 parent a2b7f67 commit 6557b77
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 39 deletions.
Binary file not shown.

This file was deleted.

2 changes: 1 addition & 1 deletion shared/src/pages/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub fn places(places: &[restaurands_and_cafes::Place]) -> maud::Markup {
new(
"places",
None,
&generated::restaurants_and_cafes(places),
&generated::places(places),
&footer_without_copy_right(),
)
}
32 changes: 28 additions & 4 deletions shared/src/types/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,36 @@ pub fn records(records: &[records::Record]) -> maud::Markup {
artist_a.cmp(artist_b)
});

let records = records.iter().filter_map(|record| {
std::path::Path::new(&record.basic_information.cover_image)
.extension()
.and_then(|ext| ext.to_str())
.map(|ext| {
(
record.id,
format!(
"{} - {}",
record.basic_information.artists[0].name, record.basic_information.title
),
format!(
"./{}.{ext}",
record.basic_information.title.replace('/', "-")
),
)
})
});

maud::html! {
ul {
@for record in records {
@for (id, title, cover_href) in records {
li {
a href=(format!("https://www.discogs.com/release/{}", record.id)) {
(record.basic_information.artists[0].name) " - " (record.basic_information.title)
a href=(format!("https://www.discogs.com/release/{}", id)) {
figure {
img src=(cover_href) alt=(title) style="width: 300px; height: 300px;";
}
figcaption {
(title)
}
}
}
}
Expand All @@ -97,7 +121,7 @@ pub fn records(records: &[records::Record]) -> maud::Markup {
}

#[must_use]
pub fn restaurants_and_cafes(places: &[restaurands_and_cafes::Place]) -> maud::Markup {
pub fn places(places: &[restaurands_and_cafes::Place]) -> maud::Markup {
let mut places = places.to_vec();
places.sort_by(|a, b| b.times.cmp(&a.times));

Expand Down
36 changes: 22 additions & 14 deletions update/src/discogs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,18 @@ pub async fn update<P: AsRef<async_std::path::Path>>(token: &str, output: P) ->
let mut all_files = vec![];
for record in &records {
let title = record.basic_information.title.replace('/', "-");
let mut output_json = output.to_path_buf();
output_json.push(format!("{title}.json"));

if !output_json.exists().await {
let serialized = serde_json::to_vec_pretty(&record).map_err(Error::Ser)?;
async_std::fs::write(&output_json, serialized)
.await
.map_err(Error::Io)?;
}
all_files.push(output_json);

if let Some(ext) =
std::path::Path::new(&record.basic_information.cover_image).extension()
.and_then(|ext| ext.to_str())
{
if let (Some(filename), Some(ext)) = (
std::path::Path::new(&record.basic_information.cover_image)
.file_stem()
.and_then(|ext| ext.to_str()),
std::path::Path::new(&record.basic_information.cover_image)
.extension()
.and_then(|ext| ext.to_str()),
) {
if filename == "spacer" {
continue;
}
let mut image_out = output.to_path_buf();
image_out.push(format!("{title}.{ext}"));

Expand All @@ -96,6 +93,17 @@ pub async fn update<P: AsRef<async_std::path::Path>>(token: &str, output: P) ->
}
all_files.push(image_out);
}

let mut output_json = output.to_path_buf();
output_json.push(format!("{title}.json"));

if !output_json.exists().await {
let serialized = serde_json::to_vec_pretty(&record).map_err(Error::Ser)?;
async_std::fs::write(&output_json, serialized)
.await
.map_err(Error::Io)?;
}
all_files.push(output_json);
}

let mut entries = async_std::fs::read_dir(&output).await.map_err(Error::Io)?;
Expand Down

0 comments on commit 6557b77

Please sign in to comment.