Class: Florby::Page
- Inherits:
-
Object
- Object
- Florby::Page
- Defined in:
- lib/florby/page.rb
Instance Attribute Summary collapse
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
Instance Method Summary collapse
- #aliases ⇒ Object
- #content ⇒ Object
- #content=(html) ⇒ Object
- #created ⇒ Object
- #exclude_from_collections? ⇒ Boolean
- #filename ⇒ Object
-
#initialize(file:) ⇒ Page
constructor
A new instance of Page.
- #layout ⇒ Object
- #permalink ⇒ Object
- #title ⇒ Object
- #updated ⇒ Object
Constructor Details
#initialize(file:) ⇒ Page
Returns a new instance of Page.
9 10 11 12 13 14 15 |
# File 'lib/florby/page.rb', line 9 def initialize(file:) @file = file @meta = {} @markdown = File.read(@file) frontmatter, @body = @markdown.split("---\n", 3).last(2) @frontmatter = YAML.unsafe_load(frontmatter) end |
Instance Attribute Details
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
7 8 9 |
# File 'lib/florby/page.rb', line 7 def @meta end |
Instance Method Details
#aliases ⇒ Object
56 57 58 |
# File 'lib/florby/page.rb', line 56 def aliases @frontmatter['aliases'] || [] end |
#content ⇒ Object
60 61 62 |
# File 'lib/florby/page.rb', line 60 def content @content ||= Commonmarker.to_html(@body, options: { extension: { tagfilter: false, autolink: true }, render: { unsafe: true } }) end |
#content=(html) ⇒ Object
64 65 66 |
# File 'lib/florby/page.rb', line 64 def content=(html) @content = html end |
#created ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/florby/page.rb', line 32 def created if @frontmatter['created'].is_a?(String) Date.parse(@frontmatter['created']) else @frontmatter['created'] || File::Stat.new(@file).birthtime.to_date end end |
#exclude_from_collections? ⇒ Boolean
48 49 50 |
# File 'lib/florby/page.rb', line 48 def exclude_from_collections? @frontmatter['exclude_from_collections'] == 'true' end |
#filename ⇒ Object
17 18 19 |
# File 'lib/florby/page.rb', line 17 def filename @filename ||= File.basename(@file) end |
#layout ⇒ Object
52 53 54 |
# File 'lib/florby/page.rb', line 52 def layout @frontmatter['layout'] || 'default' end |
#permalink ⇒ Object
25 26 27 28 29 30 |
# File 'lib/florby/page.rb', line 25 def permalink link = @frontmatter['permalink'] || title link = "/#{link}" unless link =~ /^\// link = "#{link}/" unless link =~ /\/$/ link end |
#title ⇒ Object
21 22 23 |
# File 'lib/florby/page.rb', line 21 def title @frontmatter['title'] ||filename.gsub(/\.md$/, '') end |
#updated ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/florby/page.rb', line 40 def updated if @frontmatter['updated'].is_a?(String) Date.parse(@frontmatter['updated']) else @frontmatter['updated'] || File::Stat.new(@file).mtime.to_date end end |