diff --git a/src/Baun.php b/src/Baun.php index e49d4d2..9585dd1 100644 --- a/src/Baun.php +++ b/src/Baun.php @@ -407,12 +407,31 @@ protected function filesToPosts($files) foreach ($posts as $post) { $route = str_replace($this->config->get('app.content_extension'), '', $post['nice']); $routeBase = basename($blogBase); + if (preg_match('/^\d+\-/', $blogBase)) { list($index, $path) = explode('-', $blogBase, 2); $routeBase = $path; } $data = $this->getFileData($blogBase . '/' . $post['raw']); + + $published = date($this->config->get('blog.date_format')); + if (preg_match('/^\d+\-/', $post['raw'])) { + list($time, $path) = explode('-', $post['raw'], 2); + $published = date($this->config->get('blog.date_format'), strtotime($time)); + if ($this->config->get('blog.date_in_url')) { + $route = $time . '/' . $route; + } + } + if (isset($data['info']['published'])) { + $published = date($this->config->get('blog.date_format'), strtotime($data['info']['published'])); + } + + // Exclude posts published in the future + if (strtotime($published) > strtotime('now')) { + continue; + } + $title = isset($data['info']['title']) ? $data['info']['title'] : ''; if (!$title) { $title = ucwords(str_replace(['-', '_'], ' ', basename($route))); @@ -425,17 +444,6 @@ protected function filesToPosts($files) $excerpt = implode(' ', array_slice($words, 0, $this->config->get('blog.excerpt_words'))) . '...'; } } - $published = date($this->config->get('blog.date_format')); - if (preg_match('/^\d+\-/', $post['raw'])) { - list($time, $path) = explode('-', $post['raw'], 2); - $published = date($this->config->get('blog.date_format'), strtotime($time)); - if ($this->config->get('blog.date_in_url')) { - $route = $time . '/' . $route; - } - } - if (isset($data['info']['published'])) { - $published = date($this->config->get('blog.date_format'), strtotime($data['info']['published'])); - } $result[] = [ 'route' => $routeBase . '/' . $route,