3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'app/controllers/blog/gem/blog_controller.rb', line 3
def index
posts = Blog::Gem::Post
title = [t("blog.index.page_title")]
if params[:q].present?
title << "#{t("blog.search_by")} #{params[:q].humanize}"
posts = posts.search(params[:q])
elsif params[:tag].present?
title << "#{t("blog.tagged_with")} #{params[:tag].humanize}"
posts = posts.tagged_with(params[:tag])
elsif params[:category].present?
title << "#{t("blog.categoryed_with")} #{params[:category].humanize}"
posts = posts.find_by_category(params[:category])
elsif params[:author].present?
@author = Blog::Gem::Author.find_by_url(params[:author])
if @author.present?
title << "#{t("blog.by_author")} #{@author.name}"
posts = @author.posts
end
elsif params[:date].present?
dt = DateTime.parse("3-#{params[:date]}")
if dt.present?
date = "#{I18n.l(dt, format: :month)} #{dt.year}"
title << "#{t("blog.from_month")} #{date}"
posts = posts.by_datetime(dt)
else
post = []
end
end
@page_title = title.join(" ")
respond_to do |format|
format.atom do
@posts = posts.published.all
render layout: false
end
format.json do
@posts = posts.published.limit(params[:limit]||Blog::Gem.per_page).offset(params[:offset]||0)
render json: @posts.map{|x| {id: x.id, title: x.title, teaser: x.teaser, url: x.to_url, tags: x.tags, category: x.category, author: x.author_name, thumbnail: x.image_url, published_at: x.published_at, square: x.image_url(:square)}}
end
format.html do
@current_path = blogs_path
@posts = posts.published.paginate(page: params[:page].try(:gsub, "/", ""), per_page: Blog::Gem.per_page)
end
end
end
|