This commit is contained in:
parent
3e9bbffd58
commit
67feca4fc2
4 changed files with 51 additions and 22 deletions
|
@ -5,7 +5,7 @@ use comrak::{
|
||||||
ComrakRenderOptions, ListStyleType,
|
ComrakRenderOptions, ListStyleType,
|
||||||
};
|
};
|
||||||
use ramhorns::Content;
|
use ramhorns::Content;
|
||||||
use serde::Deserialize;
|
use serde::{Deserialize, Deserializer};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
#[derive(Default, Deserialize, Content, Debug)]
|
#[derive(Default, Deserialize, Content, Debug)]
|
||||||
|
@ -15,7 +15,27 @@ pub struct FileMetadata {
|
||||||
pub date: Option<Date>,
|
pub date: Option<Date>,
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
pub publish: Option<bool>,
|
pub publish: Option<bool>,
|
||||||
pub tags: Option<Vec<String>>,
|
pub tags: Option<Vec<Tag>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Content, Debug, Clone)]
|
||||||
|
pub struct Tag {
|
||||||
|
pub name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'de> Deserialize<'de> for Tag {
|
||||||
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
match <&str>::deserialize(deserializer) {
|
||||||
|
Ok(s) => match serde_yaml::from_str(s) {
|
||||||
|
Ok(tags) => Ok(Self { name: tags }),
|
||||||
|
Err(e) => Err(serde::de::Error::custom(e)),
|
||||||
|
},
|
||||||
|
Err(e) => Err(e),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Content, Debug)]
|
#[derive(Content, Debug)]
|
||||||
|
|
|
@ -66,6 +66,11 @@ pub fn build_index(config: Config, url: String) -> String {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Content, Debug)]
|
||||||
|
pub struct Tag {
|
||||||
|
pub name: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Content, Debug)]
|
#[derive(Content, Debug)]
|
||||||
struct Post {
|
struct Post {
|
||||||
title: String,
|
title: String,
|
||||||
|
@ -73,7 +78,7 @@ struct Post {
|
||||||
url: String,
|
url: String,
|
||||||
desc: Option<String>,
|
desc: Option<String>,
|
||||||
content: Option<String>,
|
content: Option<String>,
|
||||||
tags: Option<Vec<String>>,
|
tags: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Post {
|
impl Post {
|
||||||
|
@ -129,9 +134,6 @@ fn get_posts(location: &str) -> Vec<Post> {
|
||||||
None => Some(file_without_ext.into()),
|
None => Some(file_without_ext.into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
// No tags if the vec is empty
|
|
||||||
metadata.tags = metadata.tags.filter(|tags| !tags.is_empty());
|
|
||||||
|
|
||||||
metadata
|
metadata
|
||||||
}
|
}
|
||||||
Err(_) => FileMetadata {
|
Err(_) => FileMetadata {
|
||||||
|
@ -159,7 +161,12 @@ fn get_posts(location: &str) -> Vec<Post> {
|
||||||
}),
|
}),
|
||||||
desc: file_metadata.description,
|
desc: file_metadata.description,
|
||||||
content: None,
|
content: None,
|
||||||
tags: file_metadata.tags,
|
tags: file_metadata
|
||||||
|
.tags
|
||||||
|
.unwrap_or_default()
|
||||||
|
.iter()
|
||||||
|
.map(|t| t.name.to_owned())
|
||||||
|
.collect(),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -223,7 +230,7 @@ fn get_post(post: &mut Option<File>, filename: String, name: String, url: String
|
||||||
vec!["blog", "blogging", "write", "writing"]
|
vec!["blog", "blogging", "write", "writing"]
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&tag| tag.to_owned())
|
.map(|&tag| tag.to_owned())
|
||||||
.chain(tags.into_iter())
|
.chain(tags.into_iter().map(|t| t.name))
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join(", "),
|
.join(", "),
|
||||||
),
|
),
|
||||||
|
@ -297,16 +304,14 @@ fn build_rss(config: Config, info: ConnectionInfo) -> String {
|
||||||
title: Some(p.title.to_owned()),
|
title: Some(p.title.to_owned()),
|
||||||
link: Some(format!("{}/blog/p/{}", link_to_site, p.url)),
|
link: Some(format!("{}/blog/p/{}", link_to_site, p.url)),
|
||||||
description: p.content.to_owned(),
|
description: p.content.to_owned(),
|
||||||
categories: match &p.tags {
|
categories: p
|
||||||
Some(tags) => tags
|
.tags
|
||||||
.iter()
|
.iter()
|
||||||
.map(|c| Category {
|
.map(|c| Category {
|
||||||
name: c.into(),
|
name: c.to_owned(),
|
||||||
..Category::default()
|
..Category::default()
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
None => vec![],
|
|
||||||
},
|
|
||||||
guid: Some(Guid {
|
guid: Some(Guid {
|
||||||
value: format!("urn:hash:{}", {
|
value: format!("urn:hash:{}", {
|
||||||
let mut hasher = DefaultHasher::new();
|
let mut hasher = DefaultHasher::new();
|
||||||
|
|
|
@ -63,7 +63,7 @@ header > h1 {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Date's title */
|
/* Date's title */
|
||||||
header > p {
|
header > span {
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,13 @@
|
||||||
<header>
|
<header>
|
||||||
{{#info}}
|
{{#info}}
|
||||||
<h1>{{title}}</h1>
|
<h1>{{title}}</h1>
|
||||||
{{#date}}
|
{{#date}} {{>blog/date.html}} {{/date}}
|
||||||
<p>{{>blog/date.html}}</p>
|
<ul>
|
||||||
{{/date}} {{/info}} {{/metadata}} {{/post}}
|
{{#tags}}
|
||||||
|
<li>{{name}}</li>
|
||||||
|
{{/tags}}
|
||||||
|
</ul>
|
||||||
|
{{/info}} {{/metadata}} {{/post}}
|
||||||
</header>
|
</header>
|
||||||
<main>
|
<main>
|
||||||
{{^post}}
|
{{^post}}
|
||||||
|
|
Loading…
Reference in a new issue