diff --git a/README.md b/README.md index 040b2848..09b7d3e9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# ![Cobalt](https://raw.githubusercontent.com/cobalt-org/logos/master/cobald.logo.02.resize.png) +# ![Cobalt](https://raw.githubusercontent.com/cobalt-org/logos/master/cobald.logo.02.resize.png) [![](https://img.shields.io/crates/v/cobalt-bin.svg?maxAge=25920)](https://crates.io/crates/cobalt-bin) -[![](https://travis-ci.org/cobalt-org/cobalt.rs.svg?branch=master)](https://travis-ci.org/cobalt-org/cobalt.rs) [![](https://ci.appveyor.com/api/projects/status/gp2mmvk8dpe8wsmi/branch/master?svg=true)](https://ci.appveyor.com/project/johannhof/cobalt-rs/branch/master) +[![](https://travis-ci.org/cobalt-org/cobalt.rs.svg?branch=master)](https://travis-ci.org/cobalt-org/cobalt.rs) [![](https://ci.appveyor.com/api/projects/status/gp2mmvk8dpe8wsmi/branch/master?svg=true)](https://ci.appveyor.com/project/johannhof/cobalt-rs/branch/master) [![](https://coveralls.io/repos/cobalt-org/cobalt.rs/badge.svg?branch=master&service=github)](https://coveralls.io/github/cobalt-org/cobalt.rs?branch=master) [![](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/cobalt-org/cobalt.rs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) @@ -94,6 +94,8 @@ The ```extends``` attribute specifies which layout will be used. The ```date``` attribute will be used to sort blog posts (from last to first). ```date``` must have the format `%dd %Mon %YYYY %HH:%MM:%SS %zzzz`, so for example `27 May 2016 21:00:30 +0100`. +You can change the order of posts from newest first (default) to oldest first by setting ```post_order: "asc"``` in your .cobalt.yml + #### Drafts Cobalt supports leaving posts in "draft" state. Drafts will not be rendered unless Cobalt is run with the `--drafts` flag. @@ -218,8 +220,8 @@ script: - cobalt build after_success: | - [ $TRAVIS_BRANCH = master ] && - [ $TRAVIS_PULL_REQUEST = false ] && + [ $TRAVIS_BRANCH = master ] && + [ $TRAVIS_PULL_REQUEST = false ] && cobalt import && git config user.name "Cobalt Site Deployer" && git config user.email "name@example.com" && diff --git a/src/cobalt.rs b/src/cobalt.rs index 0781171c..49d49b05 100644 --- a/src/cobalt.rs +++ b/src/cobalt.rs @@ -125,6 +125,10 @@ pub fn build(config: &Config) -> Result<()> { // fall back to the default date posts.sort_by(|a, b| b.date.unwrap_or(default_date).cmp(&a.date.unwrap_or(default_date))); + if &config.post_order == "asc" { + posts.reverse(); + } + // collect all posts attributes to pass them to other posts for rendering let simple_posts_data: Vec = posts.iter() .map(|x| Value::Object(x.attributes.clone())) diff --git a/src/config.rs b/src/config.rs index 9f84be41..b3b96346 100644 --- a/src/config.rs +++ b/src/config.rs @@ -15,6 +15,7 @@ pub struct Config { pub include_drafts: bool, pub posts: String, pub post_path: Option, + pub post_order: String, pub template_extensions: Vec, pub rss: Option, pub name: Option, @@ -34,6 +35,7 @@ impl Default for Config { include_drafts: false, posts: "posts".to_owned(), post_path: None, + post_order: "desc".to_owned(), template_extensions: vec!["md".to_owned(), "liquid".to_owned()], rss: None, name: None, @@ -89,6 +91,10 @@ impl Config { config.posts = posts.to_owned(); }; + if let Some(post_order) = yaml["post_order"].as_str() { + config.post_order = post_order.to_owned(); + }; + if let Some(extensions) = yaml["template_extensions"].as_vec() { config.template_extensions = extensions.iter() .filter_map(|k| k.as_str().map(|k| k.to_owned())) diff --git a/tests/fixtures/post_order/.cobalt.yml b/tests/fixtures/post_order/.cobalt.yml new file mode 100644 index 00000000..200d195d --- /dev/null +++ b/tests/fixtures/post_order/.cobalt.yml @@ -0,0 +1,7 @@ +name: cobalt blog +source: "." +dest: "build" +post_order: "asc" +ignore: + - .git/* + - build/* diff --git a/tests/fixtures/post_order/_layouts/default.liquid b/tests/fixtures/post_order/_layouts/default.liquid new file mode 100644 index 00000000..389d5c84 --- /dev/null +++ b/tests/fixtures/post_order/_layouts/default.liquid @@ -0,0 +1,12 @@ + + + + test + + +

{{ path }}

+ + {{ content }} + + + diff --git a/tests/fixtures/post_order/_layouts/posts.liquid b/tests/fixtures/post_order/_layouts/posts.liquid new file mode 100644 index 00000000..46d21c6d --- /dev/null +++ b/tests/fixtures/post_order/_layouts/posts.liquid @@ -0,0 +1,10 @@ + + + + My blog - {{ title }} + + + {{ content }} + + + diff --git a/tests/fixtures/post_order/index.liquid b/tests/fixtures/post_order/index.liquid new file mode 100644 index 00000000..93de6018 --- /dev/null +++ b/tests/fixtures/post_order/index.liquid @@ -0,0 +1,7 @@ +extends: default.liquid +--- +This is my Index page! + +{% for post in posts %} + {{ post.title }} +{% endfor %} diff --git a/tests/fixtures/post_order/posts/my-first-blogpost.md b/tests/fixtures/post_order/posts/my-first-blogpost.md new file mode 100644 index 00000000..c9ee8d8f --- /dev/null +++ b/tests/fixtures/post_order/posts/my-first-blogpost.md @@ -0,0 +1,10 @@ +extends: posts.liquid + +title: My first Blogpost +date: 01 Jan 2016 21:00:00 +0100 +--- +# {{ title }} + +Hey there this is my first blogpost and this is super awesome. + +My Blog is lorem ipsum like, yes it is.. diff --git a/tests/fixtures/post_order/posts/my-fourth-blogpost.md b/tests/fixtures/post_order/posts/my-fourth-blogpost.md new file mode 100644 index 00000000..3196b84d --- /dev/null +++ b/tests/fixtures/post_order/posts/my-fourth-blogpost.md @@ -0,0 +1,10 @@ +extends: posts.liquid + +title: My fourth Blogpost +date: 29 May 2016 23:00:00 +0100 +--- +# {{ title }} + +Hey there this is my first blogpost and this is super awesome. + +My Blog is lorem ipsum like, yes it is.. diff --git a/tests/fixtures/post_order/posts/my-second-blogpost.md b/tests/fixtures/post_order/posts/my-second-blogpost.md new file mode 100644 index 00000000..7f9080d3 --- /dev/null +++ b/tests/fixtures/post_order/posts/my-second-blogpost.md @@ -0,0 +1,10 @@ +extends: posts.liquid + +title: My second Blogpost +date: 02 Jan 2016 10:00:00 +0100 +--- +# {{ title }} + +Hey there this is my first blogpost and this is super awesome. + +My Blog is lorem ipsum like, yes it is.. diff --git a/tests/fixtures/post_order/posts/my-third-blogpost.md b/tests/fixtures/post_order/posts/my-third-blogpost.md new file mode 100644 index 00000000..726abcdf --- /dev/null +++ b/tests/fixtures/post_order/posts/my-third-blogpost.md @@ -0,0 +1,10 @@ +extends: posts.liquid + +title: My third Blogpost +date: 27 May 2016 23:00:00 +0100 +--- +# {{ title }} + +Hey there this is my first blogpost and this is super awesome. + +My Blog is lorem ipsum like, yes it is.. diff --git a/tests/mod.rs b/tests/mod.rs index c3c10a37..3237c852 100644 --- a/tests/mod.rs +++ b/tests/mod.rs @@ -175,6 +175,11 @@ pub fn sort_posts() { run_test("sort_posts").expect("Build error"); } +#[test] +pub fn post_order() { + run_test("post_order").expect("Build error"); +} + #[test] pub fn previous_next() { run_test("previous_next").expect("Build error"); diff --git a/tests/target/post_order/index.html b/tests/target/post_order/index.html new file mode 100644 index 00000000..c087471f --- /dev/null +++ b/tests/target/post_order/index.html @@ -0,0 +1,23 @@ + + + + test + + +

index.html

+ + This is my Index page! + + + My first Blogpost + + My second Blogpost + + My third Blogpost + + My fourth Blogpost + + + + + diff --git a/tests/target/post_order/posts/my-first-blogpost.html b/tests/target/post_order/posts/my-first-blogpost.html new file mode 100644 index 00000000..163d0665 --- /dev/null +++ b/tests/target/post_order/posts/my-first-blogpost.html @@ -0,0 +1,13 @@ + + + + My blog - My first Blogpost + + +

My first Blogpost

+

Hey there this is my first blogpost and this is super awesome.

+

My Blog is lorem ipsum like, yes it is..

+ + + + diff --git a/tests/target/post_order/posts/my-fourth-blogpost.html b/tests/target/post_order/posts/my-fourth-blogpost.html new file mode 100644 index 00000000..4a1cd3de --- /dev/null +++ b/tests/target/post_order/posts/my-fourth-blogpost.html @@ -0,0 +1,13 @@ + + + + My blog - My fourth Blogpost + + +

My fourth Blogpost

+

Hey there this is my first blogpost and this is super awesome.

+

My Blog is lorem ipsum like, yes it is..

+ + + + diff --git a/tests/target/post_order/posts/my-second-blogpost.html b/tests/target/post_order/posts/my-second-blogpost.html new file mode 100644 index 00000000..dbc5d286 --- /dev/null +++ b/tests/target/post_order/posts/my-second-blogpost.html @@ -0,0 +1,13 @@ + + + + My blog - My second Blogpost + + +

My second Blogpost

+

Hey there this is my first blogpost and this is super awesome.

+

My Blog is lorem ipsum like, yes it is..

+ + + + diff --git a/tests/target/post_order/posts/my-third-blogpost.html b/tests/target/post_order/posts/my-third-blogpost.html new file mode 100644 index 00000000..524fcca8 --- /dev/null +++ b/tests/target/post_order/posts/my-third-blogpost.html @@ -0,0 +1,13 @@ + + + + My blog - My third Blogpost + + +

My third Blogpost

+

Hey there this is my first blogpost and this is super awesome.

+

My Blog is lorem ipsum like, yes it is..

+ + + +