Skip to content

Commit

Permalink
Refactor the post class
Browse files Browse the repository at this point in the history
  • Loading branch information
waferbaby committed Jan 27, 2024
1 parent 48c123e commit 34afc75
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions lib/dimples/post.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
# frozen_string_literal: true

require_relative 'document'

require 'date'

module Dimples
class Post < Document
# A page from a site with a date.
class Post < Page
def date
@metadata.fetch(:date, DateTime.now)
@metadata.fetch(:date, File.birthtime(@path))
end

def layout
@metadata.fetch(:layout, 'post')
end

def categories
@metadata.fetch(:categories, [])
end

def slug
File.basename(@path, '.markdown')
@metadata.fetch(:slug, File.basename(@path, '.markdown'))
end

def output_directory
@output_directory ||= File.dirname(@path).gsub(@config[:sources][:posts], @config[:output][:posts]) << "/#{slug}/"
end

def url
@url ||= output_directory.gsub(@config[:output][:root], '')
end

private

def template_class
Tilt::RedcarpetTemplate
end

def template_options
{ smartypants: true }
end
end
end

0 comments on commit 34afc75

Please sign in to comment.