#29: Labels are now included in the sitemap.xml

This commit is contained in:
Andy Heathershaw 2017-09-10 12:52:41 +01:00
parent 693f0c6760
commit 0d0584086b
2 changed files with 20 additions and 2 deletions

View File

@ -7,6 +7,7 @@ use App\Facade\Theme;
use App\Facade\UserConfig;
use App\Helpers\DbHelper;
use App\Http\Controllers\Controller;
use App\Label;
use App\Photo;
use App\VisitorHit;
use Illuminate\Http\Request;
@ -54,6 +55,18 @@ class DefaultController extends Controller
// Albums the current user is allowed to access
$albumIDs = DbHelper::getAlbumIDsForCurrentUser();
// Add each label
$labels = Label::orderBy('name');
$labels->chunk(100, function($labelsChunk) use ($xml, $root)
{
/** @var Label $label */
foreach ($labelsChunk as $label)
{
$lastModifiedPhoto = $label->photos()->orderBy('updated_at', 'desc')->first();
$this->createSitemapNode($xml, $root, $label->url(), (is_null($lastModifiedPhoto) ? $label->updated_at : $lastModifiedPhoto->updated_at), '0.9');
}
});
// Add each album URL
$albums = Album::whereIn('id', $albumIDs)->orderBy('name');
$albums->chunk(100, function($albumsChunk) use ($xml, $root)
@ -62,7 +75,7 @@ class DefaultController extends Controller
foreach ($albumsChunk as $album)
{
$lastModifiedPhoto = Photo::where('album_id', $album->id)->orderBy('updated_at', 'desc')->first();
$this->createSitemapNode($xml, $root, $album->url(), (is_null($lastModifiedPhoto) ? $album->updated_at : $lastModifiedPhoto->updated_at), '0.9');
$this->createSitemapNode($xml, $root, $album->url(), (is_null($lastModifiedPhoto) ? $album->updated_at : $lastModifiedPhoto->updated_at), '0.8');
}
});
@ -84,7 +97,7 @@ class DefaultController extends Controller
$root,
$photo->url(),
$photo->updated_at,
'0.8',
'0.7',
$photo->thumbnailUrl('fullsize', false),
join(' - ', $photoMeta)
);

View File

@ -25,4 +25,9 @@ class Label extends Model
{
return $this->belongsToMany(Photo::class, 'photo_labels');
}
public function url()
{
return route('viewLabel', $this->url_alias);
}
}