oxyagency/laravel-5-robots

Laravel 5 Robots.txt 生成器

1.0.0 2022-07-14 12:41 UTC

This package is not auto-updated.

Last update: 2024-09-20 21:42:33 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',

用法

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

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