Table of Contents

Dokuwiki sitemap

Dokuwiki has a sitemap button which is convenient, but not search engine friendly. It also has an Sitemap plugin that creates an XML sitemap for submission to search engines manually. However to automate and make it automatically search engine friendly I created a quick sitemap script. This script also categories by namespace (only one level). Below is the script and I have it as a cron job so I have a nearly current list at all times.

#!/usr/bin/php
<?php
//
// Call from shell by passing output of find command to wiki path
// Example: If wikipath is /www/example.org/somefolder/wiki/data/pages
// MAINWIKIPATH=/www/example.org/somefolder/wiki/data/pages
// Usage: find $MAINWIKIPATH | cut -d"/" -f8-99 | sort | $MAINWIKIPATH/sitemap.php > $MAINWIKIPATH/sitemap.txt
// The sort is important so it can group and title the pages correctly
//
$f = fopen( 'php://stdin', 'r' );
$replaceo = 1;
 
while( $line = fgets( $f ) )
{
    $nocrline = str_replace("\n", "", $line);
    //$fline = preg_replace("/^tech\//", "", $nocrline, $replaceo);
    $fline = $nocrline;
    $pos = strpos($line, '.txt');
    if ($pos === false)
    {
        echo "====== ", ucfirst($fline), " ======" , "\n";
    }
    else
    {
        $lline = preg_replace("/.txt$/", "", $nocrline, $replaceo);
        // This line to replace / with : may not be required if wiki is configured to use clean URLs
        $lline = preg_replace("/\//", ":", $lline);
        echo "  * [[", $lline, "]]", "\n";
    }
}
 
fclose( $f );
?>