agpretto / metadata
Laravel应用程序的元数据包
v0.2.0
2019-09-14 15:02 UTC
Requires
- php: ^7.1
- illuminate/console: ^5.0|^6.0
- illuminate/view: ^5.0|^6.0
Requires (Dev)
- phpunit/phpunit: ^7.5|^8.0
This package is auto-updated.
Last update: 2024-09-29 05:48:40 UTC
README
此包提供了一种在视图中包含元数据标签和其他SEO相关值的方法。
这是在不使用数据库的情况下在网页中注入元数据的最灵活方式。
如果您不需要对SEO元数据进行复杂的实现,请使用此包。
配置
Composer
在您的composer.json文件中要求此包。
"agpretto/metadata": "^0.1"
安装
使用包安装命令将元数据安装到您的应用程序中。
php artisan metadata:install // or php artisan metadata:install --template
您可以选择将默认元数据模板发布到您的
resouces/views/vendor/metadata
文件夹。
您可以通过使用标志-T
或--template
来选择发布元数据模板。
用法
此包是一个非常简单的元数据管理套件,用于在视图中包含元数据标签和相关SEO值。
-
在使用此包之前,请更新配置文件
config/metadata.php
,并添加您的默认SEO信息。 -
在您的基布局视图中添加一个新的堆栈。这个堆栈将收集所有您的SEO元数据。
// main layout <!DOCTYPE html> <html> <head> <!-- Metadata --> @stack('metadata') </head> <body> </body> </html>
现在您可以包含元数据了。
- 选择您网站内容的公共视图(例如,views/articles/page.blade.php)。
@extends('layouts.page') @section('content') <section> <h2>{{ $article->title }}</h2> <div>{{ $article->body }}</div> </section> @endsection // push metadata view on the stack @push('metadata') @include('metadata::metadata', [ 'title' => $article->title, // <- use the model title to contextualize the title metadata 'author' => 'John Doe' // <- or simply overrides default author value at runtime ]) @endpush
致谢
此包由星际开发者Andrea Giuseppe为您构建 - Github