samkitano/seo-gen
Composer 安装命令:
composer require samkitano/seo-gen
包简介
Generate sitemap.xml and robots.txt files in Laravel 4.2 with support for multi-language. Based on Hettiger/SeoAggregator
README 文档
README
Generate robots.txt and multi-language sitemap.xml files in Laravel 4.2.
Based on Hettiger/seo-aggregator
Installation
Require with composer
// composer.json "require": { "php": ">=5.4.0", "samkitano/seo-gen": "dev-master", // ... },
Add provider in app\config\app.php
// ... 'Samkitano\SeoGen\SeoGenServiceProvider',
Publish configuration file
php artisan config:publish samkitano/seo-gen
Modify app\config\packages\samkitano\seo-gen\config.php to suit your needs.
Provide the name of the file you are using to translate your routes in 'translated_routes_file'. Do not include extension.
If you don't need to translate your url prefix (you wouldn't be here in that case now, would you?) you should probably use another package, but feel free to open a pull request and make some changes :)
For example purposes we will use the default 'translated_routes_file' => 'routes',
Usage examples with Laravel 4.2
Obviously, you will need to have your translation files ready:
/** * app\lang\en\routes.php */ return array( 'home' => 'home', 'portfolio' => 'portfolio', 'contacts' => 'contacts', 'pages' => 'pages', // ... );
/** * app\lang\pt\routes.php */ return array( 'home' => 'inicio', 'portfolio' => 'portefolio', 'contacts' => 'contactos', 'pages' => 'paginas', // ... );
/** * app\lang\fr\routes.php */ return array( 'home' => 'accueil', 'portfolio' => 'portefeuille', 'contacts' => 'contacts', 'pages' => 'pages', // ... );
/** * app\lang\de\routes.php */ return array( 'home' => 'startseite', 'portfolio' => 'portefeuille', 'contacts' => 'kontakte', 'pages' => 'seiten', // ... );
SeoGen will take a look at your app configuration file to find out your app's default language and the available languages.
/** * app\config\app.php */ /* |-------------------------------------------------------------------------- | Application Locale Configuration |-------------------------------------------------------------------------- | | The application locale determines the default locale that will be used | by the translation service provider. You are free to set this value | to any of the locales which will be supported by the application. | */ 'locale' => 'en', /* |-------------------------------------------------------------------------- | Available Languages |-------------------------------------------------------------------------- | | Supported Languages | */ 'languages' => array('en', 'pt', 'fr', 'de'),
Now you can use SeoGen wherever you like in your app.
For the sake of this example's simplicity we will do it right in app\routes.php, but you should use a controller instead.
/** * app/routes.php */ use Samkitano\SeoGen\Facades\Sitemap; use Samkitano\SeoGen\Facades\Robots; // Language Selection $languages = array('en', 'pt', 'fr', 'de'); $locale = Request::segment(1); if ( in_array($locale, $languages) ) { \App::setLocale($locale); Session::put('locale', $locale); } else { $locale = null; } Route::group( array('prefix' => $locale), function() { Route::get( trans('routes.home'), array('as' => 'home', 'uses' => 'ExampleController@home') ); Route::get( trans('routes.portfolio'), array('as' => 'portfolio', 'uses' => 'ExampleController@portfolio') ); Route::get( trans('routes.contacts'), array('as' => 'contacts', 'uses' => 'ExampleController@contacts') ); Route::get( trans('routes.pages' . '/{slug}'), array('as' => 'pages', 'uses' => 'ExampleController@pages') ); } ); Route::get('sitemap.xml', function() { $date_time = new DateTime('now'); Sitemap::addLink($date_time, 'home'); Sitemap::addLink($date_time, 'portfolio'); Sitemap::addLink($date_time, 'contacts'); $collection = Pages::all(); Sitemap::addCollection($collection, 'pages'); return Response::make( Sitemap::getSitemapXml() ) ->header('Content-Type', 'text/xml'); }); Route::get('robots.txt', function() { Robots::disallowPath('/admin'); return Response::make( Robots::getRobotsDirectives(true) ) ->header('Content-Type', 'text/plain'); });
The above example should return a sitemap with something like
<?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml"> <url> <loc>http://example.com/en/home</loc> <xhtml:link rel="alternate" hreflang="pt" href="http://example.com/pt/inicio"/> <xhtml:link rel="alternate" hreflang="fr" href="http://example.com/fr/accueil"/> <xhtml:link rel="alternate" hreflang="de" href="http://example.com/de/startseite"/> <lastmod>2015-06-16</lastmod> </url> <url> <loc>http://example.com/en/portfolio</loc> <xhtml:link rel="alternate" hreflang="pt" href="http://example.com/pt/portefolio"/> <xhtml:link rel="alternate" hreflang="fr" href="http://example.com/fr/portefeuille"/> <xhtml:link rel="alternate" hreflang="de" href="http://example.com/de/portefeuille"/> <lastmod>2015-06-16</lastmod> </url> <url> <loc>http://example.com/en/contacts</loc> <xhtml:link rel="alternate" hreflang="pt" href="http://example.com/pt/contactos"/> <xhtml:link rel="alternate" hreflang="fr" href="http://example.com/fr/contacts"/> <xhtml:link rel="alternate" hreflang="de" href="http://example.com/de/kontakte"/> <lastmod>2015-06-16</lastmod> </url> <url> <loc>http://example.com/en/pages/page-1</loc> <xhtml:link rel="alternate" hreflang="pt" href="http://example.com/pt/paginas/page-1"/> <xhtml:link rel="alternate" hreflang="fr" href="http://example.com/fr/pages/page-1"/> <xhtml:link rel="alternate" hreflang="de" href="http://example.com/de/seiten/page-1"/> <lastmod>2015-06-10</lastmod> </url> <url> <loc>http://example.com/en/pages/page-2</loc> <xhtml:link rel="alternate" hreflang="pt" href="http://example.com/pt/paginas/page-2"/> <xhtml:link rel="alternate" hreflang="fr" href="http://example.com/fr/pages/page-2"/> <xhtml:link rel="alternate" hreflang="de" href="http://example.com/de/seiten/page-2"/> <lastmod>2015-06-10</lastmod> </url> <url> <loc>http://example.com/en/pages/page-3</loc> <xhtml:link rel="alternate" hreflang="pt" href="http://example.com/pt/paginas/page-3"/> <xhtml:link rel="alternate" hreflang="fr" href="http://example.com/fr/pages/page-3"/> <xhtml:link rel="alternate" hreflang="de" href="http://example.com/de/seiten/page-3"/> <lastmod>2015-06-10</lastmod> <url> </urlset>
and robots.txt
User-agent: *
Disallow: /admin
Sitemap: http://example.com/sitemap.xml
Notes
SeoGen does NOT translate slugs for the time being.
License
SEO Aggregator is open-sourced software licensed under the MIT license
SEO GEN is open-sourced software licensed under the MIT license
samkitano/seo-gen 适用场景与选型建议
samkitano/seo-gen 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12 次下载、GitHub Stars 达 1, 最近一次更新时间为 2015 年 06 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「generator」 「seo」 「robots.txt」 「generate」 「sitemap.xml」 「multi-language」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 samkitano/seo-gen 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 samkitano/seo-gen 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 samkitano/seo-gen 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
Help to manage meta data on Laravel Eloquent model
Statamic Fine Seo addon
Robots.txt Generator
A route for serving a basic robots.txt in Laravel 5.1+, based on configuration settings.
Agnostic model to efficiently query and scroll any kind of data (SQL, Search engine, HTTP API, CSV, ...) and push them anywhere with a ETL
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-06-15