]> git.bts.cx Git - garden.git/blobdiff - garden.php
Some small template fixes
[garden.git] / garden.php
index e4429e3f65248ca82f2dbb82f3ac166a696f41b7..8c0127705962891ee05cda45655bfa0539462977 100644 (file)
@@ -260,7 +260,11 @@ function garden_template_render($name, $variables = null) {
        $output = '';
        while ($name != null) {
                $path = garden_path(GARDEN_TEMPLATE_DIR, $name . '.php');
-               
+
+               if (file_exists($path) == false) {
+                       $path = garden_path(GARDEN_FALLBACK_TEMPLATE_DIR, $name . '.php');
+               }
+
                $base_template = null;
                $base_template_variables = null;
 
@@ -312,8 +316,6 @@ function garden_site_url(...$url_segments) {
        return GARDEN_SITE_BASE_URL . garden_url(...$url_segments);
 }
 
-
-
 ///////////////////////////////////////////////////////////////////////////////
 // Images
 ///////////////////////////////////////////////////////////////////////////////
@@ -520,14 +522,21 @@ function garden_generate_html($output_directory, $content_items) {
 // Feed
 ///////////////////////////////////////////////////////////////////////////////
 
-function garden_generate_atom($output_directory, $content_items) {
+function garden_generate_atom($output_directory, $output_filename, $content_items) {
        $recent_items = [];
        foreach ($content_items as $item) {
                if ($item->type != GardenItemType::Article) {
                        continue;
                }
 
-               $recent_items[$item->date] = $item;
+               $date_key = $item->date;
+
+               // Hack to support sorting without missing entries
+               while (isset($recent_items[$date_key])) {
+                       $date_key += 1;
+               }
+
+               $recent_items[$date_key] = $item;
        }
 
        // Sort by date...
@@ -538,10 +547,10 @@ function garden_generate_atom($output_directory, $content_items) {
        $variables['recent_items'] =  $recent_items;
        $html_data = garden_template_render('atom', $variables);
 
-       garden_write_file(garden_path($output_directory, 'feed.atom'), $html_data);
+       garden_write_file(garden_path($output_directory, $output_filename), $html_data);
 }
 
-function garden_generate_json($output_directory, $content_items) {
+function garden_generate_json($output_directory, $output_filename, $content_items) {
        $recent_items = [];
        foreach ($content_items as $item) {
                if ($item->type != GardenItemType::Article) {
@@ -559,7 +568,7 @@ function garden_generate_json($output_directory, $content_items) {
        $feed['version'] = 'https://jsonfeed.org/version/1.1';
        $feed['title'] = GARDEN_TEMPLATE_CONSTANTS['site_name'];
        $feed['home_page_url'] = garden_site_url('/');
-       $feed['feed_url'] = garden_site_url('/feed.json');
+       $feed['feed_url'] = garden_site_url($output_filename);
        $feed['items'] = [];
 
        foreach ($recent_items as $item) {
@@ -573,7 +582,7 @@ function garden_generate_json($output_directory, $content_items) {
        }
 
        $json_data = json_encode($feed);
-       garden_write_file(garden_path($output_directory, 'feed.json'), $json_data);
+       garden_write_file(garden_path($output_directory, $output_filename), $json_data);
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -588,8 +597,14 @@ function garden() {
        garden_move_raw($process_items);
        $post_process_items = garden_generate_html(GARDEN_OUTPUT_DIR, $process_items);
        garden_make_images($post_process_items);
-       garden_generate_atom(GARDEN_OUTPUT_DIR, $process_items);
-       garden_generate_json(GARDEN_OUTPUT_DIR, $process_items);
+
+       if (defined('GARDEN_ATOM_FEED_FILENAME')) {
+               garden_generate_atom(GARDEN_OUTPUT_DIR, GARDEN_ATOM_FEED_FILENAME, $process_items);
+       }
+
+       if (defined('GARDEN_JSON_FEED_FILENAME')) {
+               garden_generate_json(GARDEN_OUTPUT_DIR, GARDEN_JSON_FEED_FILENAME, $process_items);
+       }
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -599,6 +614,8 @@ function garden() {
 assert(extension_loaded('imagick'), 'Needs Imagick');
 assert($argc >= 2, 'Please provide configuration file');
 
+define('GARDEN_FALLBACK_TEMPLATE_DIR', garden_path(__DIR__, 'templates'));
+
 // First parameter needs to be the configuration php
 $config_file = $argv[1];