aipng / open-graph
用于生成基本Open Graph标签的简单库
1.3.0
2023-03-05 07:13 UTC
Requires
- php: >= 8.1
- aipng/value-objects: ^3.0.0
- myclabs/php-enum: ^1.8
- nette/utils: ^3.0 || ^4.0
Requires (Dev)
- phpstan/phpstan: ^1.10.3
- phpstan/phpstan-phpunit: ^1.3.10
- phpunit/phpunit: ^10.0.14
README
OpenGraph 是一个用于生成基本的Open Graph元标签的额外简单库,灵感来源于Chris Konnertz的Open Graph Builder。
使用示例
基础
use AipNg\OpenGraph\OpenGraph; use AipNg\OpenGraph\MetaTags; use AipNg\OpenGraph\MetaType; use AipNg\ValueObjects\Web\Url; $og = new OpenGraph; $og ->title('title') ->type(MetaType::WEBSITE) ->url(Url::from('https://site.com')) ->image(Url::from('https://site.com/image.jpg'), 100, 200, 'image/jpg') ->description('description') ->siteName('site name'); var_dump($og->hasTag(MetaTags::OG_TITLE)); // true $og->toArray();
文章
use AipNg\OpenGraph\OpenGraph; $og = new OpenGraph; $og->article('title', new \DateTimeImmutable('2020-01-02 12:13:14'), 'section', ['tag-1', 'tag-2']); $og->toArray(); /** [ 'og:title' => 'title', 'og:type' => 'article', 'article:published_time' => '2020-01-02T12:13:14+0100', 'article:section' => 'section', 'article:tag' => [ 'tag-1', 'tag-2', ], ]; */