Class: Jekyll::WebmentionIO::WebmentionTag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::WebmentionIO::WebmentionTag
show all
- Defined in:
- lib/jekyll/tags/webmention.rb
Instance Method Summary
collapse
Constructor Details
#initialize(tag_name, text, tokens) ⇒ WebmentionTag
Returns a new instance of WebmentionTag.
15
16
17
18
19
20
21
22
23
|
# File 'lib/jekyll/tags/webmention.rb', line 15
def initialize(tag_name, text, tokens)
super
cache_file = WebmentionIO.get_cache_file_path "incoming"
@cached_webmentions = if File.exist? cache_file
WebmentionIO.load_yaml(cache_file)
else
{}
end
end
|
Instance Method Details
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/jekyll/tags/webmention.rb', line 46
def (type, webmentions)
WebmentionIO.log "info", "Looking for #{type}"
keep = {}
if !WebmentionIO.types.include? type
WebmentionIO.log "warn", "#{type} are not extractable"
else
type = ActiveSupport::Inflector.singularize(type)
WebmentionIO.log "info", "Searching #{webmentions.length} webmentions for type==#{type}"
if webmentions.is_a? Hash
webmentions = webmentions.values
end
webmentions.each do |webmention|
keep[webmention["id"]] = webmention if webmention["type"] == type
end
end
keep
end
|
#lookup(context, name) ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/jekyll/tags/webmention.rb', line 25
def lookup(context, name)
lookup = context
name&.split(".")&.each do |value|
lookup = lookup[value]
end
lookup
end
|
#render(context) ⇒ Object
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
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/jekyll/tags/webmention.rb', line 64
def render(context)
args = @text.split(/\s+/).map(&:strip)
uri = args.shift
uri = lookup(context, uri)
types = []
if @cached_webmentions.key? uri
all_webmentions = @cached_webmentions[uri].clone
WebmentionIO.log "info", "#{all_webmentions.length} total webmentions for #{uri}"
if args.length.positive?
WebmentionIO.log "info", "Requesting only #{args.inspect}"
webmentions = {}
args.each do |type|
types.push type
= (type, all_webmentions)
WebmentionIO.log "info", "Merging in #{.length} #{type}"
webmentions = webmentions.merge()
end
else
WebmentionIO.log "info", "Grabbing all webmentions"
webmentions = all_webmentions
end
if webmentions.is_a? Hash
webmentions = webmentions.values
end
webmentions = sort_webmentions(webmentions)
set_data(webmentions, types)
end
render_into_template(context.registers)
end
|
#set_data(data, types) ⇒ Object
42
43
44
|
# File 'lib/jekyll/tags/webmention.rb', line 42
def set_data(data, types)
@data = { "webmentions" => data, "types" => types }
end
|
#template=(template) ⇒ Object