Skip to content

Commit

Permalink
#82 start working on endsong_web
Browse files Browse the repository at this point in the history
  • Loading branch information
fsktom committed Sep 29, 2024
1 parent 137fc7c commit f6dfbf4
Show file tree
Hide file tree
Showing 15 changed files with 3,640 additions and 23 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- run: cargo check && cd endsong_ui && cargo check && cd endsong_macros && cargo check
- run: cargo check && cd endsong_web && cargo check && cd ../endsong_ui && cargo check && cd endsong_macros && cargo check

test:
name: Test Suite
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- run: cargo test --all-features && cd endsong_ui && cargo test --all-features && cd endsong_macros && cargo test --all-features
- run: cargo test --all-features && cd endsong_web && cargo test --all-features && cd ../endsong_ui && cargo test --all-features && cd endsong_macros && cargo test --all-features

fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- run: cargo fmt --all --check && cd endsong_ui && cargo fmt --all --check && cd endsong_macros && cargo fmt --all --check
- run: cargo fmt --all --check && cd endsong_web && cargo fmt --all --check && cd ../endsong_ui && cargo fmt --all --check && cd endsong_macros && cargo fmt --all --check

clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- run: cargo clippy -- --deny warnings && cd endsong_ui && cargo clippy -- --deny warnings && cd endsong_macros && cargo clippy -- --deny warnings
- run: cargo clippy -- --deny warnings && cd endsong_web && cargo clippy -- --deny warnings && cd ../endsong_ui && cargo clippy -- --deny warnings && cd endsong_macros && cargo clippy -- --deny warnings
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ endsong_ui/summaries/

# ...
endsong_ui/templates/node_modules/
endsong_web/templates/node_modules/
9 changes: 5 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"rust-analyzer.linkedProjects": [
"./endsong_ui/Cargo.toml",
"./Cargo.toml"
]
"rust-analyzer.linkedProjects": [
"./endsong_ui/Cargo.toml",
"./Cargo.toml",
"./endsong_web/Cargo.toml"
]
}
15 changes: 1 addition & 14 deletions endsong_ui/src/summarize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ pub fn artist(entries: &SongEntries, artist: &Artist) {
first_listens,
last_listens,
};
let path = format!("summaries/{} summary.html", artist.name);
std::fs::write(&path, page.render().unwrap()).unwrap();
write_and_open_summary(page, &artist.name);
}

Expand All @@ -120,7 +118,7 @@ pub fn artist(entries: &SongEntries, artist: &Artist) {
fn write_and_open_summary<S: Template>(summary: S, name: &str) {
std::fs::create_dir_all("summaries").unwrap();

let title = crate::normalize_path(&format!("{name}_summary.html"));
let title = crate::normalize_path(&format!("{name}_summary"));

match std::env::consts::OS {
// see https://github.com/plotly/plotly.rs/issues/132#issuecomment-1488920563
Expand Down Expand Up @@ -231,15 +229,4 @@ mod filters {

Ok(format!("{minutes}m"))
}

/// Formats a [`TimeDelta`] in a machine-readble way
/// for the `dateime` `<time>` attribute
///
/// See <https://developer.mozilla.org/en-US/docs/Web/HTML/Element/time>
/// and <https://www.w3schools.com/tags/att_time_datetime.asp>
#[expect(clippy::unnecessary_wraps, reason = "rinja required output type")]
pub fn machine_duration(duration: &TimeDelta) -> rinja::Result<String> {
let seconds = duration.num_seconds();
Ok(format!("P{seconds}S"))
}
}
2 changes: 1 addition & 1 deletion endsong_ui/templates/artist.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h2 class="self-center text-xl font-bold">General info</h2>
<li>Total playcount: {{ plays }}</li>
<li>
Time spent listening:
<time datetime="{{ time_played|machine_duration }}"
<time datetime="{{ time_played }}"
>{{ time_played|pretty_duration }}</time
>
</li>
Expand Down
Loading

0 comments on commit f6dfbf4

Please sign in to comment.