add metadata for index file
All checks were successful
ci/woodpecker/push/publish Pipeline was successful

This commit is contained in:
Mylloon 2024-01-24 13:09:20 +01:00
parent 17850ae636
commit c18c0adf34
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
3 changed files with 49 additions and 15 deletions

View file

@ -49,6 +49,15 @@ pub struct FileMetadataContact {
pub description: Option<String>,
}
/// Metadata for index page
#[derive(Default, Deserialize, Content, Debug)]
pub struct FileMetadataIndex {
pub name: Option<String>,
pub pronouns: Option<String>,
pub avatar: Option<String>,
pub avatar_caption: Option<String>,
}
/// Metadata for portfolio cards
#[derive(Default, Deserialize, Content, Debug)]
pub struct FileMetadataPortfolio {
@ -63,6 +72,7 @@ pub enum TypeFileMetadata {
Blog,
Contact,
Generic,
Index,
Portfolio,
}
@ -72,6 +82,7 @@ pub enum TypeFileMetadata {
pub struct FileMetadata {
pub blog: Option<FileMetadataBlog>,
pub contact: Option<FileMetadataContact>,
pub index: Option<FileMetadataIndex>,
pub portfolio: Option<FileMetadataPortfolio>,
}
@ -246,6 +257,10 @@ pub fn get_metadata<'a>(root: &'a AstNode<'a>, mtype: TypeFileMetadata) -> FileM
TypeFileMetadata::Generic => FileMetadata {
..FileMetadata::default()
},
TypeFileMetadata::Index => FileMetadata {
index: Some(deserialize_metadata(text)),
..FileMetadata::default()
},
TypeFileMetadata::Portfolio => FileMetadata {
portfolio: Some(deserialize_metadata(text)),
..FileMetadata::default()
@ -267,6 +282,10 @@ pub fn get_metadata<'a>(root: &'a AstNode<'a>, mtype: TypeFileMetadata) -> FileM
TypeFileMetadata::Generic => FileMetadata {
..FileMetadata::default()
},
TypeFileMetadata::Index => FileMetadata {
index: Some(FileMetadataIndex::default()),
..FileMetadata::default()
},
TypeFileMetadata::Portfolio => FileMetadata {
portfolio: Some(FileMetadataPortfolio::default()),
..FileMetadata::default()

View file

@ -19,19 +19,35 @@ async fn page(config: web::Data<Config>) -> impl Responder {
#[derive(Content, Debug)]
struct IndexTemplate {
navbar: NavBar,
fullname: String,
name: String,
pronouns: Option<String>,
content: Option<File>,
avatar: String,
avatar_caption: String,
}
#[once(time = 60)]
fn build_page(config: Config) -> String {
let mut content = read_file(
let mut file = read_file(
&format!("{}/index.md", config.locations.data_dir),
TypeFileMetadata::Generic,
TypeFileMetadata::Index,
);
if content.is_none() {
content = read_file("README.md", TypeFileMetadata::Generic);
// Default values
let mut name = config.fc.fullname.to_owned().unwrap_or_default();
let mut pronouns = None;
let mut avatar = "/icons/apple-touch-icon.png".to_owned();
let mut avatar_caption = "EWP avatar".to_owned();
if let Some(f) = &file {
if let Some(m) = &f.metadata.info.index {
name = m.name.to_owned().unwrap_or(name);
avatar = m.avatar.to_owned().unwrap_or(avatar);
pronouns = m.pronouns.to_owned();
avatar_caption = m.avatar_caption.to_owned().unwrap_or(avatar_caption);
}
} else {
file = read_file("README.md", TypeFileMetadata::Generic);
}
config.tmpl.render(
@ -41,12 +57,11 @@ fn build_page(config: Config) -> String {
index: true,
..NavBar::default()
},
fullname: config
.fc
.fullname
.to_owned()
.unwrap_or("Fullname".to_owned()),
content,
content: file,
name,
pronouns,
avatar,
avatar_caption,
},
Infos {
page_title: config.fc.fullname,

View file

@ -10,13 +10,13 @@
{{#data}}
<div>
<span id="name">{{fullname}}</span>
<span id="pronouns">(il/lui, he/him)</span>
<span id="name">{{name}}</span>
{{#pronouns}}<span id="pronouns">{{pronouns}}</span>{{/pronouns}}
<img
id="avatar"
src="/icons/apple-touch-icon.png"
src="{{avatar}} "
alt="Avatar"
title="Mon avatar, dessiné un jour super rapidement sur Gimp."
title="{{avatar_caption}} "
loading="lazy"
/>
</div>