/
url_drop.rb
89 lines (69 loc) · 1.63 KB
/
url_drop.rb
1
2
3
4
5
6
7
8
9
10
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# encoding: UTF-8
# frozen_string_literal: true
module Jekyll
module Drops
class UrlDrop < Drop
extend Forwardable
mutable false
def_delegator :@obj, :cleaned_relative_path, :path
def_delegator :@obj, :output_ext, :output_ext
def collection
@obj.collection.label
end
def name
Utils.slugify(@obj.basename_without_ext)
end
def title
Utils.slugify(@obj.data["slug"], :mode => "pretty", :cased => true) ||
Utils.slugify(@obj.basename_without_ext, :mode => "pretty", :cased => true)
end
def slug
Utils.slugify(@obj.data["slug"]) || Utils.slugify(@obj.basename_without_ext)
end
def categories
category_set = Set.new
Array(@obj.data["categories"]).each do |category|
category_set << category.to_s.downcase
end
category_set.to_a.join("/")
end
def year
@obj.date.strftime("%Y")
end
def month
@obj.date.strftime("%m")
end
def day
@obj.date.strftime("%d")
end
def hour
@obj.date.strftime("%H")
end
def minute
@obj.date.strftime("%M")
end
def second
@obj.date.strftime("%S")
end
def i_day
@obj.date.strftime("%-d")
end
def i_month
@obj.date.strftime("%-m")
end
def short_month
@obj.date.strftime("%b")
end
def short_year
@obj.date.strftime("%y")
end
def y_day
@obj.date.strftime("%j")
end
private
def fallback_data
{}
end
end
end
end