aboutsummaryrefslogtreecommitdiffhomepage
path: root/services/nuldoc/lib/nuldoc/pages/post_list_page.rb
blob: 7c43a41be70b7713879bc18e0c20c9a104a64d30 (plain)
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
42
43
44
45
46
module Nuldoc
  module Pages
    class PostListPage
      def initialize(posts:, config:, current_page:, total_pages:)
        @posts = posts
        @config = config
        @current_page = current_page
        @total_pages = total_pages
      end

      def render
        posts = @posts
        config = @config
        current_page = @current_page
        total_pages = @total_pages
        page_title = '投稿一覧'
        page_info_suffix = " (#{current_page}ページ目)"
        meta_title = "#{page_title}#{page_info_suffix}|#{config.sites.blog.site_name}"
        meta_description = "投稿した記事の一覧#{page_info_suffix}"

        Components::PageLayout.new(
          meta_copyright_year: config.site.copyright_year,
          meta_description: meta_description,
          meta_title: meta_title,
          meta_atom_feed_href: "https://#{config.sites.blog.fqdn}/posts/atom.xml",
          site: 'blog',
          config: config,
          children: DOM::HTMLBuilder.new.build do
            body class: 'list' do
              render Components::BlogGlobalHeader, config: config
              main class: 'main' do
                header(class: 'page-header') { h1 { text "#{page_title}#{page_info_suffix}" } }
                render Components::Pagination, current_page: current_page, total_pages: total_pages,
                                               base_path: '/posts/'
                posts.each { |post| render(Components::PostPageEntry, post: post, config: config) }
                render Components::Pagination, current_page: current_page, total_pages: total_pages,
                                               base_path: '/posts/'
              end
              render Components::GlobalFooter, config: config
            end
          end
        ).build
      end
    end
  end
end