gabrieliuga / laravel-seo-meta-box
为您的网站添加SEO功能
v1.0.4
2021-06-30 15:10 UTC
Requires
- php: ^7.4|^8.0
- laravel/framework: >=6.2
Requires (Dev)
- orchestra/testbench: ^5.0
- phpunit/phpunit: ^8.0
README
添加创建自定义标题/描述的功能,支持按页面设置。包括Twitter账号和Open Graph数据,以便于社交分享。
安装
您可以通过composer安装此包
composer require gabrieliuga/laravel-seo-meta-box
用法
artisan migrate artisan vendor:publish --tag=metabox-config
/** * Manual entry */ Seo::create([ 'slug' => '/', //this is the page route 'title' => 'Super special application', 'description' => 'My super special application that does x', 'type' => 'page' ]); /** * Model based generator */ use Giuga\LaravelSeoMetaBox\Traits\HasSeo; use Giuga\LaravelSeoMetaBox\Traits\SeoOptions; use Illuminate\Database\Eloquent\Model; class Page extends Model { use HasSeo; public function getSeoOptions(): SeoOptions { return SeoOptions::create() ->setSlugField('slug') // optional ->setRoutePrefix('/page/') // optional ->setTitleField('name') // optional ->setDescriptionField('short_description') // optional ->setOverwriteOnUpdate(); // optional } }
更改您的应用程序布局以包括@metabox blade组件
<head> @metabox <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="https://fonts.googleapis.com/css?family=Montserrat&display=swap" rel="stylesheet"> <link href="{{ asset('css/app.css') }}" rel="stylesheet"> </head>
输出结果(所有选项已启用)
<title>Super special application - Application Name</title> <meta name="description" content="My super special application that does x"/> <meta name="twitter:card" content="summary"> <meta name="twitter:site" content="@g_iuga"> <meta name="twitter:title" content="Super special application - Application Name"> <meta name="twitter:description" content="My super special application that does x"> <meta name="twitter:creator" content="@g_iuga"> <meta property="og:title" content="Super special application - Application Name" /> <meta property="og:type" content="article" /> <meta property="og:url" content="https://example.com" /> <meta property="og:description" content="My super special application that does x" /> <meta property="og:site_name" content="Application Name" />
测试
phpunit
视图定制
如果您想以任何方式定制输出,可以通过发布视图来实现
artisan vendor:publish --tag=metabox-views
变更日志
请参阅CHANGELOG以获取更多关于最近更改的信息。
贡献
请参阅CONTRIBUTING以获取详细信息。
安全
如果您发现任何安全问题,请发送电子邮件至me@iuga.dev而不是使用问题跟踪器。
鸣谢
许可
MIT许可(MIT)。请参阅许可文件以获取更多信息。