mirror of
https://github.com/YGGverse/btracker.git
synced 2026-03-31 17:15:31 +00:00
use build-in tera filters
This commit is contained in:
parent
c1ae25f04b
commit
d95cee6c09
7 changed files with 51 additions and 53 deletions
26
src/feed.rs
26
src/feed.rs
|
|
@ -70,7 +70,10 @@ impl Feed {
|
|||
|
||||
self.buffer.push_str("<description>");
|
||||
self.buffer
|
||||
.push_str(&format!("{}\n{}", torrent.size(), torrent.files()));
|
||||
.push_str(&format!("size: {}", size(torrent.size)));
|
||||
if let Some(f) = torrent.files() {
|
||||
self.buffer.push_str(&format!(" / files: {f}"));
|
||||
}
|
||||
self.buffer.push_str("</description>");
|
||||
|
||||
self.buffer.push_str("<pubDate>");
|
||||
|
|
@ -87,6 +90,9 @@ impl Feed {
|
|||
}
|
||||
}
|
||||
|
||||
// @TODO use tera filters?
|
||||
// https://keats.github.io/tera/docs/#built-in-filters
|
||||
|
||||
fn escape(value: &str) -> String {
|
||||
value
|
||||
.replace('&', "&")
|
||||
|
|
@ -95,3 +101,21 @@ fn escape(value: &str) -> String {
|
|||
.replace('"', """)
|
||||
.replace("'", "'")
|
||||
}
|
||||
|
||||
fn size(value: u64) -> String {
|
||||
const KB: f32 = 1024.0;
|
||||
const MB: f32 = KB * KB;
|
||||
const GB: f32 = MB * KB;
|
||||
|
||||
let f = value as f32;
|
||||
|
||||
if f < KB {
|
||||
format!("{value} B")
|
||||
} else if f < MB {
|
||||
format!("{:.2} KB", f / KB)
|
||||
} else if f < GB {
|
||||
format!("{:.2} MB", f / MB)
|
||||
} else {
|
||||
format!("{:.2} GB", f / GB)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue