Skip to content

Commit

Permalink
Merge branch 'master' into sort-order
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed May 11, 2017
2 parents 8daadae + dbcaf7e commit 5c06950
Show file tree
Hide file tree
Showing 12 changed files with 160 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/cobalt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,19 @@ pub fn build(config: &Config) -> Result<()> {
.collect();

trace!("Generating posts");
for mut post in &mut posts {
for (i, mut post) in &mut posts.iter_mut().enumerate() {
trace!("Generating {}", post.path);

// posts are in reverse date order, so previous post is the next in the list (+1)
if let Some(previous) = simple_posts_data.get(i + 1) {
post.attributes.insert("previous".to_owned(), previous.clone());
}
if i >= 1 {
if let Some(next) = simple_posts_data.get(i - 1) {
post.attributes.insert("next".to_owned(), next.clone());
}
}

let mut context = post.get_render_context(&simple_posts_data);

try!(post.render_excerpt(&mut context, source, &config.excerpt_separator));
Expand Down
12 changes: 12 additions & 0 deletions tests/fixtures/previous_next/_layouts/default.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<h1>{{ path }}</h1>

{{ content }}
</body>
</html>

10 changes: 10 additions & 0 deletions tests/fixtures/previous_next/_layouts/posts.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>My blog - {{ title }}</title>
</head>
<body>
{{ content }}
</body>
</html>

7 changes: 7 additions & 0 deletions tests/fixtures/previous_next/index.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extends: default.liquid
---
This is my Index page!

{% for post in posts %}
<a href="{{post.path}}">{{ post.title }}</a>
{% endfor %}
17 changes: 17 additions & 0 deletions tests/fixtures/previous_next/posts/2014-08-24-my-first-blogpost.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
extends: posts.liquid

title: My first Blogpost
date: 24/08/2014 at 15:36
---
# {{ title }}

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

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

{% if previous %}
<a class="prev" href="/{{previous.path}}">&laquo; {{previous.title}}</a>
{% endif %}
{% if next %}
<a class="next" href="/{{next.path}}">{{next.title}} &raquo;</a>
{% endif %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
extends: posts.liquid

title: My second Blogpost
date: 25/08/2014 at 15:36
---
# {{ title }}

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

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

{% if previous %}
<a class="prev" href="/{{previous.path}}">&laquo; {{previous.title}}</a>
{% endif %}
{% if next %}
<a class="next" href="/{{next.path}}">{{next.title}} &raquo;</a>
{% endif %}
17 changes: 17 additions & 0 deletions tests/fixtures/previous_next/posts/2014-08-26-my-third-blogpost.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
extends: posts.liquid

title: My third Blogpost
date: 26/08/2014 at 15:36
---
# {{ title }}

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

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

{% if previous %}
<a class="prev" href="/{{previous.path}}">&laquo; {{previous.title}}</a>
{% endif %}
{% if next %}
<a class="next" href="/{{next.path}}">{{next.title}} &raquo;</a>
{% endif %}
5 changes: 5 additions & 0 deletions tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ pub fn post_order() {
run_test("post_order").expect("Build error");
}

#[test]
pub fn previous_next() {
run_test("previous_next").expect("Build error");
}

#[test]
pub fn rss() {
run_test("rss").expect("Build error");
Expand Down
21 changes: 21 additions & 0 deletions tests/target/previous_next/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<h1>index.html</h1>

This is my Index page!


<a href="posts/2014-08-24-my-first-blogpost.html">My first Blogpost</a>

<a href="posts/2014-08-25-my-second-blogpost.html">My second Blogpost</a>

<a href="posts/2014-08-26-my-third-blogpost.html">My third Blogpost</a>


</body>
</html>

14 changes: 14 additions & 0 deletions tests/target/previous_next/posts/2014-08-24-my-first-blogpost.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>My blog - My first Blogpost</title>
</head>
<body>
<h1>My first Blogpost</h1>
<p>Hey there this is my first blogpost and this is super awesome.</p>
<p>My Blog is lorem ipsum like, yes it is..</p>
<p><a class="prev" href="/posts/2014-08-25-my-second-blogpost.html">« My second Blogpost</a></p>

</body>
</html>

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>My blog - My second Blogpost</title>
</head>
<body>
<h1>My second Blogpost</h1>
<p>Hey there this is my second blogpost and this is super awesome.</p>
<p>My Blog is lorem ipsum like, yes it is..</p>
<p><a class="prev" href="/posts/2014-08-26-my-third-blogpost.html">« My third Blogpost</a></p>
<p><a class="next" href="/posts/2014-08-24-my-first-blogpost.html">My first Blogpost »</a></p>

</body>
</html>

14 changes: 14 additions & 0 deletions tests/target/previous_next/posts/2014-08-26-my-third-blogpost.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>My blog - My third Blogpost</title>
</head>
<body>
<h1>My third Blogpost</h1>
<p>Hey there this is my third blogpost and this is super awesome.</p>
<p>My Blog is lorem ipsum like, yes it is..</p>
<p><a class="next" href="/posts/2014-08-25-my-second-blogpost.html">My second Blogpost »</a></p>

</body>
</html>

0 comments on commit 5c06950

Please sign in to comment.