Last active
April 4, 2018 23:36
-
-
Save cvega93/e91616df2438912f0a6b4c08cfbdf863 to your computer and use it in GitHub Desktop.
Sitemap generation example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Code example to generate sitemap with https://github.com/dwightwatson/sitemap | |
<?php | |
namespace App\Http\Controllers\Admin; | |
use App\Services\DebateService; | |
use App\Http\Controllers\Controller; | |
use App\Services\GroupService; | |
use App\Services\InvitationService; | |
use App\Services\InvitationThemeService; | |
use App\Services\NameService; | |
use App\Services\UserService; | |
use Watson\Sitemap\Facades\Sitemap; | |
class SitemapController extends Controller | |
{ | |
/** | |
* Display a listing of the resource. | |
* | |
* @return \Illuminate\Http\Response | |
*/ | |
public function index() | |
{ | |
Sitemap::addSitemap(route('sitemap.estaticas')); | |
Sitemap::addSitemap(route('sitemap.debates')); | |
Sitemap::addSitemap(route('sitemap.grupos')); | |
Sitemap::addSitemap(route('sitemap.nombres')); | |
Sitemap::addSitemap(route('sitemap.calculadoras')); | |
Sitemap::addSitemap(route('sitemap.tarjetas')); | |
Sitemap::addSitemap(route('sitemap.profiles')); | |
return Sitemap::index(); | |
} | |
public function debates() | |
{ | |
$debates = (new DebateService())->getActiveDebates(); | |
foreach ($debates as $debate) { | |
$tag = Sitemap::addTag(route('portal.debate.show', $debate->slug), $debate->updated_at, 'daily', '0.5'); | |
if( $debate->images->count()) { | |
foreach($debate->images as $image) { | |
$tag->addImage($image->path); | |
} | |
} | |
} | |
return Sitemap::render(); | |
} | |
public function grupos() | |
{ | |
$grupos = (new GroupService())->all(); | |
Sitemap::addTag(route('portal.groups.index'), null, 'daily', '0.5'); | |
foreach($grupos as $grupo) { | |
Sitemap::addTag(route('portal.groups.show', $grupo->slug), null, 'daily', '0.7'); | |
Sitemap::addTag(route('portal.groups.gallery', $grupo->slug), null, 'daily', '0.7'); | |
Sitemap::addTag(route('portal.groups.members', $grupo->slug), null, 'daily', '0.7'); | |
} | |
return Sitemap::render(); | |
} | |
public function nombres() | |
{ | |
$names = (new NameService())->all(); | |
Sitemap::addTag(route('portal.name.index'), null, 'daily', '1'); | |
Sitemap::addTag(url('nombres-para-ninos'), null, 'daily', '1'); | |
Sitemap::addTag(url('nombres-para-ninas'), null, 'daily', '1'); | |
Sitemap::addTag(url('top-100-nombres-de-bebes'), null, 'daily', '1'); | |
Sitemap::addTag(url('nombres-para-bebes-unisex'), null, 'daily', '1'); | |
foreach ($names as $name) { | |
Sitemap::addTag(route('portal.debate.show', $name->slug), $name->updated_at, 'weekly', '0.5'); | |
} | |
return Sitemap::render(); | |
} | |
public function calculadoras() | |
{ | |
Sitemap::addTag(url('portal.height.child.calculator'), null, 'daily', '0.5'); | |
Sitemap::addTag(url('portal.weight.size.child.calculator'), null, 'daily', '0.5'); | |
Sitemap::addTag(url('portal.birth.day.calculator'), null, 'daily', '0.5'); | |
Sitemap::addTag(url('portal.pregnancy-week'), null, 'daily', '0.5'); | |
Sitemap::addTag(url('portal.all.calculator'), null, 'daily', '0.5'); | |
return Sitemap::render(); | |
} | |
public function tarjetas() | |
{ | |
Sitemap::addTag(route('invitations.index'), null, 'daily', '0.1'); | |
Sitemap::addTag(route('invitations.index.all'), null, 'daily', '0.6'); | |
Sitemap::addTag(url('invitaciones-para-baby-shower'), null, 'daily', '0.6'); | |
Sitemap::addTag(url('invitaciones-para-cumpleanos'), null, 'daily', '0.6'); | |
Sitemap::addTag(url('invitaciones-para-bautizo'), null, 'daily', '0.6'); | |
$invitations = (new InvitationThemeService())->all(); | |
foreach($invitations as $invitation) { | |
Sitemap::addTag(route('invitation.show', $invitation->slug), null, 'daily', '0.6'); | |
} | |
return Sitemap::render(); | |
} | |
public function profiles() | |
{ | |
$users = (new UserService())->all(); | |
foreach ($users as $user) { | |
Sitemap::addTag(route('portal.user.index', $user->slug), null, 'daily', '0.7'); | |
} | |
return Sitemap::render(); | |
} | |
public function estaticas() | |
{ | |
Sitemap::addTag(route('preguntas.frecuentes'), null, 'daily', '0.1'); | |
Sitemap::addTag(route('terminos.condiciones'), null, 'daily', '0.1'); | |
Sitemap::addTag(route('politicas.privacidad'), null, 'daily', '0.1'); | |
Sitemap::addTag(route('contacto'), null, 'daily', '0.1'); | |
return Sitemap::renderSitemap(); | |
} | |
} | |
################################# | |
# Las rutas serían algo así | |
Route::get('sitemap.xml', 'Admin\SitemapController@index')->name('sitemap.index'); | |
Route::group(['prefix' => 'sitemap'], function () { | |
Route::get('debates.xml', 'Admin\SitemapController@debates')->name('sitemap.debates'); | |
Route::get('grupos.xml', 'Admin\SitemapController@grupos')->name('sitemap.grupos'); | |
Route::get('nombres.xml', 'Admin\SitemapController@nombres')->name('sitemap.nombres'); | |
Route::get('calculadoras.xml', 'Admin\SitemapController@calculadoras')->name('sitemap.calculadoras'); | |
Route::get('tarjetas.xml', 'Admin\SitemapController@tarjetas')->name('sitemap.tarjetas'); | |
Route::get('perfiles.xml', 'Admin\SitemapController@profiles')->name('sitemap.profiles'); | |
Route::get('estaticas.xml', 'Admin\SitemapController@estaticas')->name('sitemap.estaticas'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment