-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Atom 1.0 support #1089
Atom 1.0 support #1089
Changes from all commits
e6f7914
0e7ad27
12ccd70
045e400
1d655ba
6dd3776
f7d2d06
9e85743
8b32161
b35e2fa
e61a0e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,12 +21,16 @@ pub struct Frontmatter { | |
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub categories: Option<Vec<liquid_core::model::KString>>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub authors: Option<Vec<liquid_core::model::KString>>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub tags: Option<Vec<liquid_core::model::KString>>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub excerpt_separator: Option<liquid_core::model::KString>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub published_date: Option<DateTime>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub updated_date: Option<DateTime>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you split this out into its own issue / PR? #197 exists but that is more about automatically inferring it |
||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub format: Option<SourceFormat>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub templated: Option<bool>, | ||
|
@@ -99,11 +103,13 @@ impl Frontmatter { | |
slug, | ||
title, | ||
description, | ||
authors, | ||
excerpt, | ||
categories, | ||
tags, | ||
excerpt_separator, | ||
published_date, | ||
updated_date, | ||
format, | ||
templated, | ||
layout, | ||
|
@@ -118,11 +124,13 @@ impl Frontmatter { | |
slug: slug.or_else(|| other.slug.clone()), | ||
title: title.or_else(|| other.title.clone()), | ||
description: description.or_else(|| other.description.clone()), | ||
authors: authors.or_else(|| other.authors.clone()), | ||
excerpt: excerpt.or_else(|| other.excerpt.clone()), | ||
categories: categories.or_else(|| other.categories.clone()), | ||
tags: tags.or_else(|| other.tags.clone()), | ||
excerpt_separator: excerpt_separator.or_else(|| other.excerpt_separator.clone()), | ||
published_date: published_date.or(other.published_date), | ||
updated_date: updated_date.or(other.updated_date), | ||
format: format.or(other.format), | ||
templated: templated.or(other.templated), | ||
layout: layout.or_else(|| other.layout.clone()), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,16 @@ use std::collections::HashMap; | |
use std::fs; | ||
use std::io::Write; | ||
use std::path; | ||
use std::time::SystemTime; | ||
|
||
use failure::ResultExt; | ||
use jsonfeed::Feed; | ||
use log::debug; | ||
use log::trace; | ||
use log::warn; | ||
use sitemap::writer::SiteMapWriter; | ||
use vimwiki::vendor::chrono::DateTime; | ||
use vimwiki::vendor::chrono::Utc; | ||
Comment on lines
+13
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't be relying on vimwiki like this. If we need chrono, we should use chrono. |
||
|
||
use crate::cobalt_model; | ||
use crate::cobalt_model::files; | ||
|
@@ -142,6 +145,16 @@ pub fn build(config: Config) -> Result<()> { | |
context.site.base_url.as_deref(), | ||
)?; | ||
} | ||
// check if we should creeate an atom file and create it! | ||
if let Some(ref path) = context.posts.atom { | ||
let path = path.to_path(&context.destination); | ||
create_atom( | ||
&path, | ||
&context.posts, | ||
&posts, | ||
context.site.base_url.as_deref(), | ||
)?; | ||
} | ||
if let Some(ref path) = context.site.sitemap { | ||
let path = path.to_path(&context.destination); | ||
create_sitemap(&path, &posts, &documents, context.site.base_url.as_deref())?; | ||
|
@@ -506,6 +519,60 @@ fn create_jsonfeed( | |
Ok(()) | ||
} | ||
|
||
fn create_atom( | ||
path: &std::path::Path, | ||
collection: &Collection, | ||
documents: &[Document], | ||
base_url: Option<&str>, | ||
) -> Result<()> { | ||
debug!("Creating Atom file at {}", path.display()); | ||
|
||
let title = &collection.title; | ||
let description = collection.description.as_deref().unwrap_or(""); | ||
let link = base_url | ||
.as_ref() | ||
.ok_or_else(|| failure::err_msg("`base_url` is required for atom support"))?; | ||
|
||
let entries: Result<Vec<atom_syndication::Entry>> = | ||
documents.iter().map(|doc| doc.to_atom(link)).collect(); | ||
let entries = entries?; | ||
|
||
// Assume the feed's "updated" is the same as the most recent | ||
// updated/published post. | ||
// If no entries exist, use the current time. | ||
let feed_updated = entries | ||
.iter() | ||
.map(|entry| entry.updated) | ||
.max() | ||
.unwrap_or_else(|| { | ||
atom_syndication::FixedDateTime::from(DateTime::<Utc>::from(SystemTime::now())) | ||
}); | ||
|
||
// Build the feed object | ||
let feed = atom_syndication::FeedBuilder::default() | ||
.id(link.to_string()) | ||
.updated(feed_updated) | ||
.subtitle(Some(atom_syndication::Text::plain(description.to_string()))) | ||
.links(vec![atom_syndication::Link { | ||
href: link.to_string(), | ||
..Default::default() | ||
}]) | ||
.title(atom_syndication::Text::plain(title.to_string())) | ||
.entries(entries) | ||
.build(); | ||
|
||
// create target directories if any exist | ||
if let Some(parent) = path.parent() { | ||
fs::create_dir_all(parent) | ||
.with_context(|_| failure::format_err!("Could not create {}", parent.display()))?; | ||
} | ||
Comment on lines
+564
to
+568
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The other ones don't have this. Is there a reason to do it to one vs all? |
||
|
||
let atom_string = feed.to_string(); | ||
files::write_document_file(atom_string, path)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn create_sitemap( | ||
path: &path::Path, | ||
documents: &[Document], | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
posts: | ||
atom: atom.xml | ||
default: | ||
authors: | ||
- Alice | ||
- Bob | ||
site: | ||
title: "My blog!" | ||
description: Blog description | ||
base_url: "http://example.com" | ||
syntax_highlight: | ||
enabled: false |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>test</title> | ||
</head> | ||
<body> | ||
<h1>{{ page.permalink }}</h1> | ||
|
||
{{ page.content }} | ||
</body> | ||
</html> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>My blog - {{ page.title }}</title> | ||
</head> | ||
<body> | ||
{{ page.content }} | ||
</body> | ||
</html> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
layout: default.liquid | ||
--- | ||
This is my Index page! | ||
|
||
{% for post in collections.posts.pages %} | ||
<a href="{{post.permalink}}">{{ post.title }}</a> | ||
{% endfor %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
layout: posts.liquid | ||
|
||
title: My fifth Blogpost! | ||
published_date: 2016-02-16 10:00:00 +0100 | ||
--- | ||
# {{ page.title }} | ||
|
||
Hey there this is my first blogpost and this is super awesome. | ||
|
||
My Blog is lorem ipsum like, yes it is.. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you split this out into its own Issue / PR?