Skip to content

Commit

Permalink
Merge pull request #529 from getzola/next
Browse files Browse the repository at this point in the history
0.5.1
  • Loading branch information
Keats authored Dec 14, 2018
2 parents 8e4c91c + 5eebbc6 commit 3685ed1
Show file tree
Hide file tree
Showing 26 changed files with 945 additions and 427 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ matrix:

# The earliest stable Rust version that works
- env: TARGET=x86_64-unknown-linux-gnu
rust: 1.29.0
rust: 1.30.0


before_install: set -e
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 0.5.1 (2018-12-14)

- Fix deleting markdown file in `zola serve`
- Fix pagination for taxonomies being broken and add missing documentation for it
- Add missing pager pages from the sitemap
- Allow and parse full RFC339 datetimes in filenames
- Live reload is now enabled for the 404 page on serve


## 0.5.0 (2018-11-17)

### Breaking
Expand Down
765 changes: 430 additions & 335 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zola"
version = "0.5.0"
version = "0.5.1"
authors = ["Vincent Prouillet <[email protected]>"]
license = "MIT"
readme = "README.md"
Expand Down
8 changes: 8 additions & 0 deletions components/config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ impl Taxonomy {
false
}
}

pub fn paginate_path(&self) -> &str {
if let Some(ref path) = self.paginate_path {
path
} else {
"page"
}
}
}

