]> git.bts.cx Git - garden.git/commitdiff
Added JSON feed and links in theme
authorBen Sherratt <redacted>
Sun, 28 Dec 2025 10:14:58 +0000 (10:14 +0000)
committerBen Sherratt <redacted>
Sun, 28 Dec 2025 10:25:18 +0000 (10:25 +0000)
garden.php
templates/base.php
templates/style/screen.css

index e4391e4b557993afb647a9c4ece95f9508ed60d9..e4429e3f65248ca82f2dbb82f3ac166a696f41b7 100644 (file)
@@ -521,8 +521,6 @@ function garden_generate_html($output_directory, $content_items) {
 ///////////////////////////////////////////////////////////////////////////////
 
 function garden_generate_atom($output_directory, $content_items) {
-       $output_items = [];
-
        $recent_items = [];
        foreach ($content_items as $item) {
                if ($item->type != GardenItemType::Article) {
@@ -543,6 +541,41 @@ function garden_generate_atom($output_directory, $content_items) {
        garden_write_file(garden_path($output_directory, 'feed.atom'), $html_data);
 }
 
+function garden_generate_json($output_directory, $content_items) {
+       $recent_items = [];
+       foreach ($content_items as $item) {
+               if ($item->type != GardenItemType::Article) {
+                       continue;
+               }
+
+               $recent_items[$item->date] = $item;
+       }
+
+       // Sort by date...
+       ksort($recent_items);
+       $recent_items = array_reverse($recent_items);
+
+       $feed = [];
+       $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['items'] = [];
+
+       foreach ($recent_items as $item) {
+               $feed_item = [];
+               $feed_item['id'] = $item->date + hexdec(hash('crc32', $item->title));
+               $feed_item['date_published'] = date(DATE_RFC3339, $item->date);
+               $feed_item['title'] = $item->title;
+               $feed_item['content_text'] = 'An update was published.';
+               $feed_item['url'] = $item->url;
+               $feed['items'][] = $feed_item;
+       }
+
+       $json_data = json_encode($feed);
+       garden_write_file(garden_path($output_directory, 'feed.json'), $json_data);
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 // Main
 ///////////////////////////////////////////////////////////////////////////////
@@ -556,6 +589,7 @@ function garden() {
        $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);
 }
 
 ///////////////////////////////////////////////////////////////////////////////
index 76d6d0081e24b154860f8903484802b6521c65e8..75cedb2dde5f84f593b44968cf2db28f62aea084 100644 (file)
@@ -13,7 +13,9 @@
                <meta name="viewport" content="width=device-width, initial-scale=1.0">
 
                <link rel="stylesheet" href="<?= garden_site_url('style', 'screen.css') ?>">
+               
                <link rel="alternate" type="application/atom+xml" href="<?= garden_site_url('feed.atom') ?>">
+               <link rel="alternate" type="application/feed+json" href="<?= garden_site_url('feed.json') ?>">
        </head>
 
        <body>
                                        <?php endif ?>
                                <?php endforeach ?>
                                </ul>
+
+                               <ul>
+                                       <li><a href="<?= garden_site_url('feed.atom') ?>" class="feed">Atom Feed</a></li>
+                                       <li><a href="<?= garden_site_url('feed.json') ?>" class="feed">JSON Feed</a></li>
+                               </ul>
                        </nav>
 
                        <?= garden_template_content(); ?>
index cb1176c2a421df8788747b08811d244f86755cd8..11e561161649aa519711ef87b65d5e475a1dd1d9 100644 (file)
@@ -1,5 +1,5 @@
 html {
-       line-height: 1.15;
+       line-height: 1.3;
        -webkit-text-size-adjust:100%
 }
 
@@ -130,3 +130,12 @@ blockquote {
        border-radius: 0 0.25rem 0.25rem 0;
 }
 
+a.feed {
+       color: #f26522;
+}
+
+a.feed:hover {
+       background: none !important;
+       color: #bc4e1b !important;
+}
+