sitemap.xml: calculate priority from path names
[minimedit.git] / sitemap.xml / index.php
1 <?php
2 ob_clean();
3 header('Content-Type: application/atom+xml; charset=utf-8');
4 print '<?xml version="1.0" encoding="utf-8"?>';
5 $siteref = (empty($_SERVER['HTTPS']) ? 'http' : 'https') . '://' . $_SERVER['HTTP_HOST'];
6 ?>
7
8 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
9 <?php
10 $search = new PageSearch();
11 foreach ($search->files() as $link) {
12         $article = new ArchiveArticle($link);
13         print '<url>';
14         print "<loc>$siteref/{$article->link}</loc>";
15         $score = 10;
16         if ($article->link) {
17                 $score -= substr_count($article->link, '/') + 1;  # -10% per subdir
18                 $age = time() - strtotime($article->dateiso);
19                 $age /= 3600 * 24 * 365;  # years
20                 if ($age > .1) $score -= $age / 10 + .1;  # -1% per year
21         }
22         printf('<priority>%.2f</priority>', $score / 10);
23         if ($article->last) {
24                 print "<lastmod>{$article->lastiso}</lastmod>";
25         }
26         print "</url>\n";
27 }
28 ?>
29 </urlset>
30 <?php
31 exit;