Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d91b238

Browse files
vjeuxzpao
authored andcommitted
Add pagination to blog
- Add pagination - Display full content in /blog - Truncate Recent posts - Add permalink that lists all the blog posts - Add spacing and bullet around recent posts to make it more readable
1 parent db904c2 commit d91b238

File tree

5 files changed

+63
-21
lines changed

5 files changed

+63
-21
lines changed

docs/_config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ markdown: redcarpet
1616
react_version: 0.4.1
1717
description: A JavaScript library for building user interfaces
1818
relative_permalinks: true
19+
paginate: 5
20+
paginate_path: /blog/page:num
1921
nav_docs_sections:
2022
- title: Quick Start
2123
items:

docs/_css/react.scss

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ li {
248248

249249
}
250250

251+
.nav-blog {
252+
li {
253+
margin-bottom: 5px;
254+
}
255+
}
256+
251257
// Home Page specifics
252258

253259
.home-section {
@@ -285,14 +291,14 @@ li {
285291
margin-right: 0;
286292
}
287293

288-
#examples {
289-
h3 {
290-
color: $darkColor;
291-
font-size: 24px;
292-
font-weight: normal;
293-
margin-bottom: 5px;
294-
}
294+
#examples h3, .home-presentation h3 {
295+
color: $darkColor;
296+
font-size: 24px;
297+
font-weight: normal;
298+
margin-bottom: 5px;
299+
}
295300

301+
#examples {
296302
p {
297303
margin: 0 0 25px 0;
298304
max-width: $twoColumnWidth;
@@ -685,3 +691,15 @@ p code {
685691
.post {
686692
margin-bottom: 30px;
687693
}
694+
695+
.pagination {
696+
margin-bottom: 30px;
697+
698+
/* Trick to get the wrapper to expand to fit floating elements */
699+
width: 100%;
700+
overflow: hidden;
701+
702+
.next {
703+
float: right;
704+
}
705+
}

docs/_includes/nav_blog.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
<div class="nav-docs">
1+
<div class="nav-docs nav-blog">
22
<div class="nav-docs-section">
33
<h3>Recent posts</h3>
44
<ul>
5-
{% for post in site.posts %}
6-
<li><a href="/react{{ post.url }}"{% if page.title == post.title %} class="active"{% endif %}>{{ post.title }}</a></li>
7-
{% endfor %}
5+
{% for post in site.posts limit:10 %}
6+
<li><a href="/react{{ post.url }}"{% if page.title == post.title %} class="active"{% endif %}>{{ post.title }}</a></li>
7+
{% endfor %}
8+
<li><a href="/react/blog/all.html">All posts ...</a></li>
89
</ul>
910
</div>
1011
</div>

docs/blog/all.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: Blog
3+
layout: default
4+
sectionid: blog
5+
id: all-posts
6+
---
7+
8+
<section class="content wrap documentationContent nosidebar">
9+
<div class="inner-content">
10+
<h1>All Posts</h1>
11+
{% for page in site.posts %}
12+
<p><strong><a href="/react{{ page.url }}">{{ page.title }}</a></strong> on {{ page.date | date: "%B %e, %Y" }} by {{ page.author }}</p>
13+
{% endfor %}
14+
</div>
15+
</section>

docs/blog/index.html

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,28 @@
77
<section class="content wrap blogContent">
88
{% include nav_blog.html %}
99
<div class="inner-content">
10-
{% for page in site.posts %}
10+
{% for page in paginator.posts %}
1111
<div class="post-list-item">
1212
<h1><a href="/react{{ page.url }}">{{ page.title }}</a></h1>
1313
<p class="meta">{{ page.date | date: "%B %e, %Y" }} by {{ page.author }}</p>
14-
15-
<hr>
16-
14+
<hr />
1715
<div class="post">
18-
{{ page.excerpt }}
19-
{% if page.excerpt != page.content %}
20-
<p>
21-
<a href="/react{{ page.url }}">Continue Reading &rarr;</a>
22-
</p>
23-
{% endif %}
16+
{{ page.content }}
2417
</div>
2518
</div>
2619
{% endfor %}
20+
21+
<div class="pagination">
22+
{% if paginator.previous_page %}
23+
<a href="/react/blog/{{ paginator.previous_page_path }}" class="previous">
24+
&laquo; Previous Page
25+
</a>
26+
{% endif %}
27+
{% if paginator.next_page %}
28+
<a href="/react/blog/{{ paginator.next_page_path }}" class="next">
29+
Next Page &raquo;
30+
</a>
31+
{% endif %}
32+
</div>
2733
</div>
2834
</section>

0 commit comments

Comments
 (0)