@@ -733,7 +733,7 @@ dependencies = [ | |||||
[[package]] | [[package]] | ||||
name = "gutenberg" | name = "gutenberg" | ||||
version = "0.4.1" | |||||
version = "0.4.2" | |||||
dependencies = [ | dependencies = [ | ||||
"actix-web 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", | "actix-web 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", | ||||
"chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", | "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", | ||||
@@ -1,6 +1,6 @@ | |||||
[package] | [package] | ||||
name = "gutenberg" | name = "gutenberg" | ||||
version = "0.4.1" | |||||
version = "0.4.2" | |||||
authors = ["Vincent Prouillet <prouillet.vincent@gmail.com>"] | authors = ["Vincent Prouillet <prouillet.vincent@gmail.com>"] | ||||
license = "MIT" | license = "MIT" | ||||
readme = "README.md" | readme = "README.md" | ||||
@@ -7,6 +7,7 @@ extern crate front_matter; | |||||
extern crate config; | extern crate config; | ||||
use std::collections::HashMap; | use std::collections::HashMap; | ||||
use std::path::Path; | |||||
use config::Config; | use config::Config; | ||||
use tera::Tera; | use tera::Tera; | ||||
@@ -14,19 +15,16 @@ use front_matter::{SortBy, InsertAnchor}; | |||||
use content::{Page, sort_pages, populate_siblings}; | use content::{Page, sort_pages, populate_siblings}; | ||||
fn create_pages(number: usize, sort_by: SortBy) -> Vec<Page> { | |||||
fn create_pages(number: usize) -> Vec<Page> { | |||||
let mut pages = vec![]; | let mut pages = vec![]; | ||||
let config = Config::default(); | let config = Config::default(); | ||||
let tera = Tera::default(); | |||||
let mut tera = Tera::default(); | |||||
tera.add_raw_template("shortcodes/youtube.html", "hello"); | |||||
let permalinks = HashMap::new(); | let permalinks = HashMap::new(); | ||||
for i in 0..number { | for i in 0..number { | ||||
let mut page = Page::default(); | let mut page = Page::default(); | ||||
match sort_by { | |||||
SortBy::Weight => { page.meta.weight = Some(i); } | |||||
SortBy::Order => { page.meta.order = Some(i); } | |||||
_ => (), | |||||
}; | |||||
page.meta.weight = Some(i); | |||||
page.raw_content = r#" | page.raw_content = r#" | ||||
# Modus cognitius profanam ne duae virtutis mundi | # Modus cognitius profanam ne duae virtutis mundi | ||||
@@ -98,7 +96,7 @@ if __name__ == "__main__": | |||||
gen_site("basic-blog", [""], 250, paginate=True) | gen_site("basic-blog", [""], 250, paginate=True) | ||||
``` | ``` | ||||
"#.to_string(); | "#.to_string(); | ||||
page.render_markdown(&permalinks, &tera, &config, InsertAnchor::None).unwrap(); | |||||
page.render_markdown(&permalinks, &tera, &config, &Path::new(""), InsertAnchor::None).unwrap(); | |||||
pages.push(page); | pages.push(page); | ||||
} | } | ||||
@@ -111,34 +109,34 @@ if __name__ == "__main__": | |||||
#[bench] | #[bench] | ||||
fn bench_baseline_cloning(b: &mut test::Bencher) { | fn bench_baseline_cloning(b: &mut test::Bencher) { | ||||
let pages = create_pages(250, SortBy::Order); | |||||
let pages = create_pages(250); | |||||
b.iter(|| pages.clone()); | b.iter(|| pages.clone()); | ||||
} | } | ||||
#[bench] | #[bench] | ||||
fn bench_sorting_none(b: &mut test::Bencher) { | fn bench_sorting_none(b: &mut test::Bencher) { | ||||
let pages = create_pages(250, SortBy::Order); | |||||
b.iter(|| sort_pages(pages.clone(), SortBy::None)); | |||||
let pages = create_pages(250); | |||||
b.iter(|| sort_pages(pages.clone(), SortBy::Weight)); | |||||
} | } | ||||
#[bench] | #[bench] | ||||
fn bench_sorting_order(b: &mut test::Bencher) { | fn bench_sorting_order(b: &mut test::Bencher) { | ||||
let pages = create_pages(250, SortBy::Order); | |||||
b.iter(|| sort_pages(pages.clone(), SortBy::Order)); | |||||
let pages = create_pages(250); | |||||
b.iter(|| sort_pages(pages.clone(), SortBy::Weight)); | |||||
} | } | ||||
#[bench] | #[bench] | ||||
fn bench_populate_siblings(b: &mut test::Bencher) { | fn bench_populate_siblings(b: &mut test::Bencher) { | ||||
let pages = create_pages(250, SortBy::Order); | |||||
let (sorted_pages, _) = sort_pages(pages, SortBy::Order); | |||||
b.iter(|| populate_siblings(&sorted_pages.clone())); | |||||
let pages = create_pages(250); | |||||
let (sorted_pages, _) = sort_pages(pages, SortBy::Weight); | |||||
b.iter(|| populate_siblings(&sorted_pages.clone(), SortBy::Weight)); | |||||
} | } | ||||
#[bench] | #[bench] | ||||
fn bench_page_render_html(b: &mut test::Bencher) { | fn bench_page_render_html(b: &mut test::Bencher) { | ||||
let pages = create_pages(10, SortBy::Order); | |||||
let (mut sorted_pages, _) = sort_pages(pages, SortBy::Order); | |||||
sorted_pages = populate_siblings(&sorted_pages); | |||||
let pages = create_pages(10); | |||||
let (mut sorted_pages, _) = sort_pages(pages, SortBy::Weight); | |||||
sorted_pages = populate_siblings(&sorted_pages, SortBy::Weight); | |||||
let config = Config::default(); | let config = Config::default(); | ||||
let mut tera = Tera::default(); | let mut tera = Tera::default(); | ||||
@@ -15,8 +15,10 @@ PAGE = """ | |||||
+++ | +++ | ||||
title = "Hello" | title = "Hello" | ||||
date = REPLACE_DATE | date = REPLACE_DATE | ||||
[taxonomies] | |||||
tags = REPLACE_TAG | tags = REPLACE_TAG | ||||
category = "REPLACE_CATEGORY" | |||||
categories = ["REPLACE_CATEGORY"] | |||||
+++ | +++ | ||||
# Modus cognitius profanam ne duae virtutis mundi | # Modus cognitius profanam ne duae virtutis mundi | ||||
@@ -103,10 +105,13 @@ def gen_skeleton(name, is_blog): | |||||
f.write(""" | f.write(""" | ||||
title = "My site" | title = "My site" | ||||
base_url = "https://replace-this-with-your-url.com" | base_url = "https://replace-this-with-your-url.com" | ||||
generate_tags_pages = true | |||||
generate_categories_pages = true | |||||
theme = "sample" | theme = "sample" | ||||
taxonomies = [ | |||||
{name = "tags", rss = true}, | |||||
{name = "categories"} | |||||
] | |||||
[extra.author] | [extra.author] | ||||
name = "Vincent Prouillet" | name = "Vincent Prouillet" | ||||
""") | """) | ||||
@@ -121,8 +126,8 @@ name = "Vincent Prouillet" | |||||
""") | """) | ||||
# Re-use the test templates | # Re-use the test templates | ||||
shutil.copytree("../test_site/templates", os.path.join(name, "templates")) | |||||
shutil.copytree("../test_site/themes", os.path.join(name, "themes")) | |||||
shutil.copytree("../../../test_site/templates", os.path.join(name, "templates")) | |||||
shutil.copytree("../../../test_site/themes", os.path.join(name, "themes")) | |||||
def gen_section(path, num_pages, is_blog): | def gen_section(path, num_pages, is_blog): | ||||
@@ -25,7 +25,7 @@ fn bench_loading_small_blog_with_syntax_highlighting(b: &mut test::Bencher) { | |||||
path.push("benches"); | path.push("benches"); | ||||
path.push("small-blog"); | path.push("small-blog"); | ||||
let mut site = Site::new(&path, "config.toml").unwrap(); | let mut site = Site::new(&path, "config.toml").unwrap(); | ||||
site.config.highlight_code = Some(true); | |||||
site.config.highlight_code = true; | |||||
b.iter(|| site.load().unwrap()); | b.iter(|| site.load().unwrap()); | ||||
} | } | ||||
@@ -46,7 +46,7 @@ fn bench_loading_small_blog_with_syntax_highlighting(b: &mut test::Bencher) { | |||||
// path.push("benches"); | // path.push("benches"); | ||||
// path.push("medium-blog"); | // path.push("medium-blog"); | ||||
// let mut site = Site::new(&path, "config.toml").unwrap(); | // let mut site = Site::new(&path, "config.toml").unwrap(); | ||||
// site.config.highlight_code = Some(true); | |||||
// site.config.highlight_code = true; | |||||
// | // | ||||
// b.iter(|| site.load().unwrap()); | // b.iter(|| site.load().unwrap()); | ||||
//} | //} | ||||
@@ -67,7 +67,7 @@ fn bench_loading_small_blog_with_syntax_highlighting(b: &mut test::Bencher) { | |||||
// path.push("benches"); | // path.push("benches"); | ||||
// path.push("big-blog"); | // path.push("big-blog"); | ||||
// let mut site = Site::new(&path, "config.toml").unwrap(); | // let mut site = Site::new(&path, "config.toml").unwrap(); | ||||
// site.config.highlight_code = Some(true); | |||||
// site.config.highlight_code = true; | |||||
// | // | ||||
// b.iter(|| site.load().unwrap()); | // b.iter(|| site.load().unwrap()); | ||||
//} | //} | ||||
@@ -88,7 +88,7 @@ fn bench_loading_small_blog_with_syntax_highlighting(b: &mut test::Bencher) { | |||||
// path.push("benches"); | // path.push("benches"); | ||||
// path.push("huge-blog"); | // path.push("huge-blog"); | ||||
// let mut site = Site::new(&path, "config.toml").unwrap(); | // let mut site = Site::new(&path, "config.toml").unwrap(); | ||||
// site.config.highlight_code = Some(true); | |||||
// site.config.highlight_code = true; | |||||
// | // | ||||
// b.iter(|| site.load().unwrap()); | // b.iter(|| site.load().unwrap()); | ||||
//} | //} | ||||
@@ -109,7 +109,7 @@ fn bench_loading_small_kb_with_syntax_highlighting(b: &mut test::Bencher) { | |||||
path.push("benches"); | path.push("benches"); | ||||
path.push("small-kb"); | path.push("small-kb"); | ||||
let mut site = Site::new(&path, "config.toml").unwrap(); | let mut site = Site::new(&path, "config.toml").unwrap(); | ||||
site.config.highlight_code = Some(true); | |||||
site.config.highlight_code = true; | |||||
b.iter(|| site.load().unwrap()); | b.iter(|| site.load().unwrap()); | ||||
} | } | ||||
@@ -1,12 +1,14 @@ | |||||
#![feature(test)] | #![feature(test)] | ||||
extern crate test; | extern crate test; | ||||
extern crate site; | extern crate site; | ||||
extern crate pagination; | |||||
extern crate tempfile; | extern crate tempfile; | ||||
use std::env; | use std::env; | ||||
use tempfile::tempdir; | use tempfile::tempdir; | ||||
use site::Site; | use site::Site; | ||||
use pagination::Paginator; | |||||
fn setup_site(name: &str) -> Site { | fn setup_site(name: &str) -> Site { | ||||
@@ -20,8 +22,8 @@ fn setup_site(name: &str) -> Site { | |||||
#[bench] | #[bench] | ||||
fn bench_render_aliases(b: &mut test::Bencher) { | fn bench_render_aliases(b: &mut test::Bencher) { | ||||
let mut site = setup_site("huge-blog"); | |||||
let tmp_dir = TempDir::new("benches").expect("create temp dir"); | |||||
let mut site = setup_site("small-blog"); | |||||
let tmp_dir = tempdir().expect("create temp dir"); | |||||
let public = &tmp_dir.path().join("public"); | let public = &tmp_dir.path().join("public"); | ||||
site.set_output_path(&public); | site.set_output_path(&public); | ||||
b.iter(|| site.render_aliases().unwrap()); | b.iter(|| site.render_aliases().unwrap()); | ||||
@@ -29,8 +31,8 @@ fn bench_render_aliases(b: &mut test::Bencher) { | |||||
#[bench] | #[bench] | ||||
fn bench_render_sitemap(b: &mut test::Bencher) { | fn bench_render_sitemap(b: &mut test::Bencher) { | ||||
let mut site = setup_site("huge-blog"); | |||||
let tmp_dir = TempDir::new("benches").expect("create temp dir"); | |||||
let mut site = setup_site("small-blog"); | |||||
let tmp_dir = tempdir().expect("create temp dir"); | |||||
let public = &tmp_dir.path().join("public"); | let public = &tmp_dir.path().join("public"); | ||||
site.set_output_path(&public); | site.set_output_path(&public); | ||||
b.iter(|| site.render_sitemap().unwrap()); | b.iter(|| site.render_sitemap().unwrap()); | ||||
@@ -38,29 +40,30 @@ fn bench_render_sitemap(b: &mut test::Bencher) { | |||||
#[bench] | #[bench] | ||||
fn bench_render_rss_feed(b: &mut test::Bencher) { | fn bench_render_rss_feed(b: &mut test::Bencher) { | ||||
let mut site = setup_site("huge-blog"); | |||||
let tmp_dir = TempDir::new("benches").expect("create temp dir"); | |||||
let mut site = setup_site("small-blog"); | |||||
let tmp_dir = tempdir().expect("create temp dir"); | |||||
let public = &tmp_dir.path().join("public"); | let public = &tmp_dir.path().join("public"); | ||||
site.set_output_path(&public); | site.set_output_path(&public); | ||||
b.iter(|| site.render_rss_feed().unwrap()); | |||||
b.iter(|| site.render_rss_feed(None, None).unwrap()); | |||||
} | } | ||||
#[bench] | #[bench] | ||||
fn bench_render_categories(b: &mut test::Bencher) { | |||||
let mut site = setup_site("huge-blog"); | |||||
let tmp_dir = TempDir::new("benches").expect("create temp dir"); | |||||
fn bench_render_taxonomies(b: &mut test::Bencher) { | |||||
let mut site = setup_site("small-blog"); | |||||
let tmp_dir = tempdir().expect("create temp dir"); | |||||
let public = &tmp_dir.path().join("public"); | let public = &tmp_dir.path().join("public"); | ||||
site.set_output_path(&public); | site.set_output_path(&public); | ||||
b.iter(|| site.render_categories().unwrap()); | |||||
b.iter(|| site.render_taxonomies().unwrap()); | |||||
} | } | ||||
#[bench] | #[bench] | ||||
fn bench_render_paginated(b: &mut test::Bencher) { | fn bench_render_paginated(b: &mut test::Bencher) { | ||||
let mut site = setup_site("medium-blog"); | |||||
let tmp_dir = TempDir::new("benches").expect("create temp dir"); | |||||
let mut site = setup_site("small-blog"); | |||||
let tmp_dir = tempdir().expect("create temp dir"); | |||||
let public = &tmp_dir.path().join("public"); | let public = &tmp_dir.path().join("public"); | ||||
site.set_output_path(&public); | site.set_output_path(&public); | ||||
let section = site.sections.values().collect::<Vec<_>>()[0]; | let section = site.sections.values().collect::<Vec<_>>()[0]; | ||||
let paginator = Paginator::from_section(§ion.pages, section); | |||||
b.iter(|| site.render_paginated(public, section)); | |||||
b.iter(|| site.render_paginated(public, &paginator)); | |||||
} | } |
@@ -1,3 +1,3 @@ | |||||
{% for tag in tags %} | |||||
{% for tag in terms %} | |||||
{{ tag.name }} {{ tag.slug }} {{ tag.pages | length }} | {{ tag.name }} {{ tag.slug }} {{ tag.pages | length }} | ||||
{% endfor %} | {% endfor %} |
@@ -1,6 +1,6 @@ | |||||
Tag: {{ tag.name }} | |||||
Tag: {{ term.name }} | |||||
{% for page in tag.pages %} | |||||
{% for page in term.pages %} | |||||
<article> | <article> | ||||
<h3 class="post__title"><a href="{{ page.permalink }}">{{ page.title }}</a></h3> | <h3 class="post__title"><a href="{{ page.permalink }}">{{ page.title }}</a></h3> | ||||
</article> | </article> |