~srushe/indieweb-authorship

c5a58955573374042c26c38d904ecceaa5e1a702 — Stephen Rushe 2 months ago a0118e7 master v0.2.2
Support encoded emails within the h-card.
M CHANGELOG.md => CHANGELOG.md +14 -0
@@ 6,6 6,20 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [0.2.2] - 2021-04-03

### Added

- Support encoded emails within the h-card.

### Changed

- Update microformats gem to a minimum of 4.2.1 (to remove Ruby 2.7 deprecation warning).

### Security

- Update nokogiri from 1.10.10 to 1.11.2

## [0.2.1] - 2020-08-02

### Changed

M Gemfile.lock => Gemfile.lock +4 -4
@@ 1,15 1,15 @@
PATH
  remote: .
  specs:
    indieweb-authorship (0.2.1)
      microformats (~> 4.0, >= 4.1.0)
    indieweb-authorship (0.2.2)
      microformats (~> 4.0, >= 4.2.1)

GEM
  remote: https://rubygems.org/
  specs:
    diff-lcs (1.3)
    json (2.3.1)
    microformats (4.2.0)
    json (2.5.1)
    microformats (4.2.1)
      json (~> 2.2)
      nokogiri (~> 1.10)
    mini_portile2 (2.5.0)

M indieweb-authorship.gemspec => indieweb-authorship.gemspec +1 -1
@@ 28,7 28,7 @@ Gem::Specification.new do |spec|
  spec.executables   = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
  spec.require_paths = ["lib"]

  spec.add_runtime_dependency "microformats", "~> 4.0", ">= 4.1.0"
  spec.add_runtime_dependency "microformats", "~> 4.0", ">= 4.2.1"

  spec.add_development_dependency "bundler", "~> 1.16"
  spec.add_development_dependency "rake", "~> 13.0"

M lib/indieweb/authorship.rb => lib/indieweb/authorship.rb +9 -2
@@ 3,11 3,12 @@
require 'indieweb/authorship/version'
require 'microformats'
require 'net/http'
require 'cgi'

module Indieweb
  module Authorship
    def self.identify(url, html = nil)
      collection = microformats_from(html: html, url: url)
      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


@@ 64,7 65,7 @@ module Indieweb

    def self.microformats_from(html: nil, url:)
      html ||= Net::HTTP.get(URI(url))
      ::Microformats.parse(html, base: url)
      ::Microformats.parse(unescaped_html_for(html), base: url)
    end
    private_class_method :microformats_from



@@ 182,5 183,11 @@ module Indieweb
                     hcard['properties']['name'][0],
                     hcard['properties']['photo'][0])
    end

    def self.unescaped_html_for(html)
      return if html.nil?
      CGI.unescape(html)
    end
    private_class_method :unescaped_html_for
  end
end

M lib/indieweb/authorship/version.rb => lib/indieweb/authorship/version.rb +1 -1
@@ 1,5 1,5 @@
module Indieweb
  module Authorship
    VERSION = "0.2.1"
    VERSION = "0.2.2"
  end
end

A spec/examples/h-entry-author-email-is-escaped => spec/examples/h-entry-author-email-is-escaped +24 -0
@@ 0,0 1,24 @@
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 09 Dec 2015 03:29:14 GMT
Content-Type: text/html; charset=utf-8

<!DOCTYPE html>
<html lang="en">
<head>
  <title>busybee</title>
</head>

<body>
  <article class="entry h-entry">
    <span class="h-card p-author hidden">
      <a class="p-name u-url" rel="author me" href="/">fluffy</a>
      <a class="u-email" href="mailto:fluffy%40beesbuzz%2ebiz">fluffy at beesbuzz dot biz</a>
      <a class="u-photo" href="/static/headshot.jpg"></a>
      <time class="dt-bday" datetime="1978-06-14"></time>
      <span class="p-note">A Seattle-based programmer/musician who makes games, comics, and bad decisions.</span>
      <span class="p-pronouns"><span class="p-pronoun-nominative">she</span>/<span class="p-pronoun-oblique">her</span> or <span class="p-pronoun-nominative">they</span>/<span class="p-pronoun-oblique">them</span></span>
    </span>
  </article>
</body>
</html>
\ No newline at end of file

A spec/h-entry-author-email-is-escaped_spec.rb => spec/h-entry-author-email-is-escaped_spec.rb +24 -0
@@ 0,0 1,24 @@
RSpec.describe Indieweb::Authorship do
  let(:page) { 'h-entry-author-email-is-escaped' }
  let(:url) { "https://beesbuzz.biz/" }
  let(:html) { html_for(page) }
  let(:expected_data) do
    {
      'url' => url,
      'name' => 'fluffy',
      'photo' => 'https://beesbuzz.biz/static/headshot.jpg'
    }
  end

  before do
    allow(Net::HTTP).to receive(:get).with(URI(url)) { html }
  end

  context 'when given just a URL' do
    it { expect(described_class.identify(url)).to eq expected_data }
  end

  context 'when given both a URL and HTML' do
    it { expect(described_class.identify(url, html)).to eq expected_data }
  end
end