about summary refs log tree commit diff stats
path: root/app/controllers/blogs_controller.rb
blob: 0d218ae75187f7be81ea0cd9b9b9b4b109ad5184 (plain) (blame)
1
2
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
require 'redcarpet/render_strip'

class BlogsController < ApplicationController

  def summary
    @blogs = Blog.where(published: true).order(published_at: :desc).paginate(page: params[:page], per_page: 10)
    if not params[:page]
      @main_page = true
    end
  end

  def index
    @blogs = Blog.where(published: true).order(published_at: :desc)

    respond_to do |format|
      format.html
      format.atom
    end
  end

  def show
    @blog = Blog.find_by_slug(params[:slug])

    raise ActiveRecord::RecordNotFound unless @blog
    raise ActiveRecord::RecordNotFound unless @blog.published

    body = Redcarpet::Markdown.new(Redcarpet::Render::StripDown).render(@blog.body)

    set_meta_tags(og: {
      title: @blog.title,
      type: "article",
      description: (body.length <= 300 ? body : body[0..299]),
      url: blog_url(@blog, host: "www.fourisland.com"),
      article: {
        published_time: @blog.published_at.iso8601,
        modified_time: @blog.updated_at.iso8601
      }
    })
  end

end