50 lines
1.6 KiB
PHP
50 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
define('BASE_PATH', realpath(__DIR__ . '/../'));
|
|
|
|
require_once BASE_PATH . '/src/helpers.php';
|
|
require_once BASE_PATH . '/config/config.php';
|
|
require_once BASE_PATH . '/src/ArticleManager.php';
|
|
|
|
$articles = new ArticleManager(BASE_PATH . '/data');
|
|
$privateCats = $articles->getPrivateCategories();
|
|
|
|
$published = array_filter($articles->getAll(true), static function (array $a) use ($privateCats): bool {
|
|
$cat = trim($a['category'] ?? '');
|
|
if ($cat !== '' && in_array($cat, $privateCats, true)) {
|
|
return false;
|
|
}
|
|
if (strtotime((string)($a['published_at'] ?? '')) > time()) {
|
|
return false;
|
|
}
|
|
return true;
|
|
});
|
|
|
|
header('Content-Type: application/xml; charset=UTF-8');
|
|
header('X-Robots-Tag: noindex');
|
|
|
|
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
|
|
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
|
|
|
|
// Homepage
|
|
echo ' <url>' . "\n";
|
|
echo ' <loc>' . htmlspecialchars(rtrim(APP_URL, '/') . '/') . '</loc>' . "\n";
|
|
echo ' <changefreq>daily</changefreq>' . "\n";
|
|
echo ' <priority>1.0</priority>' . "\n";
|
|
echo ' </url>' . "\n";
|
|
|
|
foreach ($published as $article) {
|
|
$loc = htmlspecialchars(rtrim(APP_URL, '/') . '/post/' . rawurlencode($article['slug'] ?? ''));
|
|
$lastmod = date('Y-m-d', strtotime((string)($article['updated_at'] ?? $article['published_at'] ?? 'now')));
|
|
echo ' <url>' . "\n";
|
|
echo ' <loc>' . $loc . '</loc>' . "\n";
|
|
echo ' <lastmod>' . $lastmod . '</lastmod>' . "\n";
|
|
echo ' <changefreq>monthly</changefreq>' . "\n";
|
|
echo ' <priority>0.8</priority>' . "\n";
|
|
echo ' </url>' . "\n";
|
|
}
|
|
|
|
echo '</urlset>' . "\n";
|