Class: Siru::Post

Inherits:
Object
  • Object
show all
Defined in:
lib/siru/post.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ Post



5
6
7
8
# File 'lib/siru/post.rb', line 5

def initialize(file_path)
  @file_path = file_path
  parse_file
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



3
4
5
# File 'lib/siru/post.rb', line 3

def content
  @content
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



3
4
5
# File 'lib/siru/post.rb', line 3

def file_path
  @file_path
end

#front_matterObject (readonly)

Returns the value of attribute front_matter.



3
4
5
# File 'lib/siru/post.rb', line 3

def front_matter
  @front_matter
end

#rendered_contentObject (readonly)

Returns the value of attribute rendered_content.



3
4
5
# File 'lib/siru/post.rb', line 3

def rendered_content
  @rendered_content
end

Instance Method Details

#dateObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/siru/post.rb', line 14

def date
  date_str = @front_matter['date']
  return Date.today unless date_str
  
  if date_str.is_a?(String)
    Date.parse(date_str)
  else
    date_str
  end
end

#draft?Boolean



25
26
27
# File 'lib/siru/post.rb', line 25

def draft?
  @front_matter['draft'] == true
end

#slugObject



29
30
31
# File 'lib/siru/post.rb', line 29

def slug
  @front_matter['slug'] || File.basename(@file_path, '.md')
end

#summaryObject



37
38
39
# File 'lib/siru/post.rb', line 37

def summary
  @front_matter['summary'] || @content.split("\n\n").first&.strip || ''
end

#tagsObject



41
42
43
# File 'lib/siru/post.rb', line 41

def tags
  @front_matter['tags'] || []
end

#titleObject



10
11
12
# File 'lib/siru/post.rb', line 10

def title
  @front_matter['title'] || File.basename(@file_path, '.md').tr('-', ' ').capitalize
end

#urlObject



33
34
35
# File 'lib/siru/post.rb', line 33

def url
  "/posts/#{slug}/"
end