mirror of
https://github.com/openclassify/openclassify.git
synced 2026-01-24 22:11:01 -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"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||||
{% for category in categories %}
|
{% for link in sitemapLinks %}
|
||||||
<url>
|
<url>
|
||||||
<loc>{{ url_route('adv_list_seo', [category.slug]) }}</loc>
|
<loc>{{ link }}</loc>
|
||||||
<lastmod>{{ category.created_at.tz('UTC').toAtomString() }}</lastmod>
|
|
||||||
<changefreq>weekly</changefreq>
|
<changefreq>weekly</changefreq>
|
||||||
</url>
|
</url>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
@ -2,22 +2,31 @@
|
|||||||
|
|
||||||
use Anomaly\Streams\Platform\Http\Controller\PublicController;
|
use Anomaly\Streams\Platform\Http\Controller\PublicController;
|
||||||
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
|
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
|
||||||
|
use Visiosoft\LocationModule\City\Contract\CityRepositoryInterface;
|
||||||
|
|
||||||
class SitemapController extends PublicController
|
class SitemapController extends PublicController
|
||||||
{
|
{
|
||||||
|
|
||||||
private $categoryRepository;
|
private $categoryRepository;
|
||||||
|
private $cityRepository;
|
||||||
|
|
||||||
public function __construct(CategoryRepositoryInterface $categoryRepository)
|
public function __construct(
|
||||||
|
CategoryRepositoryInterface $categoryRepository,
|
||||||
|
CityRepositoryInterface $cityRepository
|
||||||
|
)
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->categoryRepository = $categoryRepository;
|
$this->categoryRepository = $categoryRepository;
|
||||||
|
$this->cityRepository = $cityRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$categoriesCount = $this->categoryRepository->count();
|
$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', [
|
return response()->view('visiosoft.module.cats::sitemap.index', [
|
||||||
'pagesCount' => $pagesCount,
|
'pagesCount' => $pagesCount,
|
||||||
@ -26,13 +35,44 @@ class SitemapController extends PublicController
|
|||||||
|
|
||||||
public function categories()
|
public function categories()
|
||||||
{
|
{
|
||||||
|
$sitemapDividingNumber = setting_value('visiosoft.module.cats::sitemap_dividing_number');
|
||||||
$page = request()->page ?: 1;
|
$page = request()->page ?: 1;
|
||||||
$skip = $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', [
|
return response()->view('visiosoft.module.cats::sitemap.categories', [
|
||||||
'categories' => $categories,
|
'sitemapLinks' => $sitemapLinks,
|
||||||
])->header('Content-Type', 'text/xml');
|
])->header('Content-Type', 'text/xml');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user