No URL of an image in XML sitemap, just 'file'

Hi,

I am trying set up my sitemap.xml to include cover image of any given page listed there.

Despite setting up sitemap template in such a way:

<?= '<?xml version="1.0" encoding="utf-8"?>'; ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
  <?php foreach ($pages as $p): ?>
    <?php if (in_array($p->uri(), $ignore)) continue ?>
    <url>
      <loc><?= html($p->url()) ?></loc>
      <lastmod><?= $p->modified('c') ?></lastmod>
      <priority><?= ($p->isHomePage()) ? 1 : number_format(0.5 / $p->depth(), 1) ?></priority>

        <?php if ($p->cover()->isNotEmpty()): ?>
            <image:image>
                <image:loc><?= html($p->cover()->url()) ?></image:loc>
            </image:image>
        <?php endif; ?>

    </url>
  <?php endforeach ?>
</urlset>

I am being served finally with these (see code below). Please note that I am getting no URL to the image just - file://….

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">

<url>

<loc>https://example.com/samplepage</loc>

<lastmod>2025-02-26T10:27:57+01:00</lastmod>

<priority>0.5</priority>

<image:image>

<image:loc>- file://4hlkBiVWqWqaJKt6</image:loc>

</image:image>

</url>

A files field value needs to be converted to a file object before you can call the url() method on it, see Files | Kirby CMS

My sitemap template is now set like code cited below and it is rendering results as it is demanded!

Thanks, @texnixe for your knowledge and guidance! :pray:

<?= '<?xml version="1.0" encoding="utf-8"?>'; ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
  <?php foreach ($pages as $p): ?>
    <?php if (in_array($p->uri(), $ignore)) continue ?>
    <url>
      <loc><?= html($p->url()) ?></loc>
      <lastmod><?= $p->modified('c') ?></lastmod>
      <priority><?= ($p->isHomePage()) ? 1 : number_format(0.5 / $p->depth(), 1) ?></priority>

        <?php if ($p->cover()->isNotEmpty()): ?>
            <image:image>
                <image:loc>
                <?php if($image = $p->cover()->toFile()): ?>
                <?= $image->resize(1200, 1200, 100)->url() ?>
                <?php endif ?>
                </image:loc>
            </image:image>
        <?php endif; ?>

    </url>
  <?php endforeach ?>
</urlset>