Take full path for index file, not just name; change any "hourly" changefreqs to "daily"; add small function for W3C timestamps.

darcs-hash:20080714000833-68ac8-388a8a23336cd08b7e5e5984834aef3d57c3b7bc.gz
This commit is contained in:
Earle Martin 2008-07-13 20:08:33 -04:00
parent a47ab1ad6a
commit 941eb61e82
1 changed files with 25 additions and 20 deletions

View File

@ -32,15 +32,13 @@ function index_map() {
$index_urls .= url( $index_urls .= url(
array( array(
'url' => $output_url . $file_name, 'url' => $output_url . $file_name,
'changefreq' => 'hourly', 'changefreq' => 'daily',
'priority' => '1', 'priority' => '1',
) )
); );
} }
$index_path = $output_dir . $output_paths['index_file']; write_file($output_paths['index_file'], urlset($index_urls));
write_file($index_path, urlset($index_urls));
} }
@ -51,7 +49,7 @@ function standard_map() {
$standard_map_urls .= url( $standard_map_urls .= url(
array( array(
'url' => common_local_url('public'), 'url' => common_local_url('public'),
'changefreq' => 'hourly', 'changefreq' => 'daily',
'priority' => '1', 'priority' => '1',
) )
); );
@ -59,7 +57,7 @@ function standard_map() {
$standard_map_urls .= url( $standard_map_urls .= url(
array( array(
'url' => common_local_url('publicrss'), 'url' => common_local_url('publicrss'),
'changefreq' => 'hourly', 'changefreq' => 'daily',
'priority' => '0.3', 'priority' => '0.3',
) )
); );
@ -102,8 +100,8 @@ function notices_map() {
$notice = array( $notice = array(
'url' => $notices->uri, 'url' => $notices->uri,
'lastmod' => preg_replace('/ /', 'T', $notices->modified), # W3C DTF requires "T" separator 'lastmod' => w3cdate($notices->modified),
'changefreq' => 'hourly', 'changefreq' => 'daily',
'priority' => '1', 'priority' => '1',
); );
@ -140,37 +138,37 @@ function user_map() {
# Define parameters for generating <url></url> elements. # Define parameters for generating <url></url> elements.
$user = array( $user = array(
'url' => common_local_url('showstream', $user_args), 'url' => common_local_url('showstream', $user_args),
'changefreq' => 'hourly', 'changefreq' => 'daily',
'priority' => '1', 'priority' => '1',
); );
$user_rss = array( $user_rss = array(
'url' => common_local_url('userrss', $user_args), 'url' => common_local_url('userrss', $user_args),
'changefreq' => 'hourly', 'changefreq' => 'daily',
'priority' => '0.3', 'priority' => '0.3',
); );
$all = array( $all = array(
'url' => common_local_url('all', $user_args), 'url' => common_local_url('all', $user_args),
'changefreq' => 'hourly', 'changefreq' => 'daily',
'priority' => '1', 'priority' => '1',
); );
$all_rss = array( $all_rss = array(
'url' => common_local_url('allrss', $user_args), 'url' => common_local_url('allrss', $user_args),
'changefreq' => 'hourly', 'changefreq' => 'daily',
'priority' => '0.3', 'priority' => '0.3',
); );
$replies = array( $replies = array(
'url' => common_local_url('replies', $user_args), 'url' => common_local_url('replies', $user_args),
'changefreq' => 'hourly', 'changefreq' => 'daily',
'priority' => '1', 'priority' => '1',
); );
$replies_rss = array( $replies_rss = array(
'url' => common_local_url('repliesrss', $user_args), 'url' => common_local_url('repliesrss', $user_args),
'changefreq' => 'hourly', 'changefreq' => 'daily',
'priority' => '0.3', 'priority' => '0.3',
); );
@ -228,10 +226,10 @@ function avatar_map() {
$avatar_count = 0; $avatar_count = 0;
$map_count++; $map_count++;
} }
w3cdate($avatars->modified);
$image = array( $image = array(
'url' => $avatars->url, 'url' => $avatars->url,
'lastmod' => preg_replace('/ /', 'T', $avatars->modified), # W3C DTF requires "T" separator 'lastmod' => w3cdate($avatars->modified),
'changefreq' => 'monthly', 'changefreq' => 'monthly',
'priority' => '0.2', 'priority' => '0.2',
); );
@ -281,9 +279,9 @@ function url($url_args) {
# Generate a <urlset></urlset> element. # Generate a <urlset></urlset> element.
function urlset($urlset_text) { function urlset($urlset_text) {
$urlset = '<?xml version="1.0" encoding="UTF-8"?>'. $urlset = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'. '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n" .
$urlset_text. $urlset_text .
'</urlset>'; '</urlset>';
return $urlset; return $urlset;
@ -310,7 +308,7 @@ function parse_args() {
$args = getopt('f:d:u:'); $args = getopt('f:d:u:');
if (is_null($args[f]) && is_null($args[d]) && is_null($args[u])) { if (is_null($args[f]) && is_null($args[d]) && is_null($args[u])) {
error('Mandatory arguments: -f <index file name> -d <output directory> -u <URL of sitemaps directory>'); error('Mandatory arguments: -f <index file path> -d <output directory path> -u <URL of sitemaps directory>');
} }
if (is_null($args[f])) { if (is_null($args[f])) {
@ -346,6 +344,13 @@ function parse_args() {
return $paths; return $paths;
} }
# Format database timestamps as W3C DTF.
function w3cdate ($timestamp) {
preg_match('/(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/', $timestamp, $date);
return date(DATE_W3C, mktime($date[4], $date[5], $date[6], $date[2], $date[3], $date[1]));
}
# Ensure paths end with a "/". # Ensure paths end with a "/".
function trailing_slash($path) { function trailing_slash($path) {
if (preg_match('/\/$/', $path) == 0) { if (preg_match('/\/$/', $path) == 0) {