abzudev / laravel-spa-seo
Laravel SPA SEO增强功能
dev-master
2019-10-20 17:16 UTC
Requires
- php: >=5.5.9
- nesk/puphpeteer: ^1.6
- sunra/php-simple-html-dom-parser: ^1.5
Requires (Dev)
- orchestra/testbench: ~3.8.0
- phpunit/phpunit: ^8.0
This package is auto-updated.
Last update: 2024-09-21 05:26:04 UTC
README
请注意:此软件包仍在开发中。
示例
控制器
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Abzudev\LaravelSpaSeo\SpaContent;
class AppController extends Controller
{
/**
* @param Illuminate\Http\Request $request
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index(Request $request)
{
$context['html_source'] = SpaContent::getHtmlContent($request);
return view('index', $context);
}
}
Blade模板
<!DOCTYPE html>
<html lang="en">
<head>
\\ Head content
</head>
<body>
<div id="app">
@if(isset($html_source) and !empty($html_source))
{!! $html_source !!}
@else
\\ Content
@endif
</div>
// Any additional HTML
</body>
</html>
说明
该软件包返回在body标签中找到的第一个
的渲染HTML。因此,为确保返回正确的HTML,请确保body的第一个div是您的SPA的挂载元素。在第一个div之后,您可以放置任何其他内容,但这些内容将不包括在渲染的HTML中。
需求
此软件包需要node 8.0或更高版本以及Puppeteer Node库,并使用nesk/puphpeteer软件包。
您需要通过NPM在您的项目中安装@nesk/puphpeteer。
npm install @nesk/puphpeteer
安装
要安装此软件包,请运行
composer require abzudev/laravel-spa-seo
如果您使用的是Laravel 5.5+,则软件包将自动注册。
或者,您需要将SpaSeoServiceProvider添加到app.php中的服务提供者列表中。
您可以使用以下命令发布配置文件
php artisan vendor:publish --provider="Abzudev\LaravelSpaSeo\SpaSeoServiceProvider" --tag="config"
这是已发布配置文件的内容
return [ /* |-------------------------------------------------------------------------- | Cache Lifetime |-------------------------------------------------------------------------- | | Here you may specify the number of minutes that you wish the cache | to be allowed to remain idle before it expires. | */ 'cache_lifetime' => env('SPA_CACHE_LIFETIME', 60), /* |-------------------------------------------------------------------------- | Route Lifetime |-------------------------------------------------------------------------- | | This array of routes will allow you to specify the cache lifetime | of specific routes. By default each route will use the 'cache_lifetime' | as the amount of minutes that vue will be cached. | */ 'routes' => [ // '/' => 60, (1 hour) // '/about' => 1440, (1 day) // '/contact' => 43200, (30 days) ], ];
测试
使用以下命令运行测试
composer test
更新日志
请参阅更新日志以获取最近更改的更多信息。
贡献
请参阅贡献指南以获取详细信息。
安全性
如果您发现任何安全问题,请通过电子邮件jeandrew.swart@gmail.com报告,而不是使用问题跟踪器。
许可协议
MIT许可协议(MIT)。请参阅许可文件以获取更多信息。