Class: MetaInspector::Parsers::HeadLinksParser
- Inherits:
-
Base
- Object
- Base
- MetaInspector::Parsers::HeadLinksParser
show all
- Defined in:
- lib/meta_inspector/parsers/head_links.rb
Constant Summary
collapse
- KNOWN_FEED_TYPES =
%w[
application/rss+xml application/atom+xml application/json
].freeze
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Instance Method Details
#canonicals ⇒ Object
27
28
29
|
# File 'lib/meta_inspector/parsers/head_links.rb', line 27
def canonicals
@canonicals ||= head_links.select { |hl| hl[:rel] == 'canonical' }
end
|
#feed ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/meta_inspector/parsers/head_links.rb', line 44
def feed
warn "DEPRECATION: Use MetaInspector#feeds instead of #feed. The former gives you all feeds and their metadata, the latter will be removed."
@feed ||= begin
first_feed = feeds.find { |l| /\/(rss|atom)\+xml$/i =~ l[:type] } || {}
first_feed[:href]
end
end
|
#feeds ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/meta_inspector/parsers/head_links.rb', line 31
def feeds
@feeds ||=
parsed.search("//link[@rel='alternate']").map do |link|
next if !KNOWN_FEED_TYPES.include?(link["type"]) || link["href"].to_s.strip == ''
{
title: link["title"],
href: URL.absolutify(link["href"], base_url),
type: link["type"]
}
end.compact
end
|
#head_links ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/meta_inspector/parsers/head_links.rb', line 10
def head_links
@head_links ||= parsed.css('head link').map do |tag|
Hash[
tag.attributes.keys.map do |key|
keysym = key.to_sym
val = tag.attributes[key].value
val = URL.absolutify(val, base_url) if keysym == :href
[keysym, val]
end
]
end
end
|
#stylesheets ⇒ Object
23
24
25
|
# File 'lib/meta_inspector/parsers/head_links.rb', line 23
def stylesheets
@stylesheets ||= head_links.select { |hl| hl[:rel] == 'stylesheet' }
end
|