@@ -17,26 +17,26 @@ discard block |
||
17 | 17 | * @return boolean |
18 | 18 | */ |
19 | 19 | $buildSitemap = function (array $entries, $domain, $folder) { |
20 | - $urlSet = new Urlset(); |
|
21 | - foreach ($entries as $path => $entry) { |
|
22 | - $url = new Url("{$domain}{$path}"); // todo better detection of domain by env |
|
23 | - $url->setLastMod($entry['lastmod']); // todo check if exists |
|
24 | - $url->setChangeFreq($entry['changefreq']); // todo check if exists |
|
25 | - $url->setPriority($entry['priority']); // todo check if exists |
|
26 | - $urlSet->addUrl($url); |
|
27 | - } |
|
28 | - |
|
29 | - $output = new Output(); |
|
30 | - $output->setIndentString(' '); // change indentation from 4 to 2 spaces |
|
31 | - |
|
32 | - $tempSitemap = __DIR__ . "/../../public/{$folder}/sitemap-new.xml"; |
|
33 | - $finalSitemap = __DIR__ . "/../../public/{$folder}/sitemap.xml"; |
|
34 | - |
|
35 | - $sitemapHandle = fopen($tempSitemap, 'w'); |
|
36 | - fwrite($sitemapHandle, $output->getOutput($urlSet)); |
|
37 | - fclose($sitemapHandle); |
|
38 | - |
|
39 | - rename($tempSitemap, $finalSitemap); |
|
20 | + $urlSet = new Urlset(); |
|
21 | + foreach ($entries as $path => $entry) { |
|
22 | + $url = new Url("{$domain}{$path}"); // todo better detection of domain by env |
|
23 | + $url->setLastMod($entry['lastmod']); // todo check if exists |
|
24 | + $url->setChangeFreq($entry['changefreq']); // todo check if exists |
|
25 | + $url->setPriority($entry['priority']); // todo check if exists |
|
26 | + $urlSet->addUrl($url); |
|
27 | + } |
|
28 | + |
|
29 | + $output = new Output(); |
|
30 | + $output->setIndentString(' '); // change indentation from 4 to 2 spaces |
|
31 | + |
|
32 | + $tempSitemap = __DIR__ . "/../../public/{$folder}/sitemap-new.xml"; |
|
33 | + $finalSitemap = __DIR__ . "/../../public/{$folder}/sitemap.xml"; |
|
34 | + |
|
35 | + $sitemapHandle = fopen($tempSitemap, 'w'); |
|
36 | + fwrite($sitemapHandle, $output->getOutput($urlSet)); |
|
37 | + fclose($sitemapHandle); |
|
38 | + |
|
39 | + rename($tempSitemap, $finalSitemap); |
|
40 | 40 | }; |
41 | 41 | |
42 | 42 | |
@@ -44,12 +44,12 @@ discard block |
||
44 | 44 | * blog.jacobemerick.com |
45 | 45 | *********************************************/ |
46 | 46 | $reduceToMostRecentBlogPost = function ($recentPost, $post) { |
47 | - if (is_null($recentPost)) { |
|
48 | - return $post; |
|
49 | - } |
|
50 | - $postDate = new DateTime($post['date']); |
|
51 | - $recentPostDate = new DateTime($recentPost['date']); |
|
52 | - return ($postDate > $recentPostDate) ? $post: $recentPost; |
|
47 | + if (is_null($recentPost)) { |
|
48 | + return $post; |
|
49 | + } |
|
50 | + $postDate = new DateTime($post['date']); |
|
51 | + $recentPostDate = new DateTime($recentPost['date']); |
|
52 | + return ($postDate > $recentPostDate) ? $post: $recentPost; |
|
53 | 53 | }; |
54 | 54 | |
55 | 55 | $blogPostsPerPage = 10; |
@@ -60,107 +60,107 @@ discard block |
||
60 | 60 | |
61 | 61 | // todo these post-level dates should be accurate to H:i:s |
62 | 62 | $entryArray = [ |
63 | - '/' => [ |
|
64 | - 'lastmod' => (new DateTime($mostRecentBlogPost['date']))->format('Y-m-d'), |
|
65 | - 'changefreq' => 'daily', |
|
66 | - 'priority' => .9, |
|
67 | - ] |
|
63 | + '/' => [ |
|
64 | + 'lastmod' => (new DateTime($mostRecentBlogPost['date']))->format('Y-m-d'), |
|
65 | + 'changefreq' => 'daily', |
|
66 | + 'priority' => .9, |
|
67 | + ] |
|
68 | 68 | ]; |
69 | 69 | for ($i = 2; (($i - 1) * $blogPostsPerPage) < count($activeBlogPosts); $i++) { |
70 | - $entryKey = "/{$i}/"; |
|
71 | - $entryArray += [ |
|
72 | - $entryKey => [ |
|
73 | - 'lastmod' => (new DateTime($mostRecentBlogPost['date']))->format('Y-m-d'), |
|
74 | - 'changefreq' => 'daily', |
|
75 | - 'priority' => .1, |
|
76 | - ] |
|
77 | - ]; |
|
70 | + $entryKey = "/{$i}/"; |
|
71 | + $entryArray += [ |
|
72 | + $entryKey => [ |
|
73 | + 'lastmod' => (new DateTime($mostRecentBlogPost['date']))->format('Y-m-d'), |
|
74 | + 'changefreq' => 'daily', |
|
75 | + 'priority' => .1, |
|
76 | + ] |
|
77 | + ]; |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | $blogCategoryArray = [ |
81 | - 'hiking', |
|
82 | - 'personal', |
|
83 | - 'web-development', |
|
81 | + 'hiking', |
|
82 | + 'personal', |
|
83 | + 'web-development', |
|
84 | 84 | ]; |
85 | 85 | |
86 | 86 | foreach ($blogCategoryArray as $blogCategory) { |
87 | - $blogCategoryPosts = array_filter($activeBlogPosts, function ($post) use ($blogCategory) { |
|
88 | - return $post['category'] == $blogCategory; |
|
89 | - }); |
|
90 | - $mostRecentBlogCategoryPost = array_reduce($blogCategoryPosts, $reduceToMostRecentBlogPost); |
|
91 | - |
|
92 | - $entryKey = "/{$blogCategory}/"; |
|
93 | - $entryArray += [ |
|
94 | - $entryKey => [ |
|
95 | - 'lastmod' => (new DateTime($mostRecentBlogCategoryPost['date']))->format('Y-m-d'), |
|
96 | - 'changefreq' => 'daily', |
|
97 | - 'priority' => .3, |
|
98 | - ] |
|
99 | - ]; |
|
100 | - |
|
101 | - for ($i = 2; (($i - 1) * $blogPostsPerPage) < count($blogCategoryPosts); $i++) { |
|
102 | - $entryKey = "/{$blogCategory}/{$i}/"; |
|
103 | - $entryArray += [ |
|
104 | - $entryKey => [ |
|
105 | - 'lastmod' => (new DateTime($mostRecentBlogCategoryPost['date']))->format('Y-m-d'), |
|
106 | - 'changefreq' => 'daily', |
|
107 | - 'priority' => .1, |
|
108 | - ] |
|
109 | - ]; |
|
110 | - } |
|
87 | + $blogCategoryPosts = array_filter($activeBlogPosts, function ($post) use ($blogCategory) { |
|
88 | + return $post['category'] == $blogCategory; |
|
89 | + }); |
|
90 | + $mostRecentBlogCategoryPost = array_reduce($blogCategoryPosts, $reduceToMostRecentBlogPost); |
|
91 | + |
|
92 | + $entryKey = "/{$blogCategory}/"; |
|
93 | + $entryArray += [ |
|
94 | + $entryKey => [ |
|
95 | + 'lastmod' => (new DateTime($mostRecentBlogCategoryPost['date']))->format('Y-m-d'), |
|
96 | + 'changefreq' => 'daily', |
|
97 | + 'priority' => .3, |
|
98 | + ] |
|
99 | + ]; |
|
100 | + |
|
101 | + for ($i = 2; (($i - 1) * $blogPostsPerPage) < count($blogCategoryPosts); $i++) { |
|
102 | + $entryKey = "/{$blogCategory}/{$i}/"; |
|
103 | + $entryArray += [ |
|
104 | + $entryKey => [ |
|
105 | + 'lastmod' => (new DateTime($mostRecentBlogCategoryPost['date']))->format('Y-m-d'), |
|
106 | + 'changefreq' => 'daily', |
|
107 | + 'priority' => .1, |
|
108 | + ] |
|
109 | + ]; |
|
110 | + } |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | $blogTagRepository = new BlogTagRepository($container['db_connection_locator']); |
114 | 114 | $blogTags = $blogTagRepository->getAllTags(); |
115 | 115 | foreach ($blogTags as $blogTag) { |
116 | - $blogPostsWithTag = $blogPostRepository->getActivePostsByTag($blogTag['id']); |
|
117 | - if (count($blogPostsWithTag) < 1) { |
|
118 | - continue; |
|
119 | - } |
|
120 | - |
|
121 | - $mostRecentBlogTagPost = array_reduce($blogPostsWithTag, $reduceToMostRecentBlogPost); |
|
122 | - |
|
123 | - $blogTagPath = str_replace(' ', '-', $blogTag['tag']); |
|
124 | - $entryKey = "/tag/{$blogTagPath}/"; |
|
125 | - $entryArray += [ |
|
126 | - $entryKey => [ |
|
127 | - 'lastmod' => (new DateTime($mostRecentBlogTagPost['date']))->format('Y-m-d'), |
|
128 | - 'changefreq' => 'daily', |
|
129 | - 'priority' => .1, |
|
130 | - ] |
|
131 | - ]; |
|
132 | - |
|
133 | - for ($i = 2; (($i - 1) * $blogPostsPerPage) < count($blogPostsWithTag); $i++) { |
|
134 | - $blogTagPath = str_replace(' ', '-', $blogTag['tag']); |
|
135 | - $entryKey = "/tag/{$blogTagPath}/{$i}/"; |
|
136 | - $entryArray += [ |
|
137 | - $entryKey => [ |
|
138 | - 'lastmod' => (new DateTime($mostRecentBlogTagPost['date']))->format('Y-m-d'), |
|
139 | - 'changefreq' => 'daily', |
|
140 | - 'priority' => .1, |
|
141 | - ] |
|
142 | - ]; |
|
143 | - } |
|
116 | + $blogPostsWithTag = $blogPostRepository->getActivePostsByTag($blogTag['id']); |
|
117 | + if (count($blogPostsWithTag) < 1) { |
|
118 | + continue; |
|
119 | + } |
|
120 | + |
|
121 | + $mostRecentBlogTagPost = array_reduce($blogPostsWithTag, $reduceToMostRecentBlogPost); |
|
122 | + |
|
123 | + $blogTagPath = str_replace(' ', '-', $blogTag['tag']); |
|
124 | + $entryKey = "/tag/{$blogTagPath}/"; |
|
125 | + $entryArray += [ |
|
126 | + $entryKey => [ |
|
127 | + 'lastmod' => (new DateTime($mostRecentBlogTagPost['date']))->format('Y-m-d'), |
|
128 | + 'changefreq' => 'daily', |
|
129 | + 'priority' => .1, |
|
130 | + ] |
|
131 | + ]; |
|
132 | + |
|
133 | + for ($i = 2; (($i - 1) * $blogPostsPerPage) < count($blogPostsWithTag); $i++) { |
|
134 | + $blogTagPath = str_replace(' ', '-', $blogTag['tag']); |
|
135 | + $entryKey = "/tag/{$blogTagPath}/{$i}/"; |
|
136 | + $entryArray += [ |
|
137 | + $entryKey => [ |
|
138 | + 'lastmod' => (new DateTime($mostRecentBlogTagPost['date']))->format('Y-m-d'), |
|
139 | + 'changefreq' => 'daily', |
|
140 | + 'priority' => .1, |
|
141 | + ] |
|
142 | + ]; |
|
143 | + } |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | $reversedBlogPosts = array_reverse($activeBlogPosts); |
147 | 147 | foreach ($reversedBlogPosts as $blogPost) { |
148 | - $entryKey = "/{$blogPost['category']}/{$blogPost['path']}/"; |
|
149 | - $entryArray += [ |
|
150 | - $entryKey => [ |
|
151 | - 'lastmod' => (new DateTime($blogPost['date']))->format('Y-m-d'), // todo this should be based on comment |
|
152 | - 'changefreq' => 'weekly', |
|
153 | - 'priority' => .8, |
|
154 | - ], |
|
155 | - ]; |
|
148 | + $entryKey = "/{$blogPost['category']}/{$blogPost['path']}/"; |
|
149 | + $entryArray += [ |
|
150 | + $entryKey => [ |
|
151 | + 'lastmod' => (new DateTime($blogPost['date']))->format('Y-m-d'), // todo this should be based on comment |
|
152 | + 'changefreq' => 'weekly', |
|
153 | + 'priority' => .8, |
|
154 | + ], |
|
155 | + ]; |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | $entryArray += [ |
159 | - '/about/' => [ |
|
160 | - 'lastmod' => (new DateTime('December 20, 2015'))->format('Y-m-d'), |
|
161 | - 'changefreq' => 'monthly', |
|
162 | - 'priority' => .2, |
|
163 | - ] |
|
159 | + '/about/' => [ |
|
160 | + 'lastmod' => (new DateTime('December 20, 2015'))->format('Y-m-d'), |
|
161 | + 'changefreq' => 'monthly', |
|
162 | + 'priority' => .2, |
|
163 | + ] |
|
164 | 164 | ]; |
165 | 165 | |
166 | 166 | $buildSitemap($entryArray, 'http://blog.jacobemerick.com', 'blog'); |
@@ -170,26 +170,26 @@ discard block |
||
170 | 170 | * site.jacobemerick.com |
171 | 171 | *********************************************/ |
172 | 172 | $entryArray = [ |
173 | - '/' => [ |
|
174 | - 'lastmod' => (new DateTime('December 20, 2015'))->format('Y-m-d'), |
|
175 | - 'changefreq' => 'weekly', |
|
176 | - 'priority' => 1, |
|
177 | - ], |
|
178 | - '/terms/' => [ |
|
179 | - 'lastmod' => (new DateTime('December 20, 2015'))->format('Y-m-d'), |
|
180 | - 'changefreq' => 'weekly', |
|
181 | - 'priority' => .3, |
|
182 | - ], |
|
183 | - '/change-log/' => [ |
|
184 | - 'lastmod' => (new DateTime('now'))->format('Y-m-d'), // todo lookup based on changelog |
|
185 | - 'changefreq' => 'daily', |
|
186 | - 'priority' => .1, |
|
187 | - ], |
|
188 | - '/contact/' => [ |
|
189 | - 'lastmod' => (new DateTime('December 20, 2015'))->format('Y-m-d'), |
|
190 | - 'changefreq' => 'weekly', |
|
191 | - 'priority' => .6, |
|
192 | - ], |
|
173 | + '/' => [ |
|
174 | + 'lastmod' => (new DateTime('December 20, 2015'))->format('Y-m-d'), |
|
175 | + 'changefreq' => 'weekly', |
|
176 | + 'priority' => 1, |
|
177 | + ], |
|
178 | + '/terms/' => [ |
|
179 | + 'lastmod' => (new DateTime('December 20, 2015'))->format('Y-m-d'), |
|
180 | + 'changefreq' => 'weekly', |
|
181 | + 'priority' => .3, |
|
182 | + ], |
|
183 | + '/change-log/' => [ |
|
184 | + 'lastmod' => (new DateTime('now'))->format('Y-m-d'), // todo lookup based on changelog |
|
185 | + 'changefreq' => 'daily', |
|
186 | + 'priority' => .1, |
|
187 | + ], |
|
188 | + '/contact/' => [ |
|
189 | + 'lastmod' => (new DateTime('December 20, 2015'))->format('Y-m-d'), |
|
190 | + 'changefreq' => 'weekly', |
|
191 | + 'priority' => .6, |
|
192 | + ], |
|
193 | 193 | ]; |
194 | 194 | |
195 | 195 | $buildSitemap($entryArray, 'http://site.jacobemerick.com', 'site'); |