<commit_before>module Spree
  module Blog
    class ContentsController < BaseController
      layout 'spree/layouts/spree_blog'

      def index
        @title = "Indice dei contenuti"
        @posts = Spree::Post.order(:published_at).reverse_order.limit(4)
        @categories = Spree::Category.order(:name)
        @tags = Spree::Tag.order(:name)
        @authors = Spree::Author.order([:last_name, :first_name])
      end

      def show
        if @post = Spree::Post.find_by_permalink(params[:slug])
          @title = @post.title
          render 'post'
        elsif @author = Spree::Author.find_by_permalink(params[:slug])
          @title = @author.full_name
          render 'author'
        elsif @category = Spree::Category.find_by_permalink(params[:slug])
          @title = @category.name
          render 'category'
        elsif @tag = Spree::Tag.find_by_permalink(params[:slug])
          @title = @tag.name
          render 'tag'
        else
          render_404
        end
      end

    end
  end
end<commit_msg>better filtering of contents<commit_after>module Spree
  module Blog
    class ContentsController < BaseController
      layout 'spree/layouts/spree_blog'

      def index
        @title = "Indice dei contenuti"
        @posts = Spree::Post.order(:published_at).reverse_order.visible.limit(4)
        @categories = Spree::Category.order(:name)
        @tags = Spree::Tag.with_posts.sorted_alphabetically
        @authors = Spree::Author.order([:last_name, :first_name])
      end

      def show
        if @post = Spree::Post.where(permalink: params[:slug]).visible.first
          @title = @post.title
          render 'post'
        elsif @author = Spree::Author.where(permalink: params[:slug]).first
          @title = @author.full_name
          render 'author'
        elsif @category = Spree::Category.where(permalink: params[:slug]).first
          @title = @category.name
          render 'category'
        elsif @tag = Spree::Tag.where(permalink: params[:slug]).first
          @title = @tag.name
          render 'tag'
        else
          render_404
        end
      end

    end
  end
end
{'fraction_non_alphanumeric': 0.11220196353436185, 'fraction_numerical': 0.0037400654511453952, 'mean_word_length': 2.328149300155521, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2006172', 'n_tokens_mistral': 654, 'n_tokens_neox': 647, 'n_words': 130}