OGPResolverでmeta[name="description"] にフォールバックする🐯 (#91)
This commit is contained in:
parent
735bb00eba
commit
116dd3b798
@ -30,7 +30,7 @@ class OGPResolver implements Resolver, Parser
|
|||||||
$metadata->title = $nodes->item(0)->textContent;
|
$metadata->title = $nodes->item(0)->textContent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$metadata->description = $this->findContent($xpath, '//meta[@*="og:description"]', '//meta[@*="twitter:description"]');
|
$metadata->description = $this->findContent($xpath, '//meta[@*="og:description"]', '//meta[@*="twitter:description"]', '//meta[@name="description"]');
|
||||||
$metadata->image = $this->findContent($xpath, '//meta[@*="og:image"]', '//meta[@*="twitter:image"]');
|
$metadata->image = $this->findContent($xpath, '//meta[@*="og:image"]', '//meta[@*="twitter:image"]');
|
||||||
|
|
||||||
return $metadata;
|
return $metadata;
|
||||||
|
@ -35,4 +35,19 @@ class OGPResolverTest extends TestCase
|
|||||||
$this->assertEmpty($metadata->description);
|
$this->assertEmpty($metadata->description);
|
||||||
$this->assertEmpty($metadata->image);
|
$this->assertEmpty($metadata->image);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testResolveTitleAndDescription()
|
||||||
|
{
|
||||||
|
$resolver = new OGPResolver();
|
||||||
|
|
||||||
|
$html = <<<EOF
|
||||||
|
<title>Welcome to my homepage</title>
|
||||||
|
<meta name="description" content="This is my super hyper ultra homepage!!" />
|
||||||
|
EOF;
|
||||||
|
|
||||||
|
$metadata = $resolver->parse($html);
|
||||||
|
$this->assertEquals('Welcome to my homepage', $metadata->title);
|
||||||
|
$this->assertEquals('This is my super hyper ultra homepage!!', $metadata->description);
|
||||||
|
$this->assertEmpty($metadata->image);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user