网站sitemap

This commit is contained in:
TL 2022-10-12 17:01:32 +08:00 committed by Edward Yang
parent cdf7c6724d
commit 99eb8c2cbd
3 changed files with 135 additions and 1 deletions

View File

@ -0,0 +1,55 @@
<?php
/**
* SitemapService.php
*
* @copyright 2022 beikeshop.com - All Rights Reserved
* @link https://beikeshop.com
* @author TL <mengwb@guangda.work>
* @created 2022-10-09 17:34:34
* @modified 2022-10-09 17:34:34
*/
namespace Beike\Services;
use Beike\Models\Brand;
use Beike\Models\Category;
use Beike\Models\Page;
use Beike\Models\Product;
class SitemapService
{
public static function gen(): void
{
$sitemap = resolve("sitemap");
$sitemap->add(shop_route('brands.index'), date('c'));
$sitemap->add(shop_route('categories.index'), date('c'));
$sitemap->add(shop_route('forgotten.index'), date('c'));
$sitemap->add(shop_route('login.index'), date('c'));
$sitemap->add(shop_route('products.search'), date('c'));
$sitemap->add(shop_route('register.index'), date('c'));
$products = Product::query()->where('active', 1)->orderBy('updated_at', 'desc')->get();
foreach ($products as $item) {
$sitemap->add(shop_route('products.show', ['product'=>$item->id]), $item->updated_at->format('c'));
}
$brands = Brand::query()->where('status', 1)->orderBy('updated_at', 'desc')->get();
foreach ($brands as $item) {
$sitemap->add(shop_route('brands.show', ['id'=>$item->id]), $item->updated_at->format('c'));
}
$categories = Category::query()->where('active', 1)->orderBy('updated_at', 'desc')->get();
foreach ($categories as $item) {
$sitemap->add(shop_route('categories.show', ['category'=>$item->id]), $item->updated_at->format('c'));
}
$pages = Page::query()->where('active', 1)->orderBy('updated_at', 'desc')->get();
foreach ($pages as $item) {
$sitemap->add(shop_route('pages.show', ['page'=>$item->id]), $item->updated_at->format('c'));
}
$sitemap->store('xml', 'sitemap');
}
}

View File

@ -21,6 +21,7 @@
"srmklive/paypal": "^3.0",
"stripe/stripe-php": "^8.8",
"tormjens/eventy": "^0.8.0",
"ultrono/laravel-sitemap": "^9.1",
"zanysoft/laravel-zip": "^2.0"
},
"require-dev": {

80
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "a6c6b01c79d7432cd602e320cafb6110",
"content-hash": "5e07b1ed3b9aa782c38fb64150da497e",
"packages": [
{
"name": "asm89/stack-cors",
@ -6520,6 +6520,84 @@
},
"time": "2021-10-22T08:33:10+00:00"
},
{
"name": "ultrono/laravel-sitemap",
"version": "9.1.0",
"source": {
"type": "git",
"url": "https://github.com/ultrono/laravel-sitemap.git",
"reference": "27489bd4d0bfa6e017dad143bc1c3d120d1cd8de"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/ultrono/laravel-sitemap/zipball/27489bd4d0bfa6e017dad143bc1c3d120d1cd8de",
"reference": "27489bd4d0bfa6e017dad143bc1c3d120d1cd8de",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"illuminate/filesystem": "^8.0 || ^9.0",
"illuminate/support": "^8.0 || ^9.0",
"php": "^8.0"
},
"require-dev": {
"laravel/framework": "^8.0 || ^9.0",
"orchestra/testbench-core": "^6.0 || ^7.0",
"php-coveralls/php-coveralls": "^2.2",
"phpunit/phpunit": "^9.3"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Ultrono\\Sitemap\\SitemapServiceProvider"
]
}
},
"autoload": {
"psr-0": {
"Ultrono\\Sitemap": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Rumen Damyanov",
"email": "r@alfamatter.com",
"homepage": "https://darumen.com",
"role": "Original Developer"
},
{
"name": "Rob Allport",
"email": "rob@f9web.co.uk",
"homepage": "https://f9web.co.uk",
"role": "Developer"
}
],
"description": "PHP 8 sitemap generator for Laravel 8 and 9",
"keywords": [
"Sitemap",
"generator",
"google-news",
"html",
"laravel",
"php",
"xml"
],
"support": {
"issues": "https://github.com/ultrono/laravel-sitemap/issues",
"source": "https://github.com/ultrono/laravel-sitemap"
},
"time": "2022-03-11T10:11:30+00:00"
},
{
"name": "vlucas/phpdotenv",
"version": "v5.4.1",