Module: Indieweb::Authorship
- Defined in:
- lib/indieweb/authorship.rb,
lib/indieweb/authorship/version.rb
Constant Summary collapse
- VERSION =
"0.2.2"
Class Method Summary collapse
-
.hcard_matching_url_and_author_page_url(items, url) ⇒ Object
7.4.
- .identify(url, html = nil) ⇒ Object
Class Method Details
.hcard_matching_url_and_author_page_url(items, url) ⇒ Object
7.4. if the h-entry’s page has 1+ h-card with url == author-page URL,
use first such h-card, exit.
177 178 179 180 181 182 183 184 185 |
# File 'lib/indieweb/authorship.rb', line 177 def self.(items, url) hcard = hcards_from(items).find do |card| card['properties']['url'].include?(url) end hcard_data_for(url, hcard['properties']['name'][0], hcard['properties']['photo'][0]) end |
.identify(url, html = nil) ⇒ Object
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 |
# File 'lib/indieweb/authorship.rb', line 10 def self.identify(url, html = nil) collection = microformats_from(html: unescaped_html_for(html), url: url) # 1. start with a particular h-entry to determine authorship for, and # no author. if no h-entry, then there's no post to find authorship # for, abort. h_entry = hentry_from(collection['items']) return if h_entry.nil? # 3. if the h-entry has an author property, use that if h_entry['properties'].key?('author') = h_entry['properties']['author'] end # 4. otherwise if the h-entry has a parent h-feed with author property # use that - TODO if .nil? = (h_entry, items: collection['items']) end # 5. if an author property was found unless .nil? hcard = .find { |entry| hcard?(entry) } # 5.1. if it has an h-card, use it, exit. if !hcard.nil? return hcard_data_for( URI.join(url, hcard['properties']['url'][0]).to_s, hcard['properties']['name'][0], hcard['properties'].key?('photo') ? URI.join(url, hcard['properties']['photo'][0]).to_s : nil ) # 5.2. otherwise if author property is an http(s) URL, let the # author-page have that URL elsif [0].start_with?('http://', 'https://') return (url: [0], original_page_items: collection['items']) # 5.3. otherwise use the author property as the author name, exit else return hcard_data_for(nil, [0], nil) end end # 6. if there is no author-page and the h-entry's page is a permalink # page, then # 6.1. if the page has a rel-author link, let the author-page's URL # be the href of the rel-author link # 7. if there is an author-page URL return unless collection['rels'].key?('author') (url: collection['rels']['author'][0], original_page_items: collection['items']) end |