feat(template): profile template works great :D
This commit is contained in:
parent
436331bc72
commit
5340afbf94
3 changed files with 63 additions and 29 deletions
38
froxy-templates/examples/profile.rs
Normal file
38
froxy-templates/examples/profile.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
use froxy_templates::profile::{self};
|
||||
use smol_str::SmolStr;
|
||||
|
||||
/*
|
||||
{
|
||||
friends: std::array::from_fn::<_, 10, _>(|i| Friend {
|
||||
name: "maiboyer".into(),
|
||||
image: "https://friends.42paris.fr/proxy/resize/512/03c61af252becbca11aac5ff49a2e61c/maiboyer.jpg".into(),
|
||||
position: (i < 5).then_some("f1r1s1".into()),
|
||||
last_active: (i > 6).then_some("Last thuesday".into()),
|
||||
}).to_vec(),
|
||||
}
|
||||
*/
|
||||
|
||||
fn main() {
|
||||
let mut env = minijinja::Environment::new();
|
||||
profile::add_to_context(&mut env);
|
||||
let data = profile::render(
|
||||
&env,
|
||||
profile::ProfileData {
|
||||
user: profile::ProfileUser {
|
||||
position: Some(SmolStr::new_static("f1r1s1")),
|
||||
last_active: None,
|
||||
image: "https://friends.42paris.fr/proxy/resize/512/03c61af252becbca11aac5ff49a2e61c/maiboyer.jpg".into(),
|
||||
name: SmolStr::new_static("maiboyer"),
|
||||
pool: None, //Some(SmolStr::new_static("August 2025")),
|
||||
is_friend: false,
|
||||
github: Some("https://github.com/Maix0".to_string()),
|
||||
website: None, //Some("https://maix.me".to_string()),
|
||||
discord: None,// Some("maix".to_string()),
|
||||
recit: Some("Yes".to_string()),
|
||||
},
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
println!("{data}");
|
||||
}
|
||||
|
|
@ -21,13 +21,11 @@ pub fn render(env: &minijinja::Environment, data: ProfileData) -> Result<String,
|
|||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct ProfileUser {
|
||||
pub position: Option<SmolStr>,
|
||||
pub last_active: SmolStr,
|
||||
pub last_active: Option<SmolStr>,
|
||||
pub image: String,
|
||||
pub name: SmolStr,
|
||||
pub pool: Option<SmolStr>,
|
||||
pub id: u64,
|
||||
pub is_friend: bool,
|
||||
pub is_self: bool,
|
||||
|
||||
pub github: Option<String>,
|
||||
pub website: Option<String>,
|
||||
|
|
|
|||
|
|
@ -22,32 +22,30 @@
|
|||
<div class="display-inline-grid ms-3">
|
||||
<h1 class="display-5 fw-bold">
|
||||
{{ user.name }}
|
||||
{% if 'None' not in user.pool %}<span class="fs-6 text-muted ">Piscine de {{ user.pool }}</span>{% endif %}
|
||||
{% if user.pool %}<span class="fs-6 text-muted ">Piscine de {{ user.pool }}</span>{% endif %}
|
||||
</h1>
|
||||
<span class="text-left">
|
||||
<i class="fa-solid {{ "fa-2=xs fa-circle online" if user.position else "fa-xs fa-person-walking offline" }}"></i>
|
||||
{{ user.position if user.position else 'Absent' }} {{ user.last_active }}
|
||||
{{ user.position if user.position else "Absent" }} {{ user.last_active if user.last_active or ""}}
|
||||
{% if user.position %}<a class="fa-solid fa-users-viewfinder" href="/goto/{{ user.position }}"></a>{% endif %}
|
||||
</span>
|
||||
<span class="text-left">
|
||||
{% if !user.is_self %}
|
||||
<button {{ 'hidden' if user.is_friend else '' }}
|
||||
type="button"
|
||||
class="btn btn-sm btn-outline-success online"
|
||||
id="addLocalFriend">
|
||||
<i class="fa-solid fa-user-plus"></i>
|
||||
<i hidden class="spinner-border spinner-border-sm"></i>
|
||||
Ajouter {{ user.name }} en ami
|
||||
</button>
|
||||
<button {{ 'hidden' if not user.is_friend else '' }}
|
||||
type="button"
|
||||
class="btn btn-sm btn-outline-danger"
|
||||
id="removeLocalFriend">
|
||||
<i class="fa-solid fa-user-minus"></i>
|
||||
<i hidden class="spinner-border spinner-border-sm"></i>
|
||||
Retirer {{ user.name }} des amis
|
||||
</button>
|
||||
{% endif %}
|
||||
<button {{ 'hidden' if user.is_friend else '' }}
|
||||
type="button"
|
||||
class="btn btn-sm btn-outline-success online"
|
||||
id="addLocalFriend">
|
||||
<i class="fa-solid fa-user-plus"></i>
|
||||
<i hidden class="spinner-border spinner-border-sm"></i>
|
||||
Ajouter {{ user.name }} en ami
|
||||
</button>
|
||||
<button {{ 'hidden' if not user.is_friend else '' }}
|
||||
type="button"
|
||||
class="btn btn-sm btn-outline-danger"
|
||||
id="removeLocalFriend">
|
||||
<i class="fa-solid fa-user-minus"></i>
|
||||
<i hidden class="spinner-border spinner-border-sm"></i>
|
||||
Retirer {{ user.name }} des amis
|
||||
</button>
|
||||
<button type="button"
|
||||
onclick="newTab('https://profile.intra.42.fr/users/{{ user.name }}');"
|
||||
class="btn btn-sm btn-outline-secondary">
|
||||
|
|
@ -63,17 +61,17 @@
|
|||
{%- if user.github or user.website or user.discord -%}
|
||||
<p class="mb-0">Contacts</p>
|
||||
<ul>
|
||||
{%- if 'github' in user and len(user.github) >= 1 -%}
|
||||
{%- if 'github' in user and user.github -%}
|
||||
<li>
|
||||
<i class="fa-brands fa-github icon-length"></i> <a href="{{ user.github }}">{{ user.github.replace('https://github.com/', '') }}</a>
|
||||
<i class="fa-brands fa-github icon-length"></i> <a href="{{ user.github }}">{{ user.github |replace("https://github.com/", "") }}</a>
|
||||
</li>
|
||||
{%- endif -%}
|
||||
{%- if 'website' in user and len(user.website) >= 1 -%}
|
||||
{%- if 'website' in user and user.website -%}
|
||||
<li>
|
||||
<i class="fa-solid fa-globe icon-length"></i> <a href="{{ user.website }}">{{ user.website.replace('https://', '').replace("http://", "") }}</a>
|
||||
<i class="fa-solid fa-globe icon-length"></i> <a href="{{ user.website }}">{{ user.website |replace("https://", "")|replace("http://", "") }}</a>
|
||||
</li>
|
||||
{%- endif -%}
|
||||
{%- if 'discord' and len(user.discord) >= 1 -%}
|
||||
{%- if 'discord' and user.discord -%}
|
||||
<li>
|
||||
<i class="fa-brands fa-discord icon-length"></i> <a>{{ user.discord }}</a>
|
||||
</li>
|
||||
|
|
@ -81,7 +79,7 @@
|
|||
</ul>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="col-md-8" style="text-align: justify;">{{ user.recit if user.recit and len(user.recit) > 0 else '' }}</div>
|
||||
<div class="col-md-8" style="text-align: justify;">{{ user.recit if user.recit and user.recit else '' }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue