mkdir($directory , 0777, true); // FIXME, permissions...
}
}
+
+ return $content_items;
}
function garden_move_raw($content_items) {
foreach ($content_items as $item) {
- if ($item->type != GardenItemType::Raw && $item->type != GardenItemType::Image) {
+ if ($item->type != GardenItemType::Raw && $item->type != GardenItemType::Image) { // FIXME, do we need to copy images?
continue;
}
error('Failed to copy file: filename="', $item->source_filename, '"');
}
}
+
+ return $content_items;
}
///////////////////////////////////////////////////////////////////////////////
return $output;
}
+///////////////////////////////////////////////////////////////////////////////
+// Images
+///////////////////////////////////////////////////////////////////////////////
+
+class GardenImage {
+ public $content_item;
+ public $width;
+ public $height;
+ public $url;
+ public $target_filename;
+
+ public function __construct($content_item, $width, $height, $url, $target_filename) {
+ $this->content_item = $content_item;
+ $this->width = $width;
+ $this->height = $height;
+ $this->url = $url;
+ $this->target_filename = $target_filename;
+ }
+}
+
+function garden_make_images($post_process_items) {
+ foreach ($post_process_items as $item) {
+ $image = new Imagick($item->content_item->source_filename);
+ $image->thumbnailImage($item->width, $item->height);
+ $image->writeImage($item->target_filename);
+ }
+}
+
///////////////////////////////////////////////////////////////////////////////
// Template helpers
///////////////////////////////////////////////////////////////////////////////
return $garden_template_content();
}
+function garden_site_url(...$url_segments) {
+ return GARDEN_SITE_BASE_URL . garden_url(...$url_segments);
+}
+
///////////////////////////////////////////////////////////////////////////////
// HTML
///////////////////////////////////////////////////////////////////////////////
require_once(garden_path(__DIR__, 'third_party', 'parsedown', 'Parsedown.php'));
class GardenExtendedParsedown extends Parsedown {
+ public $post_process_items;
+ private $output_directory;
private $content_items;
- public function __construct($content_items) {
+ public function __construct($output_directory, $content_items) {
+ $this->post_process_items = [];
+ $this->output_directory = $output_directory;
$this->content_items = $content_items;
$this->InlineTypes['!'][] = 'Youtube';
$this->InlineTypes['!'][] = 'Image';
return;
}
- $target_url = null;
+ $image_content_item = null;
foreach ($this->content_items as $content_item) {
if ($content_item->path->basename == $image_name) {
- $target_url = $content_item->url;
+ $image_content_item = $content_item;
break;
}
}
- if ($target_url == null) {
+ if ($image_content_item == null) {
return;
}
+ $target_url = $image_content_item->url;
+ if ($image_width != null && $image_height != null) {
+ $original_path = $image_content_item->path;
+
+ $target_basename = $original_path->filename . '_' . $image_width . 'x' . $image_height . '.png';
+
+ $target_url = GARDEN_SITE_BASE_URL . garden_url($original_path->path, $target_basename);
+ $target_path = garden_path($this->output_directory, garden_url($original_path->path, $target_basename));
+
+ $post_process_item = new GardenImage($image_content_item, $image_width, $image_height, $target_url, $target_path);
+ $this->post_process_items[] = $post_process_item;
+ }
+
return array(
'extent' => strlen($matches[0]),
'element' => array(
}
}
-function garden_generate_html($content_items) {
- $parsedown = new GardenExtendedParsedown($content_items);
+function garden_generate_html($output_directory, $content_items) {
+ $output_items = [];
foreach ($content_items as $item) {
if ($item->type != GardenItemType::Article) {
}
$markdown_data = garden_read_file($item->source_filename);
+
+ $parsedown = new GardenExtendedParsedown($output_directory, $content_items);
$markdown_html = $parsedown->text($markdown_data);
-
+
+ if (count($parsedown->post_process_items) > 0) {
+ array_push($output_items, ...$parsedown->post_process_items);
+ }
+
$html_data = garden_template_render('article', [ 'article' => $item, 'article_content' => $markdown_html ]);
garden_write_file($item->target_filename, $html_data);
}
+
+ return $output_items;
}
///////////////////////////////////////////////////////////////////////////////
$process_items = garden_make_process_items(GARDEN_OUTPUT_DIR, $content_files);
garden_make_directories($process_items);
garden_move_raw($process_items);
- garden_generate_html($process_items);
+ $post_process_items = garden_generate_html(GARDEN_OUTPUT_DIR, $process_items);
+ garden_make_images($post_process_items);
}
///////////////////////////////////////////////////////////////////////////////