Class: Zine::Post

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

Overview

A post - content comes from the markdown, and the destination from the date

Instance Attribute Summary

Attributes inherited from Page

#formatted_data

Instance Method Summary collapse

Methods inherited from Page

#init_templates, #parse_markdown, #parse_yaml, #rel_path_from_build_dir, slug, #template_the_html

Constructor Details

#initialize(md_file_name, templates, site_options) ⇒ Post

Returns a new instance of Post.



6
7
8
9
10
11
12
13
14
15
# File 'lib/zine/post.rb', line 6

def initialize(md_file_name, templates, site_options)
  file_parts = File.open(md_file_name, 'r').read.split('---')
  @formatted_data = FormattedData.new(parse_yaml(file_parts[1]),
                                      site_options)
  @raw_text = file_parts[2]
  init_templates(templates)
  option_dir = site_options['directories']
  @build_dir = option_dir['build'] # for tags
  @dest_path = make_path_from_date option_dir['blog']
end

Instance Method Details

#make_path_from_date(build_dir) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/zine/post.rb', line 17

def make_path_from_date(build_dir)
  page_data = @formatted_data.page
  date = DateTime.parse(page_data[:date_rfc3339])
  dest_dir = File.join(build_dir,
                       date.strftime('%Y'),
                       date.strftime('%-m'))
  FileUtils.mkdir_p dest_dir
  slg = Zine::Page.slug(page_data[:title]) + '.html'
  @dest_path = File.join(dest_dir, slg)
end

#processObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/zine/post.rb', line 28

def process
  super
  page_data = @formatted_data.page
  file_path = rel_path_from_build_dir(@dest_path).to_s
  @formatted_data.uri = URI.join(page_data[:site_URL], file_path).to_s
  TagData.new(page_data[:tags],
              file_path,
              page_data[:title],
              page_data[:date_rfc3339],
              page_data[:date_us])
end