<?php
header('Content-Type: application/xml; charset=UTF-8');

$base = 'https://sharpeningbyhand.com';

$pages = [
    '/',
    '/contact.php',
    '/order.php'
];

function lastmod($path) {
    $fullPath = $_SERVER['DOCUMENT_ROOT'] . $path;
    return file_exists($fullPath)
        ? date('Y-m-d', filemtime($fullPath))
        : date('Y-m-d');
}

echo '<?xml version="1.0" encoding="UTF-8"?>';
echo "\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";

foreach ($pages as $page) {
    echo "  <url>\n";
    echo "    <loc>" . htmlspecialchars($base . $page, ENT_QUOTES, 'UTF-8') . "</loc>\n";
    echo "    <lastmod>" . lastmod($page) . "</lastmod>\n";
    echo "    <changefreq>monthly</changefreq>\n";
    echo "    <priority>" . ($page === '/' ? '1.0' : '0.8') . "</priority>\n";
    echo "  </url>\n";
}

echo "</urlset>";