crabmail

Static HTML email archive viewer in Rust
git clone git://git.alexwennerberg.com/crabmail
Log | Files | Refs | README | LICENSE

commit 1311d0beabefbaf1f9728c0e071505ca6e826606
parent 6833e75d98a2e3fd2e27a96f56ab736dfb7cf155
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Sun, 27 Mar 2022 11:34:54 -0700

better ux on page idx

Diffstat:
MTODO | 4----
Msrc/templates/html.rs | 35+++++++++++++++++++++++++----------
2 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/TODO b/TODO @@ -1,9 +1,5 @@ TODO ==== -features --------- -paginate list home - qa -- cleanup atom threads diff --git a/src/templates/html.rs b/src/templates/html.rs @@ -51,18 +51,34 @@ impl Lists { } } +// current 0-indexed +fn build_page_idx(current: usize, total: usize) -> String { + if total == 1 { + return "".to_string(); + } + let mut page_idx = "<b>Pages</b>: ".to_string(); + for n in 0..total { + let path = match n { + 0 => "index.html".to_string(), + n => format!("index-{}.html", n + 1), + }; + if current == n { + page_idx.push_str("<b>"); + page_idx.push_str(&(n + 1).to_string()); + page_idx.push_str("</b> "); + } else { + page_idx.push_str(&format!("<a href='{}'>{}</a> ", path, n + 1)); + } + } + page_idx.push_str("<hr>"); + return page_idx; +} + impl List { pub fn to_html(&self) -> Vec<String> { // TODO paginate let page_count = self.thread_topics.len() / PAGE_SIZE + 1; - let mut page_idx = "<b>Pages</b>: ".to_string(); - for n in 0..page_count { - let path = match n { - 0 => "index.html".to_string(), - n => format!("index-{}.html", n + 1), - }; - page_idx.push_str(&format!("<a href='{}'>{}</a> ", path, n + 1)); - } + // hacky self.thread_topics .chunks(PAGE_SIZE) .enumerate() @@ -118,7 +134,6 @@ impl List { <hr> {threads} {page_idx} - <hr> "#, FOOTER ), @@ -128,7 +143,7 @@ impl List { ("title", self.config.title.as_str()), ("css_path", "../style.css"), ("threads", &threads), - ("page_idx", &page_idx), + ("page_idx", &build_page_idx(n, page_count)), ("list_email", &self.config.email), ("rss_svg", RSS_SVG), ("footer", FOOTER),