dimples 10.5.1 → 10.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/dimples/config.rb +20 -3
- data/lib/dimples/entry.rb +103 -0
- data/lib/dimples/layout.rb +10 -0
- data/lib/dimples/page.rb +23 -0
- data/lib/dimples/pager.rb +19 -11
- data/lib/dimples/post.rb +43 -0
- data/lib/dimples/site.rb +6 -6
- data/lib/dimples/version.rb +1 -1
- data/lib/dimples.rb +4 -5
- metadata +5 -5
- data/lib/dimples/entries/base.rb +0 -93
- data/lib/dimples/entries/layout.rb +0 -12
- data/lib/dimples/entries/page.rb +0 -29
- data/lib/dimples/entries/post.rb +0 -38
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 46c0d12cf89d7318ad1c0e9717a3389bc3b4033676206caddc8f31081975797a
|
|
4
|
+
data.tar.gz: ed93b72589065aa25a013624ffec85a17a24629b15188bf3f0a83cbac4c52904
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8518ff8cc7c925122dbe8ca28c0775497068a15ed2bc8426cf5006591e988e52c26c35d2c7a31b2229cd3f95825e654b126133122dbeab65b7b056918f99788d
|
|
7
|
+
data.tar.gz: f1a58dc7294faec5b8e47547fccc07fea07225ba500cf509c55fcd84f0f4242757e27ebe2eb8d270de01218f53a14cc3d844ecb9181fccac631ba3d6089c93c4
|
data/lib/dimples/config.rb
CHANGED
|
@@ -3,7 +3,12 @@
|
|
|
3
3
|
module Dimples
|
|
4
4
|
# Configuration settings for a site.
|
|
5
5
|
class Config
|
|
6
|
-
SOURCE_PATHS = {
|
|
6
|
+
SOURCE_PATHS = {
|
|
7
|
+
pages: 'pages',
|
|
8
|
+
posts: 'posts',
|
|
9
|
+
layouts: 'layouts',
|
|
10
|
+
static: 'static'
|
|
11
|
+
}.freeze
|
|
7
12
|
|
|
8
13
|
attr_accessor :source_paths, :build_paths, :site, :pagination, :generation
|
|
9
14
|
|
|
@@ -14,15 +19,27 @@ module Dimples
|
|
|
14
19
|
pathnames: { posts: 'posts', categories: 'categories' },
|
|
15
20
|
site: { name: nil, domain: nil },
|
|
16
21
|
pagination: { page_prefix: 'page_', per_page: 5 },
|
|
17
|
-
generation: {
|
|
22
|
+
generation: { main_feed: true, category_feeds: false }
|
|
18
23
|
}
|
|
19
24
|
end
|
|
20
25
|
|
|
21
26
|
def initialize(options = {})
|
|
22
|
-
options = Config.defaults.
|
|
27
|
+
options = Config.defaults.to_h do |key, value|
|
|
28
|
+
unless options[key].nil?
|
|
29
|
+
value = case options[key]
|
|
30
|
+
when Hash
|
|
31
|
+
value.merge!(options[key])
|
|
32
|
+
else
|
|
33
|
+
options[key]
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
[key, value]
|
|
38
|
+
end
|
|
23
39
|
|
|
24
40
|
@source_paths = expand_paths(File.expand_path(options[:source]), SOURCE_PATHS.dup)
|
|
25
41
|
@build_paths = expand_paths(File.expand_path(options[:build]), options[:pathnames])
|
|
42
|
+
|
|
26
43
|
@site = options[:site]
|
|
27
44
|
@pagination = options[:pagination]
|
|
28
45
|
@generation = options[:generation]
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'forwardable'
|
|
4
|
+
require 'pathname'
|
|
5
|
+
|
|
6
|
+
module Dimples
|
|
7
|
+
# A class representing a dynamic source entry
|
|
8
|
+
class Entry
|
|
9
|
+
include Forwardable
|
|
10
|
+
|
|
11
|
+
FRONT_MATTER_PATTERN = /^(-{3}\n.*?\n?)^(-{3}*$\n?)/m
|
|
12
|
+
|
|
13
|
+
attr_accessor :path, :contents, :rendered_contents
|
|
14
|
+
attr_reader :metadata
|
|
15
|
+
|
|
16
|
+
def initialize(site:, source:)
|
|
17
|
+
@site = site
|
|
18
|
+
|
|
19
|
+
contents = case source
|
|
20
|
+
when Pathname
|
|
21
|
+
@path = File.expand_path(source)
|
|
22
|
+
File.read(@path)
|
|
23
|
+
when String
|
|
24
|
+
source
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
parse_metadata(contents)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def parse_metadata(contents)
|
|
31
|
+
metadata = default_metadata
|
|
32
|
+
|
|
33
|
+
matches = contents.match(FRONT_MATTER_PATTERN)
|
|
34
|
+
if matches
|
|
35
|
+
metadata.merge!(YAML.safe_load(matches[1], symbolize_names: true, permitted_classes: [Date]))
|
|
36
|
+
@contents = matches.post_match.strip
|
|
37
|
+
else
|
|
38
|
+
@contents = contents
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
@metadata = Metadata.new(metadata)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def generate(output_path: nil, context: {})
|
|
45
|
+
output_path = File.join(output_directory, @metadata[:filename]) if output_path.nil?
|
|
46
|
+
write(output_path: output_path, body: render(context: context))
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def write(output_path:, body:)
|
|
50
|
+
parent_directory = File.dirname(output_path)
|
|
51
|
+
|
|
52
|
+
FileUtils.mkdir_p(parent_directory) unless File.directory?(parent_directory)
|
|
53
|
+
File.write(output_path, body)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def url
|
|
57
|
+
@url ||= output_directory.gsub(@site.config.build_paths[:root], '').tap do |url|
|
|
58
|
+
url.concat(@metadata[:filename]) unless @metadata[:filename] == 'index.html'
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def render(context: {}, body: nil)
|
|
63
|
+
context[:site] ||= @site.metadata
|
|
64
|
+
context[:page] ||= @metadata
|
|
65
|
+
|
|
66
|
+
@rendered_contents = template.render(Metadata.new(context)) { body }
|
|
67
|
+
|
|
68
|
+
layout = @site.layouts[@metadata.layout.to_sym] if @metadata.layout
|
|
69
|
+
return @rendered_contents if layout.nil?
|
|
70
|
+
|
|
71
|
+
layout.render(context: context, body: @rendered_contents)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def output_directory
|
|
75
|
+
@output_directory ||= @site.config.build_paths[:root]
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def template
|
|
79
|
+
@template ||= Tilt::ERBTemplate.new { @contents }
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def to_h
|
|
83
|
+
@metadata.to_h.merge({ contents: contents })
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def method_missing(method_name, *_args)
|
|
87
|
+
@metadata.send(method_name)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def respond_to_missing?(_method_name, _include_private = false)
|
|
91
|
+
true
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
private
|
|
95
|
+
|
|
96
|
+
def default_metadata
|
|
97
|
+
{
|
|
98
|
+
layout: nil,
|
|
99
|
+
filename: 'index.html'
|
|
100
|
+
}
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
data/lib/dimples/page.rb
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Dimples
|
|
4
|
+
# A single page on a site.
|
|
5
|
+
class Page < Entry
|
|
6
|
+
def initialize(site:, path:)
|
|
7
|
+
super(site: site, source: Pathname.new(path))
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def output_directory
|
|
11
|
+
@output_directory ||= File.dirname(@path).gsub(
|
|
12
|
+
@site.config.source_paths[:pages],
|
|
13
|
+
@site.config.build_paths[:root]
|
|
14
|
+
).concat('/')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def default_metadata
|
|
20
|
+
super.merge!(layout: 'page')
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
data/lib/dimples/pager.rb
CHANGED
|
@@ -7,8 +7,8 @@ module Dimples
|
|
|
7
7
|
|
|
8
8
|
attr_reader :current_page, :previous_page, :next_page, :page_count
|
|
9
9
|
|
|
10
|
-
def self.paginate(site:, url:, posts:, context: {})
|
|
11
|
-
new(site: site, url: url, posts: posts).paginate(context: context)
|
|
10
|
+
def self.paginate(site:, url:, posts:, context: {}, &block)
|
|
11
|
+
new(site: site, url: url, posts: posts).paginate(context: context, &block)
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def initialize(site:, url:, posts:)
|
|
@@ -27,10 +27,16 @@ module Dimples
|
|
|
27
27
|
(1..@page_count).each do |index|
|
|
28
28
|
step_to(index)
|
|
29
29
|
|
|
30
|
-
@site.
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
output_directory = File.join(@site.config.build_paths[:root], current_page_url)
|
|
31
|
+
|
|
32
|
+
context.merge!(metadata, url: current_page_url)
|
|
33
|
+
|
|
34
|
+
@site.layouts[:posts]&.generate(
|
|
35
|
+
output_path: File.join(output_directory, 'index.html'),
|
|
36
|
+
context: context
|
|
33
37
|
)
|
|
38
|
+
|
|
39
|
+
yield(output_directory, context) if block_given?
|
|
34
40
|
end
|
|
35
41
|
end
|
|
36
42
|
|
|
@@ -89,12 +95,14 @@ module Dimples
|
|
|
89
95
|
def metadata
|
|
90
96
|
{
|
|
91
97
|
posts: posts_at(current_page),
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
+
pagination: {
|
|
99
|
+
current_page: @current_page,
|
|
100
|
+
page_count: @page_count,
|
|
101
|
+
post_count: @posts.count,
|
|
102
|
+
previous_page: @previous_page,
|
|
103
|
+
next_page: @next_page,
|
|
104
|
+
urls: urls
|
|
105
|
+
}
|
|
98
106
|
}
|
|
99
107
|
end
|
|
100
108
|
end
|
data/lib/dimples/post.rb
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Dimples
|
|
4
|
+
# A page from a site with a date.
|
|
5
|
+
class Post < Entry
|
|
6
|
+
def initialize(site:, path:)
|
|
7
|
+
super(site: site, source: Pathname.new(path))
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def output_directory
|
|
11
|
+
@output_directory ||= File.dirname(@path).gsub(
|
|
12
|
+
@site.config.source_paths[:posts],
|
|
13
|
+
@site.config.build_paths[:posts]
|
|
14
|
+
).concat("/#{slug}/")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def slug
|
|
18
|
+
File.basename(@path, File.extname(@path))&.downcase
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def template
|
|
22
|
+
@template ||= Tilt::RedcarpetTemplate.new { @contents }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def to_h
|
|
26
|
+
super.reject { |k, _| %i[filename layout].include?(k) }.tap do |output|
|
|
27
|
+
output[:date] = output[:date].iso8601 unless output[:date].nil?
|
|
28
|
+
output[:url] ||= url
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def default_metadata
|
|
35
|
+
super.tap do |defaults|
|
|
36
|
+
defaults[:layout] = 'post'
|
|
37
|
+
defaults[:slug] = slug
|
|
38
|
+
defaults[:date] = File.birthtime(@path)
|
|
39
|
+
defaults[:categories] = []
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
data/lib/dimples/site.rb
CHANGED
|
@@ -30,19 +30,19 @@ module Dimples
|
|
|
30
30
|
|
|
31
31
|
def posts
|
|
32
32
|
@posts ||= Dir.glob(File.join(@config.source_paths[:posts], '**', '*.markdown')).map do |path|
|
|
33
|
-
Dimples::
|
|
33
|
+
Dimples::Post.new(site: self, path: path)
|
|
34
34
|
end.sort_by! { |post| post.metadata[:date] }.reverse!
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
def pages
|
|
38
38
|
@pages ||= Dir.glob(File.join(@config.source_paths[:pages], '**', '*.erb')).map do |path|
|
|
39
|
-
Dimples::
|
|
39
|
+
Dimples::Page.new(site: self, path: path)
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
def layouts
|
|
44
44
|
@layouts ||= Dir.glob(File.join(@config.source_paths[:layouts], '**', '*.erb')).to_h do |path|
|
|
45
|
-
[File.basename(path, '.erb').to_sym, Dimples::
|
|
45
|
+
[File.basename(path, '.erb').to_sym, Dimples::Layout.new(site: self, path: path)]
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
|
|
@@ -76,7 +76,7 @@ module Dimples
|
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
def generate_post(post)
|
|
79
|
-
post.
|
|
79
|
+
post.generate
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
def generate_pages
|
|
@@ -84,7 +84,7 @@ module Dimples
|
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
def generate_page(page)
|
|
87
|
-
page.
|
|
87
|
+
page.generate
|
|
88
88
|
end
|
|
89
89
|
|
|
90
90
|
def generate_categories
|
|
@@ -107,7 +107,7 @@ module Dimples
|
|
|
107
107
|
def generate_feed(output_path:, posts:)
|
|
108
108
|
return if layouts[:feed].nil?
|
|
109
109
|
|
|
110
|
-
layouts[:feed].
|
|
110
|
+
layouts[:feed].generate(
|
|
111
111
|
output_path: File.join(output_path, 'feed.atom'),
|
|
112
112
|
context: { posts: posts.slice(0, 10) }
|
|
113
113
|
)
|
data/lib/dimples/version.rb
CHANGED
data/lib/dimples.rb
CHANGED
|
@@ -6,8 +6,7 @@ require 'dimples/config'
|
|
|
6
6
|
require 'dimples/metadata'
|
|
7
7
|
require 'dimples/pager'
|
|
8
8
|
require 'dimples/site'
|
|
9
|
-
|
|
10
|
-
require 'dimples/
|
|
11
|
-
require 'dimples/
|
|
12
|
-
require 'dimples/
|
|
13
|
-
require 'dimples/entries/layout'
|
|
9
|
+
require 'dimples/entry'
|
|
10
|
+
require 'dimples/page'
|
|
11
|
+
require 'dimples/post'
|
|
12
|
+
require 'dimples/layout'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dimples
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 10.
|
|
4
|
+
version: 10.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel Bogan
|
|
@@ -62,12 +62,12 @@ files:
|
|
|
62
62
|
- bin/dimples
|
|
63
63
|
- lib/dimples.rb
|
|
64
64
|
- lib/dimples/config.rb
|
|
65
|
-
- lib/dimples/
|
|
66
|
-
- lib/dimples/
|
|
67
|
-
- lib/dimples/entries/page.rb
|
|
68
|
-
- lib/dimples/entries/post.rb
|
|
65
|
+
- lib/dimples/entry.rb
|
|
66
|
+
- lib/dimples/layout.rb
|
|
69
67
|
- lib/dimples/metadata.rb
|
|
68
|
+
- lib/dimples/page.rb
|
|
70
69
|
- lib/dimples/pager.rb
|
|
70
|
+
- lib/dimples/post.rb
|
|
71
71
|
- lib/dimples/site.rb
|
|
72
72
|
- lib/dimples/version.rb
|
|
73
73
|
homepage: http://github.com/waferbaby/dimples
|
data/lib/dimples/entries/base.rb
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'forwardable'
|
|
4
|
-
require 'pathname'
|
|
5
|
-
|
|
6
|
-
module Dimples
|
|
7
|
-
module Entries
|
|
8
|
-
# A class representing a dynamic source entry
|
|
9
|
-
class Base
|
|
10
|
-
include Forwardable
|
|
11
|
-
|
|
12
|
-
FRONT_MATTER_PATTERN = /^(-{3}\n.*?\n?)^(-{3}*$\n?)/m
|
|
13
|
-
|
|
14
|
-
attr_accessor :path, :contents, :rendered_contents
|
|
15
|
-
attr_reader :metadata
|
|
16
|
-
|
|
17
|
-
def initialize(site:, source:)
|
|
18
|
-
@site = site
|
|
19
|
-
|
|
20
|
-
contents = case source
|
|
21
|
-
when Pathname
|
|
22
|
-
@path = File.expand_path(source)
|
|
23
|
-
File.read(@path)
|
|
24
|
-
when String
|
|
25
|
-
source
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
parse_metadata(contents)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def parse_metadata(contents)
|
|
32
|
-
metadata = default_metadata
|
|
33
|
-
|
|
34
|
-
matches = contents.match(FRONT_MATTER_PATTERN)
|
|
35
|
-
if matches
|
|
36
|
-
metadata.merge!(YAML.safe_load(matches[1], symbolize_names: true, permitted_classes: [Date]))
|
|
37
|
-
@contents = matches.post_match.strip
|
|
38
|
-
else
|
|
39
|
-
@contents = contents
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
@metadata = Metadata.new(metadata)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def write(output_path: nil, context: {})
|
|
46
|
-
output_path = File.join(output_directory, @metadata[:filename]) if output_path.nil?
|
|
47
|
-
|
|
48
|
-
parent_directory = File.dirname(output_path)
|
|
49
|
-
output = render(context: context)
|
|
50
|
-
|
|
51
|
-
FileUtils.mkdir_p(parent_directory) unless File.directory?(parent_directory)
|
|
52
|
-
File.write(output_path, output)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def render(context: {}, body: nil)
|
|
56
|
-
context[:site] ||= @site.metadata
|
|
57
|
-
context[:page] ||= @metadata
|
|
58
|
-
|
|
59
|
-
@rendered_contents = template.render(Metadata.new(context)) { body }
|
|
60
|
-
|
|
61
|
-
layout = @site.layouts[@metadata.layout.to_sym] if @metadata.layout
|
|
62
|
-
return @rendered_contents if layout.nil?
|
|
63
|
-
|
|
64
|
-
layout.render(context: context, body: @rendered_contents)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def output_directory
|
|
68
|
-
@output_directory ||= @site.config.build_paths[:root]
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def template
|
|
72
|
-
@template ||= Tilt::ERBTemplate.new { @contents }
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def method_missing(method_name, *_args)
|
|
76
|
-
@metadata.send(method_name)
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def respond_to_missing?(method_name, include_private = false)
|
|
80
|
-
true
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
private
|
|
84
|
-
|
|
85
|
-
def default_metadata
|
|
86
|
-
{
|
|
87
|
-
layout: nil,
|
|
88
|
-
filename: 'index.html'
|
|
89
|
-
}
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
end
|
data/lib/dimples/entries/page.rb
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Dimples
|
|
4
|
-
module Entries
|
|
5
|
-
# A single page on a site.
|
|
6
|
-
class Page < Base
|
|
7
|
-
def initialize(site:, path:)
|
|
8
|
-
super(site: site, source: Pathname.new(path))
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def output_directory
|
|
12
|
-
@output_directory ||= File.dirname(@path).gsub(
|
|
13
|
-
@site.config.source_paths[:pages],
|
|
14
|
-
@site.config.build_paths[:root]
|
|
15
|
-
).concat('/')
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def url
|
|
19
|
-
output_directory.tap { |url| url.concat(filename) unless filename == 'index.html' }
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
private
|
|
23
|
-
|
|
24
|
-
def default_metadata
|
|
25
|
-
super.merge!(layout: 'page')
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
data/lib/dimples/entries/post.rb
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Dimples
|
|
4
|
-
module Entries
|
|
5
|
-
# A page from a site with a date.
|
|
6
|
-
class Post < Base
|
|
7
|
-
def initialize(site:, path:)
|
|
8
|
-
super(site: site, source: Pathname.new(path))
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def output_directory
|
|
12
|
-
@output_directory ||= File.dirname(@path).gsub(
|
|
13
|
-
@site.config.source_paths[:posts],
|
|
14
|
-
@site.config.build_paths[:posts]
|
|
15
|
-
).concat("/#{slug}/")
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def slug
|
|
19
|
-
File.basename(@path, '.markdown')
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def template
|
|
23
|
-
@template ||= Tilt::RedcarpetTemplate.new { @contents }
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
private
|
|
27
|
-
|
|
28
|
-
def default_metadata
|
|
29
|
-
super.tap do |defaults|
|
|
30
|
-
defaults[:layout] = 'post'
|
|
31
|
-
defaults[:slug] = slug
|
|
32
|
-
defaults[:date] = File.birthtime(@path)
|
|
33
|
-
defaults[:categories] = []
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|