   plug :put_lang, []
   plug :put_author, []
 
-  def index(conn, _params) do
+  def index(conn, params) do
+    page_num = Map.get(params, "page", "0")
     q = from c in Glasnost.Post,
       where: c.author == ^conn.assigns.blog_author,
       order_by: [desc: c.id]
     posts = q
       |> Glasnost.Repo.all()
+      |> paginate_naively(page_num)
     render conn, "posts.html", posts: posts, blog_author: conn.assigns.blog_author
   end
 

  end

  def paginate_naively(xs, page_num) do
    Enum.slice(xs, @posts_per_page*page_num, @posts_per_page)
  end
end

    render conn, "post.html", post: post
  end

  def tag(conn, params = %{"tag" => tag}) do
    page_num = Map.get(params, "page", "0")
    q = from c in Glasnost.Post,
      where: c.author == ^conn.assigns.blog_author,
      order_by: [desc: c.id]
    posts = q
      |> Glasnost.Repo.all()
      |> Enum.filter(& tag in &1.tags)
      |> paginate_naively(page_num)
    render conn, "posts.html", posts: posts
  end

