Class: Jekyll::MarkdownOutput::MarkdownPage
- Inherits:
-
Object
- Object
- Jekyll::MarkdownOutput::MarkdownPage
- Defined in:
- lib/jekyll-markdown-output/markdown_page.rb
Overview
Builds the Markdown bytes for a single source document. Not a Jekyll::Page on purpose: we write directly to _site/ in a post_write hook so the converter and layout pipeline cannot touch the output.
Constant Summary collapse
- DEFAULT_FRONTMATTER_KEYS =
%w[title date url summary tags category author].freeze
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
Instance Method Summary collapse
-
#destination ⇒ Object
Absolute path on disk where this file should be written.
-
#initialize(site, doc, options = {}) ⇒ MarkdownPage
constructor
A new instance of MarkdownPage.
-
#relative_destination ⇒ Object
Path relative to the site root, e.g.
- #to_s ⇒ Object
Constructor Details
#initialize(site, doc, options = {}) ⇒ MarkdownPage
Returns a new instance of MarkdownPage.
14 15 16 17 18 |
# File 'lib/jekyll-markdown-output/markdown_page.rb', line 14 def initialize(site, doc, = {}) @site = site @doc = doc @options = end |
Instance Attribute Details
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
12 13 14 |
# File 'lib/jekyll-markdown-output/markdown_page.rb', line 12 def doc @doc end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
12 13 14 |
# File 'lib/jekyll-markdown-output/markdown_page.rb', line 12 def @options end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
12 13 14 |
# File 'lib/jekyll-markdown-output/markdown_page.rb', line 12 def site @site end |
Instance Method Details
#destination ⇒ Object
Absolute path on disk where this file should be written.
21 22 23 |
# File 'lib/jekyll-markdown-output/markdown_page.rb', line 21 def destination File.join(@site.dest, relative_destination) end |
#relative_destination ⇒ Object
Path relative to the site root, e.g. “/foo.md”.
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/jekyll-markdown-output/markdown_page.rb', line 26 def relative_destination ext = @options.fetch("extension", ".md") url = @doc.url if url.end_with?("/") File.join(url, "index#{ext}") else dir = File.dirname(url) base = File.basename(url, ".*") File.join(dir, "#{base}#{ext}") end end |
#to_s ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/jekyll-markdown-output/markdown_page.rb', line 38 def to_s parts = [] fm = build_frontmatter parts << "---\n#{fm}---" unless fm.empty? if @options.fetch("include_title_heading", true) && @doc.data["title"] parts << "# #{@doc.data["title"]}" end parts << rendered_source.to_s.strip "#{parts.join("\n\n")}\n" end |