Module: JekyllAeo::Generators::DotMdWriter

Defined in:
lib/jekyll-aeo/generators/dot_md_writer.rb

Constant Summary collapse

YAML_FRONT_MATTER_REGEXP =
/\A(---\s*\n.*?\n?)^(---\s*$\n?)/m
LIQUID_PATTERN =
/\{[{%]/
YAML_NEEDS_QUOTING =
/[:\#"'{}\[\],&*?|<>=!%@`\n\r]/
SCALAR_FIELDS =
%w[title description author lang].freeze

Class Method Summary collapse

Class Method Details

.process(obj, site) ⇒ Object



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
# File 'lib/jekyll-aeo/generators/dot_md_writer.rb', line 11

def self.process(obj, site)
  config = JekyllAeo::Config.from_site(site)
  dotmd_config = config["dotmd"]
  source_path = JekyllAeo::Utils::IncludeLogic.resolve_source_path(obj, site)
  return unless JekyllAeo::Utils::IncludeLogic.include?(obj, site, config)

  dest_path = md_dest_path(obj, site)
  body, dotmd_mode = extract_body(source_path, obj, dotmd_config)
  obj.data["aeo_dotmd_mode"] = dotmd_mode
  return if body.nil? || body.strip.empty?

  if dotmd_config["include_last_modified"] && File.exist?(source_path)
    last_modified = resolve_last_modified(obj, source_path)
  end

  if dotmd_config["dotmd_metadata"]
     = (obj, site, config, last_modified)
    header = build_header(obj, body, config, last_modified: nil)
    result =  + header + body.lstrip
  else
    header = build_header(obj, body, config, last_modified: last_modified)
    result = header + body.lstrip
  end

  result = result.gsub(/\n{3,}/, "\n\n")
  result = "#{result.rstrip}\n"

  FileUtils.mkdir_p(File.dirname(dest_path))
  File.write(dest_path, result)

  root_index = File.basename(dest_path) == "index.md" && File.dirname(dest_path) == site.dest
  File.write(File.join(site.dest, "index.html.md"), result) if root_index
end