From c4804c604c62dd07360c958c1c7e3930cfdb0d23 Mon Sep 17 00:00:00 2001 From: Lester Caine Date: Thu, 21 May 2026 10:17:34 +0100 Subject: Tidy automatic generation of sitemap --- sitemap.php | 68 ++++++++++++++++--------------------------------------------- 1 file changed, 18 insertions(+), 50 deletions(-) diff --git a/sitemap.php b/sitemap.php index 3a1f189..89f0940 100755 --- a/sitemap.php +++ b/sitemap.php @@ -1,65 +1,33 @@ -1, 'sort_mode' => 'last_modified_desc' ]; -$listHash = []; - -if( $bookList = $book->getList( $listHash ) ) { - foreach( $bookList['data'] as $bookHash ) { - $bookStructure = new LibertyStructure( $bookHash['structure_id'] ); - if( $rootObject = LibertyContent::getLibertyObject( $bookStructure->getField( 'content_id' ), $bookStructure->getField( 'content_type_guid' ) ) ) { - if( $rootObject->isPublic() ) { - $listBook = $bookStructure->buildTreeToc( $bookHash['structure_id'] ); - process_book_list( $listBook ); - } - } - } -} - -function process_book_list( $pList, $pDepth = 1 ) { - global $gSiteMapHash; - foreach( array_keys( $pList ) as $key ) { - if( !empty( $pList[$key]['display_url'] ) ) { - $hash = []; - $hash['loc'] = BIT_BASE_URI.$pList[$key]['display_url']; - $hash['lastmod'] = date( 'Y-m-d', $pList[$key]['last_modified'] ); - if( (time() - $pList[$key]['last_modified']) < 86400 ) { - $freq = 'daily'; - } elseif( (time() - $pList[$key]['last_modified']) < (86400 * 7) ) { - $freq = 'weekly'; - } else { - $freq = 'monthly'; - } - - $hash['changefreq'] = $freq; - $hash['priority'] = 1 - round( $pDepth * .5 ) * .1; - $gSiteMapHash[$pList[$key]['content_id']] = $hash; - } - if( !empty( $pList[$key]['sub'] ) ) { - process_book_list( $pList[$key]['sub'], $pDepth + 1 ); - } +if( $pageList = $page->getList( $listHash ) ) { + foreach( $pageList as $row ) { + if( empty( $row['display_url'] ) ) continue; + $age = time() - $row['last_modified']; + if( $age < 86400 ) $freq = 'daily'; + elseif( $age < 86400 * 7 ) $freq = 'weekly'; + else $freq = 'monthly'; + $gSiteMapHash[$row['content_id']] = [ + 'loc' => BIT_BASE_URI . $row['display_url'], + 'lastmod' => date( 'Y-m-d', $row['last_modified'] ), + 'changefreq' => $freq, + 'priority' => 0.8, + ]; } } $gBitSmarty->assign( 'gSiteMapHash', $gSiteMapHash ); $gBitThemes->setFormatHeader( 'xml' ); -print $gBitSmarty->display( 'bitpackage:kernel/sitemap.tpl' ); +header( 'Content-Type: application/xml; charset=utf-8' ); +$gBitSystem->display( 'bitpackage:kernel/sitemap.tpl' ); -- cgit v1.3