Skip to content

Commit

Permalink
Merge pull request #994 from chris-morgan/misc
Browse files Browse the repository at this point in the history
Chris Morgan’s whole bunch of miscellaneous work for landing
  • Loading branch information
Keats committed Apr 21, 2020
2 parents 8253adb + 4653e68 commit 0ac70cb
Show file tree
Hide file tree
Showing 44 changed files with 366 additions and 219 deletions.
21 changes: 19 additions & 2 deletions CHANGELOG.md
@@ -1,5 +1,24 @@
# Changelog

## 0.11.0 (unreleased)

### Breaking
- RSS feed support has been altered to allow, *and default to*, Atom feeds, Atom being technically superior and just as widely-supported in normal use cases.
- New config value `feed_filename`, defaulting to `atom.xml` (change to `rss.xml` to reinstate the old behaviour)
- Config value `rss_limit` is renamed to `feed_limit`
- Config value `languages.*.rss` is renamed to `languages.*.feed`
- Config value `generate_rss` is renamed to `generate_feed`

Users with existing feeds should either set `feed_filename = "rss.xml"` in config.toml to keep things the same, or set up a 3xx redirect from rss.xml to atom.xml so that existing feed consumers aren’t broken.

- The feed template variable `last_build_date` is renamed to `last_updated` to more accurately reflect its semantics
- The sitemap template’s `SitemapEntry` type’s `date` field has been renamed to `updated` to reflect that it will use the `updated` front-matter field if available, rather than `date`

### Other
- Add `updated` front-matter field for pages, which sitemap templates will use for the `SitemapEntry.date` field instead of the `date` front-matter field, and which the default Atom feed template will use
- Add `lang` to the feed template context
- Add `taxonomy` and `term` to the feed template context for taxonomy feeds

## 0.10.2 (unreleased)

