承接 spescina/seorules 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

spescina/seorules

Composer 安装命令:

composer require spescina/seorules

包简介

A tool for building seo rules in your Laravel projects

README 文档

README

A package for building seo rules in your Laravel projects. Manage with ease SEO meta tags (title, description, keywords, noindex) of your pages.

Installation

To install Seorules in Laravel 5.1, simply run composer require spescina\seorules.
To install Seorules in Laravel 4, simply run composer require spescina\seorules 1.* and then follow these instructions.

Once it's installed, you have to register the service provider. In app/config/app.php add the following line of code to the providers array
Spescina\Seorules\SeorulesServiceProvider::class.

If you want in app/config/app.php add the following line of code to the aliases array
'Seo' => Spescina\Seorules\Facades\Seo::class.

Register the route middleware adding these line to the app/Http/Kernel.php file
'seorules.before' => \Spescina\Seorules\Init::class.

Then, publish the config file with php artisan vendor:publish --provider="Spescina\Seorules\SeorulesServiceProvider" --tag="config" .
Then, publish the migration file with php artisan vendor:publish --provider="Spescina\Seorules\SeorulesServiceProvider" --tag="migrations" .

Then run the migration with php artisan migrate.

Usage

Define your rules creating entries in the seorules database table

  • alias: system identificative name of the rule
  • route: name of the target route
  • pattern: regular expression for matching page url (used for targeting different pages on the same route)
  • priority: highest value come first
  • title: title tag
  • description: description meta tag
  • keywords: keywords meta tag
  • noindex: noindex meta tag
{
  alias: 'first',
  route: 'first.route',
  pattern: '',
  priority: 0,
  title: 'the first route title is [#_first_placeholder]',
  description: 'my first route description is [#_second_placeholder]',
  keywords: '[#_first_placeholder], [#_second_placeholder], laravel',
  noindex: 0
},
{
  alias: 'second',
  route: 'second.route',
  pattern: '',
  priority: 0,
  title: 'the second route title is [#_second_placeholder]',
  description: 'my second route description is empty',
  keywords: '[#_first_placeholder]',
  noindex: 1
}

Attach seorules.before middleware to your target named routes (route groups are reccomended)

Route::group(['middleware' => 'seorules.before'], function()
{
    Route::get('/first', array('as' => 'first.route', function(){
        //do things
    }));

    Route::get('/second', array('as' => 'second.route', function(){
        //do things
    }));
});

Manage your rules in your controllers or in your closures

Seo::addPlaceholder('first_placeholder','Foo');
Seo::addPlaceholder('second_placeholder','Bar');

Display prepared fields in your views

<title>{{ Seo::get('title') }}</title>
<meta name="description" content="{{ Seo::get('description') }}" />
<meta name="keywords" content="{{ Seo::get('keywords') }}" />
@if (Seo::get('noindex'))
<meta name="robots" content="noindex" />
@endif

Now you should have rendered this code when visiting /first (assuming both routes are prepared with same placeholder data)

<title>the first route title is Foo</title>
<meta name="description" content="my first route description is Bar" />
<meta name="keywords" content="Foo, Bar, laravel" />

and when visting /second

<title>the second route title is Bar</title>
<meta name="description" content="my second route description is empty" />
<meta name="keywords" content="Foo" />
<meta name="robots" content="noindex" />

统计信息

  • 总下载量: 628
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 11
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 11
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-08-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固