Switch to better topic counting
This commit is contained in:
parent
01a9f941ed
commit
6005f1e59c
|
@ -9,16 +9,15 @@ layout: default
|
|||
<div class="hr-line"></div>
|
||||
<p class="topic-date"><time datetime="{{site.time | date: '%y-%m-%d'}}">{{site.time | date: "%A, %b, %e, %Y"}}</time></p>
|
||||
|
||||
{% 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 %}
|
||||
<p class="topic-empty">No articles today under {{page.title}}</p>
|
||||
{% 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 %}
|
||||
|
||||
</div> <!-- topic-container -->
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue