switch from crazy macro to trait for path variable substitution

This commit is contained in:
Trevor Bentley
2023-01-16 03:42:40 +01:00
parent ca747583d2
commit 78156268ba
5 changed files with 178 additions and 77 deletions
+5 -2
View File
@@ -24,7 +24,7 @@ use crate::git::GitFile;
use chrono::{naive::NaiveDateTime, offset::FixedOffset, DateTime};
use serde::Serialize;
use std::collections::HashMap;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use tera::{from_value, to_value, try_get_value, Filter, Function, Value};
fn ts_to_date(ts: i64, offset: Option<i64>, format: Option<String>) -> String {
@@ -180,7 +180,10 @@ pub struct Pagination {
pub prev_page: Option<String>,
}
impl Pagination {
pub fn new(cur: usize, total: usize, url_template: &str) -> Self {
pub fn new<P: AsRef<Path>>(cur: usize, total: usize, url_template: &P) -> Self {
let url_template = url_template.as_ref().to_str()
.expect(&format!("ERROR: attempted to paginate unparseable path: {}",
url_template.as_ref().display()));
let digits = total.to_string().len().max(2);
let next = match cur + 1 <= total {
true => Some(cur + 1),