protected function generate($language)
 {
     $xml = public_path() . "/{$language}/rss.xml";
     $feed = Feed::make();
     $feed->setDateFormat('datetime');
     $feed->setShortening(false);
     $feed->title = trans('meta.blog.title', [], 'messages', $language);
     $feed->description = trans('meta.blog.description', [], 'messages', $language);
     $feed->logo = url('img/cover.png');
     $feed->link = url("{$language}/rss.xml");
     $feed->pubdate = (new DateTime())->format(DateTime::ATOM);
     $feed->lang = $language;
     $loader = new PostLoader($language);
     $posts = $loader->loadList();
     uasort($posts, function ($a, $b) {
         return $a['published'] > $b['published'] ? -1 : 1;
     });
     $posts = array_slice($posts, 0, 10);
     foreach ($posts as $post) {
         $post = $loader->load($post['slug'], $post);
         $feed->addArray(['title' => $post['title'], 'author' => '*****@*****.**', 'link' => route('post', $post['slug']), 'pubdate' => $post['published']->format(DateTime::ATOM), 'description' => $post['intro'], 'content' => $post['content']]);
     }
     file_put_contents($xml, $feed->render('rss', -1));
     $this->info("RSS feed for site language {$language} was generated and saved to {$xml}");
 }
 public function warmup($language)
 {
     $loader = new PostLoader($language);
     $posts = $loader->loadList();
     if (!count($posts)) {
         $this->error("Could not load posts for language {$language}");
         return;
     }
     $this->info("List of posts on '{$language}' was loaded...");
     foreach ($posts as $post) {
         $loader->load($post['slug'], $post);
         $this->info("Was loaded post with slug {$post['slug']} for language {$language}");
     }
     (new Tag())->all();
     $this->info("Tags for posts for '{$language}' was loaded...");
 }
Exemple #3
0
 public function latest($latest = 4)
 {
     $posts = PostLoader::convert(Redis::zrevrange(Key::posts(), 0, $latest - 1, 'WITHSCORES'));
     foreach ($posts as $slug => &$post) {
         $post = $this->loader->load($slug);
     }
     return $posts;
 }
 protected function generate($language)
 {
     $directory = public_path() . "/{$language}";
     if (!file_exists($directory)) {
         $this->fs->makeDirectory($directory);
     }
     $xml = $directory . "/sitemap.xml";
     $sitemap = new Sitemap($xml);
     $sitemap->addItem(url('/'), time(), Sitemap::DAILY);
     $sitemap->addItem(url('about'), time(), Sitemap::MONTHLY);
     $sitemap->addItem(url('ambassador'), time(), Sitemap::MONTHLY);
     $sitemap->addItem(route('blog'), time(), Sitemap::DAILY);
     $loader = new PostLoader($language);
     $posts = $loader->loadList();
     foreach ($posts as $post) {
         $sitemap->addItem(route('post', $post['slug']), time(), Sitemap::DAILY);
     }
     $tags = (new Tag($language))->all(1000);
     foreach ($tags as $tag => $count) {
         $sitemap->addItem(route('tag', $tag), time(), Sitemap::DAILY);
     }
     $sitemap->write();
     $this->info("Sitemap for site language {$language} was generated and saved to {$xml}");
 }