ellisthedev/laravel-5-robots

此包已被废弃,不再维护。未建议替代包。

Laravel 5 机器人.txt 生成器

0.1.0 2015-04-30 21:39 UTC

This package is not auto-updated.

Last update: 2020-04-23 15:40:40 UTC


README

Current Release Total Downloads Build Status Code Climate Test Coverage

这是对https://github.com/jayhealey/Robots的分支。原始存储库上的开发似乎已经停滞。

此分支的目的是引入 Laravel 5 兼容性以及 PSR-4 和 PSR-2(针对 Laravel 5.1)。

安装

步骤 1: Composer

将包添加到您的 composer.json

{
    "require": {
        "ellisthedev/laravel-5-robots": "~0.1.0"
    }
}

步骤 2: 配置

将以下内容添加到您的 config/app.php 中的 providers 数组

'EllisTheDev\Robots\RobotsServiceProvider',

您还可以选择性地将以下内容添加到 aliases 数组

'Robots' => 'EllisTheDev\Robots\RobotsFacade',

用法

删除项目默认的 public/robots.txt

将以下内容添加到您的路由文件中

Route::get('robots.txt', function ()
{
    if (App::environment() == 'production') {
        // If on the live server, serve a nice, welcoming robots.txt.
        Robots::addUserAgent('*');
        Robots::addSitemap('sitemap.xml');
    } else {
        // If you're on any other server, tell everyone to go away.
        Robots::addDisallow('*');
    }

    return Response::make(Robots::generate(), 200, ['Content-Type' => 'text/plain']);
});

有关 API 用法的详细信息,请参阅 Robots.php

许可协议

MIT