diff --git a/_layouts/topic.html b/_layouts/topic.html index 8030e23..6d4bcf9 100644 --- a/_layouts/topic.html +++ b/_layouts/topic.html @@ -9,16 +9,15 @@ layout: default

-{% assign post_count = 1 %} -{% for post in site.pages %} -{% if post.topics and post.topics contains page.topic %} - {% include_cached story.html story=post heading_level="2" %} - {% assign post_count = post_count | plus: 1 %} -{% endif %} -{% endfor %} - -{% if post_count == 1 %} +{% if page.article_count == 0 %}

No articles today under {{page.title}}

+{% else %} + {% for post in site.pages %} + {% if post.topics and post.topics contains page.topic %} + {% include_cached story.html story=post heading_level="2" %} + {% assign post_count = post_count | plus: 1 %} + {% endif %} + {% endfor %} {% endif %} diff --git a/_plugins/fetch_posts.rb b/_plugins/fetch_posts.rb index bf0ea51..1e67139 100644 --- a/_plugins/fetch_posts.rb +++ b/_plugins/fetch_posts.rb @@ -57,21 +57,27 @@ class BeatrootNews < Jekyll::Generator end site.data['topics'].each do |topic, count| - @site.pages << make_topic_page(topic) + @site.pages << make_topic_page(topic, count) end - Jekyll.logger.info "News:", "Generated #{site.data['topics'].values.sum} pages" + Jekyll.logger.info "News:", "Generated #{site.data['topics'].values.sum} article pages" + # These are fallback checks to make sure if we have a bug or get bad data, + # we don't update the website with not enough news + # better to fail the build than show an empty website. + raise "Not enough articles, not updating website" if site.data['topics'].values.sum < 10 + raise "Not enough topics, not updating website" if site.data['topics'].size < 5 end private - def make_topic_page(topic) + def make_topic_page(topic, count) PageWithoutAFile.new(@site, __dir__, topic, "index.html").tap do |file| file.data.merge!( 'title' => topic.capitalize, 'layout' => 'topic', 'topic' => topic, - 'permalink' => "/#{topic}/" + 'permalink' => "/#{topic}/", + 'article_count' => count ) file.output end