aboutsummaryrefslogtreecommitdiffhomepage
path: root/services/nuldoc/lib/nuldoc/components/post_page_entry.rb
blob: 4a9ab6c64f43b0123008c3068f4e088df049e560 (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
module Nuldoc
  module Components
    class PostPageEntry < DOM::HTMLBuilder
      def initialize(post:, config:)
        super()
        @post = post
        @config = config
      end

      def build
        published = Revision.date_to_string(GeneratorUtils.published_date(@post))
        updated = Revision.date_to_string(GeneratorUtils.updated_date(@post))
        has_updates = GeneratorUtils.any_updates?(@post)

        article(class: 'post-entry') do
          a(href: @post.href) do
            header(class: 'entry-header') { h2 { text @post.title } }
            section(class: 'entry-content') { p { text @post.description } }
            footer(class: 'entry-footer') do
              time(datetime: published) { text published }
              text ' 投稿'
              if has_updates
                text '、'
                time(datetime: updated) { text updated }
                text ' 更新'
              end
              render(TagList, tags: @post.tags, config: @config) if @post.tags.length.positive?
            end
          end
        end
      end
    end
  end
end