https://dev.kronoz.win/r/rgit.git
1// sorry clippy, we don't have a choice. askama forces this on us
2#![allow(clippy::unnecessary_wraps, clippy::trivially_copy_pass_by_ref)]
3
4use std::borrow::Borrow;
5
6pub fn timeago(s: impl Borrow<time::OffsetDateTime>) -> Result<String, askama::Error> {
7 Ok(timeago::Formatter::new()
8 .convert((time::OffsetDateTime::now_utc() - *s.borrow()).unsigned_abs()))
9}
10
11pub fn file_perms(s: &i32) -> Result<String, askama::Error> {
12 Ok(unix_mode::to_string(s.unsigned_abs()))
13}
14
15pub fn hex(s: &[u8]) -> Result<String, askama::Error> {
16 Ok(hex::encode(s))
17}
18
19pub fn md5(s: &str) -> Result<String, askama::Error> {
20 Ok(hex::encode(md5::compute(s).0))
21}
22
23#[allow(dead_code)]
24pub fn md(md: &str) -> Result<String, askama::Error> {
25 Ok(comrak::markdown_to_html(
26 md,
27 &comrak::ComrakOptions::default(),
28 ))
29}