mirror of
https://github.com/openclassify/openclassify.git
synced 2026-01-11 18:01:10 -06:00
#1811 SEO links in cats
This commit is contained in:
parent
c57a1b3518
commit
4a7ce85a77
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'sitemap_dividing_number' => [
|
||||
"type" => "anomaly.field_type.integer",
|
||||
"config" => [
|
||||
"default_value" => 5000,
|
||||
]
|
||||
],
|
||||
];
|
||||
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'sitemap_dividing_number' => [
|
||||
'name' => 'Sitemap Dividing Number',
|
||||
],
|
||||
];
|
||||
@ -1,9 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
{% for category in categories %}
|
||||
{% for link in sitemapLinks %}
|
||||
<url>
|
||||
<loc>{{ url_route('adv_list_seo', [category.slug]) }}</loc>
|
||||
<lastmod>{{ category.created_at.tz('UTC').toAtomString() }}</lastmod>
|
||||
<loc>{{ link }}</loc>
|
||||
<changefreq>weekly</changefreq>
|
||||
</url>
|
||||
{% endfor %}
|
||||
|
||||
@ -2,22 +2,31 @@
|
||||
|
||||
use Anomaly\Streams\Platform\Http\Controller\PublicController;
|
||||
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
|
||||
use Visiosoft\LocationModule\City\Contract\CityRepositoryInterface;
|
||||
|
||||
class SitemapController extends PublicController
|
||||
{
|
||||
|
||||
private $categoryRepository;
|
||||
private $cityRepository;
|
||||
|
||||
public function __construct(CategoryRepositoryInterface $categoryRepository)
|
||||
public function __construct(
|
||||
CategoryRepositoryInterface $categoryRepository,
|
||||
CityRepositoryInterface $cityRepository
|
||||
)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->categoryRepository = $categoryRepository;
|
||||
$this->cityRepository = $cityRepository;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$categoriesCount = $this->categoryRepository->count();
|
||||
$pagesCount = ceil($categoriesCount / 5000);
|
||||
$citiesCount = $this->cityRepository->count();
|
||||
|
||||
$pagesCount = $citiesCount ? $categoriesCount * $citiesCount : $categoriesCount;
|
||||
$pagesCount = ceil($pagesCount / setting_value('visiosoft.module.cats::sitemap_dividing_number'));
|
||||
|
||||
return response()->view('visiosoft.module.cats::sitemap.index', [
|
||||
'pagesCount' => $pagesCount,
|
||||
@ -26,13 +35,44 @@ class SitemapController extends PublicController
|
||||
|
||||
public function categories()
|
||||
{
|
||||
$sitemapDividingNumber = setting_value('visiosoft.module.cats::sitemap_dividing_number');
|
||||
$page = request()->page ?: 1;
|
||||
$skip = $page - 1;
|
||||
|
||||
$categories = $this->categoryRepository->newQuery()->skip(5000 * $skip)->take(5000)->get();
|
||||
$citiesCount = $this->cityRepository->count();
|
||||
if ($citiesCount) {
|
||||
$categoriesCount = $this->categoryRepository->count();
|
||||
|
||||
$takeCategories = $categoriesCount / ($categoriesCount * $citiesCount / $sitemapDividingNumber);
|
||||
|
||||
$categories = $this->categoryRepository
|
||||
->newQuery()
|
||||
->skip($takeCategories * $skip)
|
||||
->take($takeCategories)
|
||||
->get();
|
||||
|
||||
$sitemapLinks = array();
|
||||
$cities = $this->cityRepository->all();
|
||||
foreach ($categories as $category) {
|
||||
foreach ($cities as $city) {
|
||||
$sitemapLinks[] = route('adv_list_seo', [$category->slug, $city->slug]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$categories = $this->categoryRepository
|
||||
->newQuery()
|
||||
->skip($sitemapDividingNumber * $skip)
|
||||
->take($sitemapDividingNumber)
|
||||
->get();
|
||||
|
||||
$sitemapLinks = array();
|
||||
foreach ($categories as $category) {
|
||||
$sitemapLinks[] = route('adv_list_seo', [$category->slug]);
|
||||
}
|
||||
}
|
||||
|
||||
return response()->view('visiosoft.module.cats::sitemap.categories', [
|
||||
'categories' => $categories,
|
||||
'sitemapLinks' => $sitemapLinks,
|
||||
])->header('Content-Type', 'text/xml');
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user