-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
mod.rs
63 lines (56 loc) · 1.45 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use crate::common::{utils::extract_domain, DbArticle, DbPerson};
use chrono::{DateTime, Local, Utc};
use leptos::*;
pub mod api;
pub mod app;
mod components;
pub mod error;
pub mod markdown;
pub mod pages;
#[cfg(feature = "hydrate")]
#[wasm_bindgen::prelude::wasm_bindgen]
pub fn hydrate() {}
fn article_link(article: &DbArticle) -> String {
if article.local {
format!("/article/{}", article.title)
} else {
format!(
"/article/{}@{}",
article.title,
extract_domain(&article.ap_id)
)
}
}
fn article_title(article: &DbArticle) -> String {
let title = article.title.replace('_', " ");
if article.local {
title
} else {
format!("{}@{}", title, extract_domain(&article.ap_id))
}
}
fn user_title(person: &DbPerson) -> String {
if person.local {
person.username.clone()
} else {
format!("{}@{}", person.username, extract_domain(&person.ap_id))
}
}
fn user_link(person: &DbPerson) -> impl IntoView {
let creator_path = if person.local {
format!("/user/{}", person.username)
} else {
format!(
"/user/{}@{}",
person.username,
extract_domain(&person.ap_id)
)
};
view! { <a href=creator_path>{user_title(person)}</a> }
}
fn render_date_time(date_time: DateTime<Utc>) -> String {
date_time
.with_timezone(&Local)
.format("%Y-%m-%d %H:%M:%S")
.to_string()
}