- Fix link checker not looking for anchor with capital id/name
Expand All @@ -17,8 +36,6 @@
### Breaking
- Remove `toc` variable in section/page context and pass it to `page.toc` and `section.toc` instead so they are
accessible everywhere
- [Slugification](https://en.wikipedia.org/wiki/Slug_(web_publishing)#Slug) of paths, taxonomies and anchors is now configurable. By default, everything will still be slugified like in previous versions.
See documentation for information on how to disable it.

### Other
- Add zenburn syntax highlighting theme
Expand Down
43 changes: 24 additions & 19 deletions components/config/src/config.rs
Expand Up @@ -47,15 +47,15 @@ impl Default for Slugify {
pub struct Language {
/// The language code
pub code: String,
/// Whether to generate a RSS feed for that language, defaults to `false`
pub rss: bool,
/// Whether to generate a feed for that language, defaults to `false`
pub feed: bool,
/// Whether to generate search index for that language, defaults to `false`
pub search: bool,
}

impl Default for Language {
fn default() -> Self {
Language { code: String::new(), rss: false, search: false }
Language { code: String::new(), feed: false, search: false }
}
}

Expand All @@ -68,8 +68,8 @@ pub struct Taxonomy {
/// by this much
pub paginate_by: Option<usize>,
pub paginate_path: Option<String>,
/// Whether to generate a RSS feed only for each taxonomy term, defaults to false
pub rss: bool,
/// Whether to generate a feed only for each taxonomy term, defaults to false
pub feed: bool,
/// The language for that taxonomy, only used in multilingual sites.
/// Defaults to the config `default_language` if not set
pub lang: String,
Expand Down Expand Up @@ -99,7 +99,7 @@ impl Default for Taxonomy {
name: String::new(),
paginate_by: None,
paginate_path: None,
rss: false,
feed: false,
lang: String::new(),
}
}
Expand Down Expand Up @@ -155,10 +155,13 @@ pub struct Config {
/// Defaults to "base16-ocean-dark"
pub highlight_theme: String,

/// Whether to generate RSS. Defaults to false
pub generate_rss: bool,
/// The number of articles to include in the RSS feed. Defaults to including all items.
pub rss_limit: Option<usize>,
/// Whether to generate a feed. Defaults to false.
pub generate_feed: bool,
/// The number of articles to include in the feed. Defaults to including all items.
pub feed_limit: Option<usize>,
/// The filename to use for feeds. Used to find the template, too.
/// Defaults to "atom.xml", with "rss.xml" also having a template provided out of the box.
pub feed_filename: String,
/// If set, files from static/ will be hardlinked instead of copied to the output dir.
pub hard_link_static: bool,

Expand Down Expand Up @@ -276,11 +279,12 @@ impl Config {

/// Makes a url, taking into account that the base url might have a trailing slash
pub fn make_permalink(&self, path: &str) -> String {
let trailing_bit = if path.ends_with('/') || path.ends_with("rss.xml") || path.is_empty() {
""
} else {
"/"
};
let trailing_bit =
if path.ends_with('/') || path.ends_with(&self.feed_filename) || path.is_empty() {
""
} else {
"/"
};

// Index section with a base url that has a trailing slash
if self.base_url.ends_with('/') && path == "/" {
Expand Down Expand Up @@ -384,8 +388,9 @@ impl Default for Config {
highlight_theme: "base16-ocean-dark".to_string(),
default_language: "en".to_string(),
languages: Vec::new(),
generate_rss: false,
rss_limit: None,
generate_feed: false,
feed_limit: None,
feed_filename: "atom.xml".to_string(),
hard_link_static: false,
taxonomies: Vec::new(),
compile_sass: false,
Expand Down Expand Up @@ -493,10 +498,10 @@ hello = "world"

// https://github.com/Keats/gutenberg/issues/486
#[test]
fn doesnt_add_trailing_slash_to_rss() {
fn doesnt_add_trailing_slash_to_feed() {
let mut config = Config::default();
config.base_url = "http://vincent.is/".to_string();
assert_eq!(config.make_permalink("rss.xml"), "http://vincent.is/rss.xml");
assert_eq!(config.make_permalink("atom.xml"), "http://vincent.is/atom.xml");
}

#[test]
Expand Down
Empty file modified components/errors/src/lib.rs 100755 → 100644
Empty file.
4 changes: 4 additions & 0 deletions components/front_matter/src/page.rs
Expand Up @@ -16,6 +16,9 @@ pub struct PageFrontMatter {
pub title: Option<String>,
/// Description in <meta> that appears when linked, e.g. on twitter
pub description: Option<String>,
/// Updated date
#[serde(default, deserialize_with = "from_toml_datetime")]
pub updated: Option<String>,
/// Date if we want to order pages (ie blog post)
#[serde(default, deserialize_with = "from_toml_datetime")]
pub date: Option<String>,
Expand Down Expand Up @@ -117,6 +120,7 @@ impl Default for PageFrontMatter {
PageFrontMatter {
title: None,
description: None,
updated: None,
date: None,
datetime: None,
datetime_tuple: None,
Expand Down
10 changes: 5 additions & 5 deletions components/library/src/content/file_info.rs
Expand Up @@ -195,7 +195,7 @@ mod tests {
#[test]
fn can_find_valid_language_in_page() {
let mut config = Config::default();
config.languages.push(Language { code: String::from("fr"), rss: false, search: false });
config.languages.push(Language { code: String::from("fr"), feed: false, search: false });
let mut file = FileInfo::new_page(
&Path::new("/home/vincent/code/site/content/posts/tutorials/python.fr.md"),
&PathBuf::new(),
Expand All @@ -208,7 +208,7 @@ mod tests {
#[test]
fn can_find_valid_language_in_page_with_assets() {
let mut config = Config::default();
config.languages.push(Language { code: String::from("fr"), rss: false, search: false });
config.languages.push(Language { code: String::from("fr"), feed: false, search: false });
let mut file = FileInfo::new_page(
&Path::new("/home/vincent/code/site/content/posts/tutorials/python/index.fr.md"),
&PathBuf::new(),
Expand All @@ -234,7 +234,7 @@ mod tests {
#[test]
fn errors_on_unknown_language_in_page_with_i18n_on() {
let mut config = Config::default();
config.languages.push(Language { code: String::from("it"), rss: false, search: false });
config.languages.push(Language { code: String::from("it"), feed: false, search: false });
let mut file = FileInfo::new_page(
&Path::new("/home/vincent/code/site/content/posts/tutorials/python.fr.md"),
&PathBuf::new(),
Expand All @@ -246,7 +246,7 @@ mod tests {
#[test]
fn can_find_valid_language_in_section() {
let mut config = Config::default();
config.languages.push(Language { code: String::from("fr"), rss: false, search: false });
config.languages.push(Language { code: String::from("fr"), feed: false, search: false });
let mut file = FileInfo::new_section(
&Path::new("/home/vincent/code/site/content/posts/tutorials/_index.fr.md"),
&PathBuf::new(),
Expand All @@ -273,7 +273,7 @@ mod tests {
#[test]
fn correct_canonical_after_find_language() {
let mut config = Config::default();
config.languages.push(Language { code: String::from("fr"), rss: false, search: false });
config.languages.push(Language { code: String::from("fr"), feed: false, search: false });
let mut file = FileInfo::new_page(
&Path::new("/home/vincent/code/site/content/posts/tutorials/python/index.fr.md"),
&PathBuf::new(),
Expand Down
6 changes: 3 additions & 3 deletions components/library/src/content/page.rs
Expand Up @@ -770,7 +770,7 @@ Hello world
#[test]
fn can_specify_language_in_filename() {
let mut config = Config::default();
config.languages.push(Language { code: String::from("fr"), rss: false, search: false });
config.languages.push(Language { code: String::from("fr"), feed: false, search: false });
let content = r#"
+++
+++
Expand All @@ -787,7 +787,7 @@ Bonjour le monde"#
#[test]
fn can_specify_language_in_filename_with_date() {
let mut config = Config::default();
config.languages.push(Language { code: String::from("fr"), rss: false, search: false });
config.languages.push(Language { code: String::from("fr"), feed: false, search: false });
let content = r#"
+++
+++
Expand All @@ -806,7 +806,7 @@ Bonjour le monde"#
#[test]
fn i18n_frontmatter_path_overrides_default_permalink() {
let mut config = Config::default();
config.languages.push(Language { code: String::from("fr"), rss: false, search: false });
config.languages.push(Language { code: String::from("fr"), feed: false, search: false });
let content = r#"
+++
path = "bonjour"
Expand Down
6 changes: 3 additions & 3 deletions components/library/src/content/section.rs
Expand Up @@ -350,7 +350,7 @@ mod tests {
#[test]
fn can_specify_language_in_filename() {
let mut config = Config::default();
config.languages.push(Language { code: String::from("fr"), rss: false, search: false });
config.languages.push(Language { code: String::from("fr"), feed: false, search: false });
let content = r#"
+++
+++
Expand All @@ -372,7 +372,7 @@ Bonjour le monde"#
#[test]
fn can_make_links_to_translated_sections_without_double_trailing_slash() {
let mut config = Config::default();
config.languages.push(Language { code: String::from("fr"), rss: false, search: false });
config.languages.push(Language { code: String::from("fr"), feed: false, search: false });
let content = r#"
+++
+++
Expand All @@ -389,7 +389,7 @@ Bonjour le monde"#
#[test]
fn can_make_links_to_translated_subsections_with_trailing_slash() {
let mut config = Config::default();
config.languages.push(Language { code: String::from("fr"), rss: false, search: false });
config.languages.push(Language { code: String::from("fr"), feed: false, search: false });
let content = r#"
+++
+++
Expand Down
3 changes: 3 additions & 0 deletions components/library/src/content/ser.rs
Expand Up @@ -63,6 +63,7 @@ pub struct SerializingPage<'a> {
ancestors: Vec<String>,
title: &'a Option<String>,
description: &'a Option<String>,
updated: &'a Option<String>,
date: &'a Option<String>,
year: Option<i32>,
month: Option<u32>,
Expand Down Expand Up @@ -126,6 +127,7 @@ impl<'a> SerializingPage<'a> {
title: &page.meta.title,
description: &page.meta.description,
extra: &page.meta.extra,
updated: &page.meta.updated,
date: &page.meta.date,
year,
month,
Expand Down Expand Up @@ -182,6 +184,7 @@ impl<'a> SerializingPage<'a> {
title: &page.meta.title,
description: &page.meta.description,
extra: &page.meta.extra,
updated: &page.meta.updated,
date: &page.meta.date,
year,
month,
Expand Down
2 changes: 1 addition & 1 deletion components/library/src/sorting.rs
Expand Up @@ -6,7 +6,7 @@ use slotmap::DefaultKey;

use crate::content::Page;

/// Used by the RSS feed
/// Used by the feed
/// There to not have to import sorting stuff in the site crate
#[allow(clippy::trivially_copy_pass_by_ref)]
pub fn sort_actual_pages_by_date(a: &&Page, b: &&Page) -> Ordering {
Expand Down
6 changes: 3 additions & 3 deletions components/library/src/taxonomies/mod.rs
Expand Up @@ -458,7 +458,7 @@ mod tests {
#[test]
fn can_make_taxonomies_in_multiple_languages() {
let mut config = Config::default();
config.languages.push(Language { rss: false, code: "fr".to_string(), search: false });
config.languages.push(Language { feed: false, code: "fr".to_string(), search: false });
let mut library = Library::new(2, 0, true);

config.taxonomies = vec![
Expand Down Expand Up @@ -569,7 +569,7 @@ mod tests {
let mut config = Config::default();
config.slugify.taxonomies = SlugifyStrategy::Safe;
config.languages.push(Language {
rss: false,
feed: false,
code: "fr".to_string(),
..Language::default()
});
Expand Down Expand Up @@ -602,7 +602,7 @@ mod tests {
let mut config = Config::default();
config.slugify.taxonomies = SlugifyStrategy::On;
config.languages.push(Language {
rss: false,
feed: false,
code: "fr".to_string(),
..Language::default()
});
Expand Down
12 changes: 11 additions & 1 deletion components/rebuild/src/lib.rs
Expand Up @@ -395,7 +395,17 @@ pub fn after_template_change(site: &mut Site, path: &Path) -> Result<()> {

match filename {
"sitemap.xml" => site.render_sitemap(),
"rss.xml" => site.render_rss_feed(site.library.read().unwrap().pages_values(), None),
filename if filename == site.config.feed_filename => {
// FIXME: this is insufficient; for multilingual sites, it’s rendering the wrong
// content into the root feed, and it’s not regenerating any of the other feeds (other
// languages or taxonomies with feed enabled).
site.render_feed(
site.library.read().unwrap().pages_values(),
None,
&site.config.default_language,
None,
)
}
"split_sitemap_index.xml" => site.render_sitemap(),
"robots.txt" => site.render_robots(),
"single.html" | "list.html" => site.render_taxonomies(),
Expand Down
2 changes: 1 addition & 1 deletion components/site/benches/gen.py
Expand Up @@ -108,7 +108,7 @@ def gen_skeleton(name, is_blog):
theme = "sample"
taxonomies = [
{name = "tags", rss = true},
{name = "tags", feed = true},
{name = "categories"}
]
Expand Down
11 changes: 9 additions & 2 deletions components/site/benches/site.rs
Expand Up @@ -35,12 +35,19 @@ fn bench_render_sitemap(b: &mut test::Bencher) {
}

#[bench]
fn bench_render_rss_feed(b: &mut test::Bencher) {
fn bench_render_feed(b: &mut test::Bencher) {
let mut site = setup_site("big-blog");
let tmp_dir = tempdir().expect("create temp dir");
let public = &tmp_dir.path().join("public");
site.set_output_path(&public);
b.iter(|| site.render_rss_feed(site.library.read().unwrap().pages_values(), None).unwrap());
b.iter(|| {
site.render_feed(
site.library.read().unwrap().pages_values(),
None,
&site.config.default_language,
None,
).unwrap();
});
}

#[bench]
Expand Down

0 comments on commit 0ac70cb

Please sign in to comment.