-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.php
More file actions
42 lines (36 loc) · 1.24 KB
/
example.php
File metadata and controls
42 lines (36 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Vendor\SitemapGenerator\SitemapGenerator;
use Vendor\SitemapGenerator\Exceptions\InvalidDataException;
use Vendor\SitemapGenerator\Exceptions\FileWriteException;
use Vendor\SitemapGenerator\Exceptions\UnsupportedFormatException;
use Vendor\SitemapGenerator\Exceptions\DuplicateUrlException;
$urls = [
[
'loc' => 'https://site.ru/',
'lastmod' => '2020-12-14',
'priority' => 1.0,
'changefreq' => 'hourly'
],
[
'loc' => 'https://site.ru/news',
'lastmod' => '2020-12-10',
'priority' => 0.5,
'changefreq' => 'daily'
],
[
'loc' => 'https://site.ru/about',
'lastmod' => '2020-12-07',
'priority' => 0.1,
'changefreq' => 'weekly'
],
];
try {
// Создаем объект генератора карты сайта
$generator = new SitemapGenerator('xml', __DIR__ . '/sitemaps/sitemap.xml');
// Генерируем файл
$generator->generate($urls);
echo "Карта сайта успешно создана!";
} catch (InvalidDataException | FileWriteException | UnsupportedFormatException | DuplicateUrlException $e) {
echo "Ошибка: " . $e->getMessage();
}