<commit_before><%

  cookies.permanent[:news_type] ||= 'stack_overflow'

  has_discourse_news = ( cookies.permanent[:news_type] == 'discourse' )
  has_reddit_news = ( cookies.permanent[:news_type] == 'reddit' )
  has_github_news = ( cookies.permanent[:news_type] == 'github' )
  has_stack_overflow_news = ( cookies.permanent[:news_type] == 'stack_overflow' )

  # has_all_news = ( cookies.permanent[:news_type] == 'all' )

%>

<div class="list-group-item cs-center row cs-no-padding cs-no-margin">

  <%= link_to settings_path(news_type: has_discourse_news ? 'all' : 'discourse'), class: "col-xs-3 cs-no-margin btn cs-news-selector #{ 'btn-primary' if has_discourse_news }" do %>
    <h4 class="cs-no-margin">
      <%= fa_icon "comment" %>
    </h4>
  <% end %>

  <%= link_to settings_path(news_type: has_stack_overflow_news ? 'all' : 'stack_overflow'), class: "col-xs-3 cs-no-margin btn cs-news-selector #{ 'btn-primary' if has_stack_overflow_news }" do %>
    <h4 class="cs-no-margin">
      <%= fa_icon "stack-overflow" %>
    </h4>
  <% end %>

  <%= link_to settings_path(news_type: has_reddit_news ? 'all' : 'reddit'), class: "col-xs-3 cs-no-margin btn cs-news-selector #{ 'btn-primary' if has_reddit_news }" do %>
    <h4 class="cs-no-margin">
      <%= fa_icon "reddit" %>
    </h4>
  <% end %>

  <%= link_to settings_path(news_type: has_github_news ? 'all' : 'github'), class: "col-xs-3 cs-no-margin btn cs-news-selector #{ 'btn-primary' if has_github_news }" do %>
    <h4 class="cs-no-margin">
      <%= fa_icon "github" %>
    </h4>
  <% end %>

</div>

<%
  has_no_news_type = !has_discourse_news && !has_reddit_news
  has_no_news_type &= !has_github_news && !has_stack_overflow_news

  if has_no_news_type
    has_discourse_news, has_reddit_news = true, true
    has_github_news, has_stack_overflow_news = true, true
  end

  if has_discourse_news
    discourse_even_news_items, discourse_odd_news_items = \
      DiscourseNewsItem.active_batch_scope.includes(:target)
      .limit(50).all.partition.with_index { |x, i| i.even? }
  end

  news_items_lists = []

  if has_reddit_news
    news_items_lists << RedditNewsItem.active_batch_scope.includes(:target).all
  end

  if has_discourse_news
    news_items_lists << discourse_even_news_items
  end

  if has_github_news
    news_items_lists << GithubNewsItem.active_batch_scope.includes(:target).all
  end

  if has_discourse_news
    news_items_lists << discourse_odd_news_items
  end

  if has_stack_overflow_news
    news_items_lists << StackOverflowNewsItem.active_batch_scope.includes(:target).all
  end

  news_items_lists.reject! &:empty?

  first_news_items = news_items_lists.shift

  news_items = first_news_items.zip(
    *news_items_lists
  ).flatten

  news_css_classes = 'btn btn-default cs-left-align cs-no-margin col-xs-10'

%>

<%

  blurb_replace_tags = %w[
    p
    a
    pre
    code
    strong<commit_msg>Make sidebar more robust against missing news bars<commit_after><%

  cookies.permanent[:news_type] ||= 'stack_overflow'

  has_discourse_news = ( cookies.permanent[:news_type] == 'discourse' )
  has_reddit_news = ( cookies.permanent[:news_type] == 'reddit' )
  has_github_news = ( cookies.permanent[:news_type] == 'github' )
  has_stack_overflow_news = ( cookies.permanent[:news_type] == 'stack_overflow' )

  # has_all_news = ( cookies.permanent[:news_type] == 'all' )

%>

<div class="list-group-item cs-center row cs-no-padding cs-no-margin">

  <%= link_to settings_path(news_type: has_discourse_news ? 'all' : 'discourse'), class: "col-xs-3 cs-no-margin btn cs-news-selector #{ 'btn-primary' if has_discourse_news }" do %>
    <h4 class="cs-no-margin">
      <%= fa_icon "comment" %>
    </h4>
  <% end %>

  <%= link_to settings_path(news_type: has_stack_overflow_news ? 'all' : 'stack_overflow'), class: "col-xs-3 cs-no-margin btn cs-news-selector #{ 'btn-primary' if has_stack_overflow_news }" do %>
    <h4 class="cs-no-margin">
      <%= fa_icon "stack-overflow" %>
    </h4>
  <% end %>

  <%= link_to settings_path(news_type: has_reddit_news ? 'all' : 'reddit'), class: "col-xs-3 cs-no-margin btn cs-news-selector #{ 'btn-primary' if has_reddit_news }" do %>
    <h4 class="cs-no-margin">
      <%= fa_icon "reddit" %>
    </h4>
  <% end %>

  <%= link_to settings_path(news_type: has_github_news ? 'all' : 'github'), class: "col-xs-3 cs-no-margin btn cs-news-selector #{ 'btn-primary' if has_github_news }" do %>
    <h4 class="cs-no-margin">
      <%= fa_icon "github" %>
    </h4>
  <% end %>

</div>

<%
  has_no_news_type = !has_discourse_news && !has_reddit_news
  has_no_news_type &= !has_github_news && !has_stack_overflow_news

  if has_no_news_type
    has_discourse_news, has_reddit_news = true, true
    has_github_news, has_stack_overflow_news = true, true
  end

  if has_discourse_news
    discourse_even_news_items, discourse_odd_news_items = \
      DiscourseNewsItem.active_batch_scope.includes(:target)
      .limit(50).all.partition.with_index { |x, i| i.even? }
  end

  news_items_lists = []

  if has_reddit_news
    news_items_lists << RedditNewsItem.active_batch_scope.includes(:target).all
  end

  if has_discourse_news
    news_items_lists << discourse_even_news_items
  end

  if has_github_news
    news_items_lists << GithubNewsItem.active_batch_scope.includes(:target).all
  end

  if has_discourse_news
    news_items_lists << discourse_odd_news_items
  end

  if has_stack_overflow_news
    news_items_lists << StackOverflowNewsItem.active_batch_scope.includes(:target).all
  end

  news_items_lists.select! &:present?
  news_items_lists.reject! &:empty?

  if news_items_lists.empty?
    news_items = []
  else
    first_news_items = news_items_lists.shift

    news_items = first_news_items.zip(
      *news_items_lists
    ).flatten
  end

  news_css_classes = 'btn btn-default cs-left-align cs-no-margin col-xs-10'

%>

<%

  blurb_replace_tags = %w[
    p
    a
    pre
    code
    strong
{'fraction_non_alphanumeric': 0.13407444837459997, 'fraction_numerical': 0.00538992757284824, 'mean_word_length': 4.019442096365173, 'pattern_counts': {'":': 0, '<': 73, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3212520', 'n_tokens_mistral': 2263, 'n_tokens_neox': 2179, 'n_words': 371}