Beispiel #1
0
 public function write_archive($posts)
 {
     $template = Updater::$archive_page_template;
     $t = new Template($template);
     $t->content = array('post-title' => 'Archive', 'post-type' => 'archive', 'page-type' => 'archive', 'page-title' => 'Archive', 'blog-title' => html_entity_decode(SmartyPants(self::$blog_title), ENT_QUOTES, 'UTF-8'));
     foreach ($posts as $post) {
         $t->content['posts'][] = array('title' => html_entity_decode(SmartyPants($post->title), ENT_QUOTES, 'UTF-8'), 'timestamp' => $post->timestamp, 'uri' => '/' . $post->year . '/' . str_pad($post->month, 2, '0', STR_PAD_LEFT) . '/' . $post->slug, 'tags' => $post->tags);
         $output_html = $t->outputHTML();
     }
     if (!file_exists(Updater::$dest_path)) {
         mkdir_as_parent_owner(Updater::$dest_path, 0755, true);
     }
     file_put_contents_as_dir_owner(Updater::$dest_path . '/archive.html', $output_html);
 }
Beispiel #2
0
 public function write_index_sequence($dest_path, $title, $type, array $posts, $template = 'main.html', $archive_array = false, $posts_per_page = 20)
 {
     $sequence = 0;
     $new_dest_path = $dest_path;
     // $dest_uri = substring_after(substring_before($dest_path, '.', true), Updater::$dest_path);
     $dest_uri = substring_after(substring_after($dest_path, '/', true), Updater::$dest_path);
     $total_sequences = ceil(count($posts) / $posts_per_page);
     while ($posts) {
         $sequence++;
         $seq_array = array_splice($posts, 0, $posts_per_page);
         if ($sequence == 1) {
             continue;
         }
         // skip writing the redundant "-1" page
         $new_dest_path = $dest_path . '-' . $sequence . '.html';
         $posts_data = array();
         foreach ($seq_array as $p) {
             $posts_data[] = $p->array_for_template();
         }
         $t = new Template($template);
         $t->content = array('page-title' => html_entity_decode(SmartyPants($title), ENT_QUOTES, 'UTF-8'), 'blog-title' => html_entity_decode(SmartyPants(self::$blog_title), ENT_QUOTES, 'UTF-8'), 'blog-url' => self::$blog_url, 'blog-description' => html_entity_decode(SmartyPants(self::$blog_description), ENT_QUOTES, 'UTF-8'), 'page-type' => $type, 'posts' => $posts_data, 'previous_page_url' => $sequence != 1 ? $sequence == 2 ? $dest_uri : $dest_uri . '-' . ($sequence - 1) : false, 'next_page_url' => $sequence < $total_sequences ? $dest_uri . '-' . ($sequence + 1) : false, 'archives' => $archive_array ? $archive_array : array());
         $output_html = $t->outputHTML();
         $output_path = dirname($new_dest_path);
         if (!file_exists($output_path)) {
             mkdir_as_parent_owner($output_path, 0755, true);
         }
         file_put_contents_as_dir_owner($new_dest_path, $output_html);
     }
     return $total_sequences;
 }
Beispiel #3
0
 public static function update_drafts()
 {
     foreach (self::changed_files_in_directory(self::$source_path . '/drafts') as $filename => $info) {
         self::$changes_were_written = true;
         if (contains($filename, '/_publish-now/') && file_exists($filename)) {
             $post = new Post($filename, false);
             $expected_fname = $post->expected_source_filename(true);
             error_log("Publishing draft {$filename}");
             $dir = dirname($expected_fname);
             if (!file_exists($dir)) {
                 mkdir_as_parent_owner($dir, 0755, true);
             }
             if (file_put_contents_as_dir_owner($expected_fname, $post->normalized_source())) {
                 safe_unlink($filename);
             }
             self::post_hooks($post);
         }
         if (!file_exists($filename)) {
             if (ends_with($filename, self::$post_extension)) {
                 error_log("Deleted draft {$filename}");
                 $slug = substring_before(basename($filename), '.', true);
                 $html_preview_filename = self::$source_path . '/drafts/_previews/' . $slug . '.html';
                 $webroot_preview_filename = self::$dest_path . '/drafts/' . $slug;
                 if (file_exists($html_preview_filename)) {
                     safe_unlink($html_preview_filename);
                 }
                 if (file_exists($webroot_preview_filename)) {
                     safe_unlink($webroot_preview_filename);
                 }
             }
             continue;
         }
         if (substr($filename, -strlen(self::$post_extension)) == self::$post_extension) {
             $post = new Post($filename, true);
             if ($post->publish_now) {
                 $post = new Post($filename, false);
                 $expected_fname = $post->expected_source_filename(true);
                 error_log("Publishing draft {$filename}");
                 $dir = dirname($expected_fname);
                 if (!file_exists($dir)) {
                     mkdir_as_parent_owner($dir, 0755, true);
                 }
                 if (file_put_contents_as_dir_owner($expected_fname, $post->normalized_source())) {
                     safe_unlink($filename);
                 }
                 self::post_hooks($post);
             } else {
                 $post->write_permalink_page(true);
             }
         }
     }
 }