[internal] Switch to a hash for topic-post counts

This commit is contained in:
Nemo 2023-11-30 10:08:52 +05:30
parent 14e5d33669
commit fe1cf59b9a
4 changed files with 16 additions and 23 deletions

View File

@ -1,5 +1,5 @@
<nav>
<ul>
{% for topic in site.data.topics %}<li class="topic-list"><a href="/{{ topic}}/">{{topic | capitalize|strip}}</a></li>{% endfor %}
{% for T in site.data.topics %}{%if T[1]>0%}<li class="topic-list"><a href="/{{ T[0]}}/">{{T[0] | capitalize|strip}}</a></li>{%endif%}{% endfor %}
</ul>
</nav>

View File

@ -40,28 +40,27 @@ class BeatrootNews < Jekyll::Generator
# Main plugin action, called by Jekyll-core
def generate(site)
@site = site
site.data['topics'] = Set.new site.data['topics']
count = 0
# Topic Counter
site.data['topics'] = site.data['topics'].to_h {|topic| [topic, 0]}
get_content.each do |article|
page = make_page(article['attributes']['modules'])
if page
site.pages << page
page['topics'].each do |topic|
unless site.data['topics'].include? topic
site.data['topics'] << topic
site.data['topics'][topic] = 0
Jekyll.logger.warn "News:", "New Topic #{topic}"
end
end
count+=1
site.data['topics'][page['topics'].first] += 1
end
end
site.data['topics'].each do |topic|
site.data['topics'].each do |topic, count|
@site.pages << make_topic_page(topic)
end
site.data['topics'] = site.data['topics'].to_a.sort
Jekyll.logger.info "News:", "Generated #{count} pages"
Jekyll.logger.info "News:", "Generated #{site.data['topics'].values.sum} pages"
end
private

View File

@ -7,23 +7,17 @@ layout: default
<h1 class="topic-heading">{{page.title}}</h1>
<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>
{% for topic in site.data.topics %}
{% assign post_count = 0 %}
{% capture h %}
{% for T in site.data.topics %}
{% assign post_count = T[1] %}
{% if post_count > 0 %}
<div class="topic-{{topic|downcase}}">
<h2><a href="/{{topic}}/">{{topic | capitalize}}</a></h2>
<h2><a href="/{{T[0]}}/">{{T[0] | capitalize}}</a></h2>
{% for post in site.pages %}
{% if post.topics and post.topics.first == topic %}
{% if post.topics and post.topics.first == T[0] %}
{% include_cached story.html story=post heading_level=3%}
{% assign post_count = post_count | plus: 1 %}
{% endif %}
{% endfor %}
</div>
{% endcapture %}
{% if post_count > 0 %}
{{h}}
{% endif %}
{% endfor %}

View File

@ -20,11 +20,11 @@ noindex: true
<h2>Hide These Topics</h2>
<fieldset>
<legend>Topics are only hidden on the home screen</legend>
{% for topic in site.data.topics %}
{% for T in site.data.topics %}
<label for="checkbox-hide-{{topic}}">
<input type=checkbox class="checkbox-hide" id="checkbox-hide-{{topic}}" value="{{topic}}">
{{topic | capitalize}}
<label for="checkbox-hide-{{T[0]}}">
<input type=checkbox class="checkbox-hide" id="checkbox-hide-{{T[0]}}" value="{{T[0]}}">
{{T[0] | capitalize}}
</label>
{% endfor %}
</fieldset>