blog nav, prev and next, some tweaking

This commit is contained in:
Torsten Ruger 2018-04-11 19:34:35 +03:00
parent 90fc084fca
commit 365d07e606
6 changed files with 55 additions and 44 deletions

View File

@ -1,21 +0,0 @@
\---
layout: site
\---
.row
%div
%h1.center
{{page.title}}
%p.center
%span Written by {{page.author}} on {{page.date | date_to_string}}.
%div
{{content}}
.row
%h2.center Older
%div
%ul.nav
{% for post in site.posts %}
%li
%a{:href => "{{ post.url }}"}
{{ post.title }}
%small {{ post.date | date: "%d.%m.%y" }}
{% endfor %}

View File

@ -43,7 +43,19 @@ ul.nav
width: 78%
.menu
width: 20%
.blog
.blog_nav
.next , .prev
width: 20%
.next
float: right
.prev
float: left
.blog_post
h1
span
font-size: 18px
.blog_index
h1
font-size: 20px
h2

View File

@ -1,10 +1,9 @@
module ApplicationHelper
def post_link(index)
post = Post.posts.values[index]
def post_link(post)
return "" unless post
link = post.date.to_s + " "
link += link_to( post.title , blog_post_url(post.slug))
link.html_safe
link_to(blog_post_url(post.slug)) do
"#{post.title.capitalize} <span>(#{post.date})</span>".html_safe
end.html_safe
end
def ext_link(name = nil, options = nil, html_options = nil, &block)
@ -22,4 +21,19 @@ module ApplicationHelper
def title(title)
@title = title
end
def prev_post(post)
index = Post.posts.keys.index(post.slug)
nav_post(index + 1 , "prev")
end
def next_post(post)
index = Post.posts.keys.index(post.slug)
nav_post(index - 1 , "next")
end
def nav_post(index, dir)
return "" unless index >= 0
post = Post.posts.values[index]
return "" unless post
link_to("#{dir} <span>(#{post.date})</span>".html_safe , blog_post_url(post.slug) , alt: post.title.capitalize)
end
end

View File

@ -1,7 +1,7 @@
.blog.blog_index
.blog_index
- @posts.each do |slug , post|
%h2
= link_to post.title , blog_post_url(post.slug)
= link_to post.title.capitalize , blog_post_url(post.slug)
%span
(
=post.date

View File

@ -1,16 +1,22 @@
.social_box
.social
.social__item
%span.fa.icon-facebook{"data-count" => "", "data-social" => "fb"}
.social__item
%span.fa.icon-twitter{"data-count" => "", "data-social" => "tw"}
.social__item
%span.fa.icon-linkedin{"data-count" => "", "data-social" => "ln"}
.social__item
%span.fa.icon-gplus{"data-count" => "", "data-social" => "gp"}
.row.blog_nav
.prev=raw(prev_post(@post))
.next=raw(next_post(@post))
.blog
.blog_post
.center_col
%h1= @post.title
%h1
= @post.title.capitalize
%span
(
=@post.date
)
.center_col
= render( "posts/#{@post.template_name}" )
.row
%ul.nav
- Post.posts.each do |slug, post|
%li
=link_to blog_post_path(slug) do
=post.title.capitalize
%small= post.date

View File

@ -82,6 +82,6 @@
%p
Last but not least, i try to get recent developments down on paper when they are
still fresh.
%p=post_link(0)
%p=post_link(1)
%p=post_link(2)
%p=post_link(Post.posts.values[0])
%p=post_link(Post.posts.values[1])
%p=post_link(Post.posts.values[2])