@@ -14,50 +14,50 @@ |
||
| 14 | 14 | * @return boolean |
| 15 | 15 | */ |
| 16 | 16 | function buildSitemap(array $entries, $domain, $folder) { |
| 17 | - $urlSet = new Urlset(); |
|
| 18 | - foreach ($entries as $path => $entry) { |
|
| 19 | - $url = new Url("{$domain}{$path}"); // todo better detection of domain by env |
|
| 20 | - $url->setLastMod($entry['lastmod']); // todo check if exists |
|
| 21 | - $url->setChangeFreq($entry['changefreq']); // todo check if exists |
|
| 22 | - $url->setPriority($entry['priority']); // todo check if exists |
|
| 23 | - $urlSet->addUrl($url); |
|
| 24 | - } |
|
| 25 | - |
|
| 26 | - $output = new Output(); |
|
| 27 | - $output->setIndentString(' '); // change indentation from 4 to 2 spaces |
|
| 28 | - |
|
| 29 | - $tempSitemap = __DIR__ . "/../../public/{$folder}/sitemap-new.xml"; |
|
| 30 | - $finalSitemap = __DIR__ . "/../../public/{$folder}/sitemap.xml"; |
|
| 31 | - |
|
| 32 | - $sitemapHandle = fopen($tempSitemap, 'w'); |
|
| 33 | - fwrite($sitemapHandle, $output->getOutput($urlSet)); |
|
| 34 | - fclose($sitemapHandle); |
|
| 35 | - |
|
| 36 | - rename($tempSitemap, $finalSitemap); |
|
| 17 | + $urlSet = new Urlset(); |
|
| 18 | + foreach ($entries as $path => $entry) { |
|
| 19 | + $url = new Url("{$domain}{$path}"); // todo better detection of domain by env |
|
| 20 | + $url->setLastMod($entry['lastmod']); // todo check if exists |
|
| 21 | + $url->setChangeFreq($entry['changefreq']); // todo check if exists |
|
| 22 | + $url->setPriority($entry['priority']); // todo check if exists |
|
| 23 | + $urlSet->addUrl($url); |
|
| 24 | + } |
|
| 25 | + |
|
| 26 | + $output = new Output(); |
|
| 27 | + $output->setIndentString(' '); // change indentation from 4 to 2 spaces |
|
| 28 | + |
|
| 29 | + $tempSitemap = __DIR__ . "/../../public/{$folder}/sitemap-new.xml"; |
|
| 30 | + $finalSitemap = __DIR__ . "/../../public/{$folder}/sitemap.xml"; |
|
| 31 | + |
|
| 32 | + $sitemapHandle = fopen($tempSitemap, 'w'); |
|
| 33 | + fwrite($sitemapHandle, $output->getOutput($urlSet)); |
|
| 34 | + fclose($sitemapHandle); |
|
| 35 | + |
|
| 36 | + rename($tempSitemap, $finalSitemap); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | // site.jacobemerick.com |
| 40 | 40 | $entryArray = [ |
| 41 | - '/' => [ |
|
| 42 | - 'lastmod' => (new DateTime('December 20, 2015'))->format('Y-m-d'), |
|
| 43 | - 'changefreq' => 'weekly', |
|
| 44 | - 'priority' => 1, |
|
| 45 | - ], |
|
| 46 | - '/terms/' => [ |
|
| 47 | - 'lastmod' => (new DateTime('December 20, 2015'))->format('Y-m-d'), |
|
| 48 | - 'changefreq' => 'weekly', |
|
| 49 | - 'priority' => .3, |
|
| 50 | - ], |
|
| 51 | - '/change-log/' => [ |
|
| 52 | - 'lastmod' => (new DateTime('now'))->format('Y-m-d'), // todo lookup based on changelog |
|
| 53 | - 'changefreq' => 'daily', |
|
| 54 | - 'priority' => .1, |
|
| 55 | - ], |
|
| 56 | - '/contact/' => [ |
|
| 57 | - 'lastmod' => (new DateTime('December 20, 2015'))->format('Y-m-d'), |
|
| 58 | - 'changefreq' => 'weekly', |
|
| 59 | - 'priority' => .6, |
|
| 60 | - ], |
|
| 41 | + '/' => [ |
|
| 42 | + 'lastmod' => (new DateTime('December 20, 2015'))->format('Y-m-d'), |
|
| 43 | + 'changefreq' => 'weekly', |
|
| 44 | + 'priority' => 1, |
|
| 45 | + ], |
|
| 46 | + '/terms/' => [ |
|
| 47 | + 'lastmod' => (new DateTime('December 20, 2015'))->format('Y-m-d'), |
|
| 48 | + 'changefreq' => 'weekly', |
|
| 49 | + 'priority' => .3, |
|
| 50 | + ], |
|
| 51 | + '/change-log/' => [ |
|
| 52 | + 'lastmod' => (new DateTime('now'))->format('Y-m-d'), // todo lookup based on changelog |
|
| 53 | + 'changefreq' => 'daily', |
|
| 54 | + 'priority' => .1, |
|
| 55 | + ], |
|
| 56 | + '/contact/' => [ |
|
| 57 | + 'lastmod' => (new DateTime('December 20, 2015'))->format('Y-m-d'), |
|
| 58 | + 'changefreq' => 'weekly', |
|
| 59 | + 'priority' => .6, |
|
| 60 | + ], |
|
| 61 | 61 | ]; |
| 62 | 62 | |
| 63 | 63 | buildSitemap($entryArray, 'http://site.jacobemerick.com', 'site'); |