Skip to content

Commit

Permalink
Make resource date mandatory.
Browse files Browse the repository at this point in the history
  • Loading branch information
ibz committed Aug 23, 2024
1 parent dc829fc commit f625392
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
32 changes: 15 additions & 17 deletions src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct PageTemplateContext<TagType> {
slug: String,
summary: Option<String>,
content: String,
date: Option<NaiveDateTime>,
date: NaiveDateTime,
#[serde(flatten)]
tags: HashMap<String, TagType>,
}
Expand All @@ -38,7 +38,7 @@ pub struct Resource {
pub slug: String,

pub title: Option<String>,
pub date: Option<NaiveDateTime>,
pub date: NaiveDateTime,

pub content_source: ContentSource,
}
Expand Down Expand Up @@ -196,28 +196,26 @@ fn render_atom_xml(site_url: &str, site: &Site) -> (mime::Mime, String) {
response.push_str(&format!("<id>{}</id>\n", site_url));
let resources = site.resources.read().unwrap();
for (url, resource) in &*resources {
if resource.date.is_some() {
if let Some((_, content)) = resource.read(site) {
response.push_str(
&format!(
"<entry>
if let Some((_, content)) = resource.read(site) {
response.push_str(
&format!(
"<entry>
<title>{}</title>
<link href=\"{}\"/>
<updated>{}</updated>
<id>{}/{}</id>
<content type=\"xhtml\"><div xmlns=\"http://www.w3.org/1999/xhtml\">{}</div></content>
</entry>
",
resource.title.clone().unwrap_or("".to_string()),
&url,
&resource.date.unwrap(),
site_url,
resource.slug.clone(),
&md_to_html(&content).to_owned()
)
.to_owned(),
);
}
resource.title.clone().unwrap_or("".to_string()),
&url,
&resource.date,
site_url,
resource.slug.clone(),
&md_to_html(&content).to_owned()
)
.to_owned(),
);
}
}
response.push_str("</feed>");
Expand Down
9 changes: 7 additions & 2 deletions src/site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ impl Site {
} else if relative_path.starts_with("pages") {
if front_matter.contains_key("title") {
kind = Some(ResourceKind::Page);
date = front_matter.get("created_at").map(|c| {
Utc.timestamp_opt(c.as_i64().unwrap(), 0)
.unwrap()
.naive_utc()
});
slug = Some(file_stem.to_owned());
title = Some(
front_matter
Expand All @@ -214,7 +219,7 @@ impl Site {

content_source = ContentSource::File(filename);
}
if let (Some(kind), Some(slug)) = (kind, slug) {
if let (Some(kind), Some(date), Some(slug)) = (kind, date, slug) {
let resource = Resource {
kind,
title,
Expand Down Expand Up @@ -296,7 +301,7 @@ impl Site {
let resource = Resource {
kind,
title: event.get_tags_hash().get("title").cloned(),
date: event.get_long_form_published_at(),
date: event.get_date(),
slug,
content_source: ContentSource::Event(event.id.to_owned()),
};
Expand Down

0 comments on commit f625392

Please sign in to comment.