impl Default for Taxonomy {
Expand Down
39 changes: 29 additions & 10 deletions components/library/src/content/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ use content::file_info::FileInfo;
use content::ser::SerializingPage;

lazy_static! {
// Check whether a string starts with yyyy-mm-dd{-,_}
static ref DATE_IN_FILENAME: Regex = Regex::new(r"^^([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))(_|-)").unwrap();
// Based on https://regex101.com/r/H2n38Z/1/tests
// A regex parsing RFC3339 date followed by {_,-}, some characters and ended by .md
static ref RFC3339_DATE: Regex = Regex::new(
r"^(?P<datetime>(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])(T([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(Z|(\+|-)([01][0-9]|2[0-3]):([0-5][0-9])))?)(_|-)(?P<slug>.+$)"
).unwrap();
}

#[derive(Clone, Debug, PartialEq)]
Expand Down Expand Up @@ -113,11 +116,11 @@ impl Page {
page.word_count = Some(word_count);
page.reading_time = Some(reading_time);

let mut has_date_in_name = false;
if DATE_IN_FILENAME.is_match(&page.file.name) {
has_date_in_name = true;
let mut slug_from_dated_filename = None;
if let Some(ref caps) = RFC3339_DATE.captures(&page.file.name.replace(".md", "")) {
slug_from_dated_filename = Some(caps.name("slug").unwrap().as_str().to_string());
if page.meta.date.is_none() {
page.meta.date = Some(page.file.name[..10].to_string());
page.meta.date = Some(caps.name("datetime").unwrap().as_str().to_string());
page.meta.date_to_datetime();
}
}
Expand All @@ -132,9 +135,8 @@ impl Page {
slugify(&page.file.name)
}
} else {
if has_date_in_name {
// skip the date + the {_,-}
slugify(&page.file.name[11..])
if let Some(slug) = slug_from_dated_filename {
slugify(&slug)
} else {
slugify(&page.file.name)
}
Expand Down Expand Up @@ -507,7 +509,7 @@ Hello world
}

#[test]
fn can_get_date_from_filename() {
fn can_get_date_from_short_date_in_filename() {
let config = Config::default();
let content = r#"
+++
Expand All @@ -523,6 +525,23 @@ Hello world
assert_eq!(page.slug, "hello");
}

#[test]
fn can_get_date_from_full_rfc3339_date_in_filename() {
let config = Config::default();
let content = r#"
+++
+++
Hello world
<!-- more -->"#
.to_string();
let res = Page::parse(Path::new("2018-10-02T15:00:00Z-hello.md"), &content, &config);
assert!(res.is_ok());
let page = res.unwrap();

assert_eq!(page.meta.date, Some("2018-10-02T15:00:00Z".to_string()));
assert_eq!(page.slug, "hello");
}

#[test]
fn frontmatter_date_override_filename_date() {
let config = Config::default();
Expand Down
2 changes: 1 addition & 1 deletion components/library/src/content/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl Section {
pub fn parse(file_path: &Path, content: &str, config: &Config) -> Result<Section> {
let (meta, content) = split_section_content(file_path, content)?;
let mut section = Section::new(file_path, meta);
section.raw_content = content.clone();
section.raw_content = content;
let (word_count, reading_time) = get_reading_analytics(&section.raw_content);
section.word_count = Some(word_count);
section.reading_time = Some(reading_time);
Expand Down
13 changes: 7 additions & 6 deletions components/library/src/pagination/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use taxonomies::{Taxonomy, TaxonomyItem};
#[derive(Clone, Debug, PartialEq)]
enum PaginationRoot<'a> {
Section(&'a Section),
Taxonomy(&'a Taxonomy),
Taxonomy(&'a Taxonomy, &'a TaxonomyItem),
}

/// A list of all the pages in the paginator with their index and links
Expand Down Expand Up @@ -93,14 +93,14 @@ impl<'a> Paginator<'a> {
all_pages: &item.pages,
pagers: Vec::with_capacity(item.pages.len() / paginate_by),
paginate_by,
root: PaginationRoot::Taxonomy(taxonomy),
root: PaginationRoot::Taxonomy(taxonomy, item),
permalink: item.permalink.clone(),
path: format!("{}/{}", taxonomy.kind.name, item.slug),
paginate_path: taxonomy
.kind
.paginate_path
.clone()
.unwrap_or_else(|| "pages".to_string()),
.unwrap_or_else(|| "page".to_string()),
is_index: false,
template: format!("{}/single.html", taxonomy.kind.name),
};
Expand Down Expand Up @@ -212,8 +212,9 @@ impl<'a> Paginator<'a> {
context
.insert("section", &SerializingSection::from_section_basic(s, Some(library)));
}
PaginationRoot::Taxonomy(t) => {
PaginationRoot::Taxonomy(t, item) => {
context.insert("taxonomy", &t.kind);
context.insert("term", &item.serialize(library));
}
};
context.insert("current_url", &pager.permalink);
Expand Down Expand Up @@ -349,7 +350,7 @@ mod tests {

assert_eq!(paginator.pagers[1].index, 2);
assert_eq!(paginator.pagers[1].pages.len(), 1);
assert_eq!(paginator.pagers[1].permalink, "https://vincent.is/tags/something/pages/2/");
assert_eq!(paginator.pagers[1].path, "tags/something/pages/2/");
assert_eq!(paginator.pagers[1].permalink, "https://vincent.is/tags/something/page/2/");
assert_eq!(paginator.pagers[1].path, "tags/something/page/2/");
}
}
6 changes: 5 additions & 1 deletion components/library/src/taxonomies/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use library::Library;
use sorting::sort_pages_by_date;

#[derive(Debug, Clone, PartialEq, Serialize)]
struct SerializedTaxonomyItem<'a> {
pub struct SerializedTaxonomyItem<'a> {
name: &'a str,
slug: &'a str,
permalink: &'a str,
Expand Down Expand Up @@ -71,6 +71,10 @@ impl TaxonomyItem {

TaxonomyItem { name: name.to_string(), permalink, slug, pages }
}

pub fn serialize<'a>(&'a self, library: &'a Library) -> SerializedTaxonomyItem<'a> {
SerializedTaxonomyItem::from_item(self, library)
}
}

#[derive(Debug, Clone, PartialEq, Serialize)]
Expand Down
3 changes: 2 additions & 1 deletion components/rebuild/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ pub fn after_content_change(site: &mut Site, path: &Path) -> Result<()> {
if is_md {
// only delete if it was able to be added in the first place
if !index.exists() && !path.exists() {
delete_element(site, path, is_section)?;
return delete_element(site, path, is_section);
}

// Added another .md in a assets directory
Expand Down Expand Up @@ -352,6 +352,7 @@ pub fn after_template_change(site: &mut Site, path: &Path) -> Result<()> {
site.render_orphan_pages()
}
"section.html" => site.render_sections(),
"404.html" => site.render_404(),
// Either the index or some unknown template changed
// We can't really know what this change affects so rebuild all
// the things
Expand Down
15 changes: 14 additions & 1 deletion components/rebuild/tests/rebuild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,22 @@ fn can_rebuild_after_renaming_section_folder() {
fn can_rebuild_after_renaming_non_md_asset_in_colocated_folder() {
let tmp_dir = tempdir().expect("create temp dir");
let (site_path, mut site) = load_and_build_site!(tmp_dir);
let (old_path, new_path) = rename!(site_path, "content/posts/with-assets/zola.png", "gutenberg.png");
let (old_path, new_path) =
rename!(site_path, "content/posts/with-assets/zola.png", "gutenberg.png");

// Testing that we don't try to load some images as markdown or something
let res = after_content_rename(&mut site, &old_path, &new_path);
assert!(res.is_ok());
}

#[test]
fn can_rebuild_after_deleting_file() {
let tmp_dir = tempdir().expect("create temp dir");
let (site_path, mut site) = load_and_build_site!(tmp_dir);
let path = site_path.join("content").join("posts").join("fixed-slug.md");
fs::remove_file(&path).unwrap();

let res = after_content_change(&mut site, &path);
println!("{:?}", res);
assert!(res.is_ok());
}
2 changes: 1 addition & 1 deletion components/rendering/src/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct Rendered {
// means we will have example, example-1, example-2 etc
fn find_anchor(anchors: &[String], name: String, level: u8) -> String {
if level == 0 && !anchors.contains(&name) {
return name.to_string();
return name;
}

let new_anchor = format!("{}-{}", name, level + 1);
Expand Down
8 changes: 4 additions & 4 deletions components/rendering/src/shortcode.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use pest::iterators::Pair;
use pest::Parser;
use tera::{to_value, Context, Map, Value};
use regex::Regex;
use tera::{to_value, Context, Map, Value};

use context::RenderContext;
use errors::{Result, ResultExt};
Expand All @@ -20,9 +20,9 @@ lazy_static! {

fn replace_string_markers(input: &str) -> String {
match input.chars().next().unwrap() {
'"' => input.replace('"', "").to_string(),
'\'' => input.replace('\'', "").to_string(),
'`' => input.replace('`', "").to_string(),
'"' => input.replace('"', ""),
'\'' => input.replace('\'', ""),
'`' => input.replace('`', ""),
_ => unreachable!("How did you even get there"),
}
}
Expand Down
Loading

0 comments on commit 3685ed1

Please sign in to comment.