https://aaronparecki.com/home-automation/ +
diff --git a/lib/XRay/Formats/HTML.php b/lib/XRay/Formats/HTML.php index 430bb94..5846266 100644 --- a/lib/XRay/Formats/HTML.php +++ b/lib/XRay/Formats/HTML.php @@ -60,6 +60,11 @@ class HTML extends Format { $mf2 = \mf2\Parse($html, $url); + $canonical = false; + + if(isset($mf2['rels']['canonical'][0])) + $canonical = $mf2['rels']['canonical'][0]; + // Check for a rel=alternate link to a Microformats JSON representation, and use that instead if(isset($mf2['rel-urls'])) { $alternates = [ @@ -141,6 +146,13 @@ class HTML extends Format { $result['source-format'] = 'mf2+html'; } } + + if($canonical) { + $result['data']['rels'] = [ + 'canonical' => $canonical, + ]; + } + return $result; } diff --git a/tests/ParseTest.php b/tests/ParseTest.php index 2d94a6a..f64c017 100644 --- a/tests/ParseTest.php +++ b/tests/ParseTest.php @@ -1099,4 +1099,16 @@ class ParseTest extends PHPUnit_Framework_TestCase { $this->assertEquals('https://realize.be/', $data['data']['follow-of']); $this->assertEquals('follow', $data['data']['post-type']); } + + public function testRelCanonical() { + $url = 'http://source.example.com/rel-canonical'; + $response = $this->parse(['url' => $url]); + + $body = $response->getContent(); + $this->assertEquals(200, $response->getStatusCode()); + $data = json_decode($body, true); + + $this->assertEquals('https://aaronparecki.com/2019/12/01/10/homeautomation', $data['data']['url']); + $this->assertEquals('https://aaronparecki.com/2019/12/01/10/homeautomation', $data['data']['rels']['canonical']); + } } diff --git a/tests/data/source.example.com/rel-canonical b/tests/data/source.example.com/rel-canonical new file mode 100644 index 0000000..9f7fe5f --- /dev/null +++ b/tests/data/source.example.com/rel-canonical @@ -0,0 +1,881 @@ +HTTP/1.1 200 OK +Server: Apache +Date: Wed, 09 Dec 2015 03:29:14 GMT +Content-Type: text/html; charset=utf-8 +Connection: keep-alive + + + + +
+ + + +