<commit_before>#
# Generates archive pages for year, month, and day.
#
# An archive listing will be created for each year, month, and day that
# contains a post.
#
# Author:: <NAME>
# Copyright: Copyright (c) 2013-2015 <NAME>
# License:: MIT

module Jekyll
  module Itafroma
    # Generator for archive listings.
    class ArchiveGenerator < Generator
      # This generator is safe from arbitrary code execution.
      safe true

      # Generate archive pages.
      #
      # site - The site.
      #
      # Returns nothing.
      def generate(site)
        archives = site.config['archive'] || []

        if archives.is_a? Hash
          puts 'Warning: the configuration format used for Jekyll Archive Generator is deprecated. Please see README for the new format.'
          archives = [archives]
        end

        archives.each do |archive|
          layout = archive['layout'] || 'archive'
          if site.layouts.key? layout
            path = archive['path'] || '/'
            title = archive['title'] || 'Blog archive - :date'

            inclusions = archive['include'] || {}
            posts = if inclusions.empty? 
              site.posts
            else 
              site.posts.select do |post|
                inclusions.any? do |key, inclusion|
                  (post[key] & inclusion).any?
                end
              end
            end

            exclusions = archive['exclude'] || {}
            exclusions.each do |key, exclusion|
              posts.reject! do |post|
                (post[key] & exclusion).any?
              end
            end

            site.pages += generate_archive_pages(site, posts, layout, path, title, '%Y/%m/%d')
            site.pages += generate_archive_pages(site, posts, layout, path, title, '%Y/%m')
            site.pages += generate_archive_pages(site, posts, layout, path, title, '%Y')
          end
        end
      end

      private

      # Generate an archive page group.
      #
      # site    - The site.
      # posts   - The Posts to include in the archive.
      # layout  - The layout to use for the archive page
      # path    - The path to use for the archive page
      # title   - The tokenized title to use for the archive page
      # pattern - The date pattern to collate the archive on
      #
      # Returns an Array of archive Pages.
      def generate_archive_pages(site, posts, layout, path, title, pattern)
        pages = []

        collate(posts, pattern).each do |_, collated_posts|
          pages << ArchivePage.new(site, site.source, layout, path, title, pattern, collated_posts)
        end

        pages.each_with_index do |page, index|
          page.data['archive'].merge!({'paginator' => ArchivePager.new(site, index + 1, pages, pages.size)})
        end<commit_msg>DRYify page generation.<commit_after>#
# Generates archive pages for year, month, and day.
#
# An archive listing will be created for each year, month, and day that
# contains a post.
#
# Author:: <NAME>
# Copyright: Copyright (c) 2013-2015 <NAME>
# License:: MIT

module Jekyll
  module Itafroma
    # Generator for archive listings.
    class ArchiveGenerator < Generator
      # This generator is safe from arbitrary code execution.
      safe true

      # Generate archive pages.
      #
      # site - The site.
      #
      # Returns nothing.
      def generate(site)
        archives = site.config['archive'] || []

        if archives.is_a? Hash
          puts 'Warning: the configuration format used for Jekyll Archive Generator is deprecated. Please see README for the new format.'
          archives = [archives]
        end

        archives.each do |archive|
          layout = archive['layout'] || 'archive'
          if site.layouts.key? layout
            path = archive['path'] || '/'
            title = archive['title'] || 'Blog archive - :date'

            inclusions = archive['include'] || {}
            posts = if inclusions.empty? 
              site.posts
            else 
              site.posts.select do |post|
                inclusions.any? do |key, inclusion|
                  (post[key] & inclusion).any?
                end
              end
            end

            exclusions = archive['exclude'] || {}
            exclusions.each do |key, exclusion|
              posts.reject! do |post|
                (post[key] & exclusion).any?
              end
            end

            date_patterns = ['%Y/%m/%d', '%Y/%m', '%Y']
            date_patterns.each do |pattern|
              site.pages += generate_archive_pages(site, posts, layout, path, title, pattern)
            end
          end
        end
      end

      private

      # Generate an archive page group.
      #
      # site    - The site.
      # posts   - The Posts to include in the archive.
      # layout  - The layout to use for the archive page
      # path    - The path to use for the archive page
      # title   - The tokenized title to use for the archive page
      # pattern - The date pattern to collate the archive on
      #
      # Returns an Array of archive Pages.
      def generate_archive_pages(site, posts, layout, path, title, pattern)
        pages = []

        collate(posts, pattern).each do |_, collated_posts|
          pages << ArchivePage.new(site, site.source, layout, path, title, pattern, collated_posts)
        end

        pages.each_with_index do |page, index|
          page.data['archive'].merge!({'paginator' => ArchivePager.new(site, index + 1, pages, pages.size)})
        end
{'fraction_non_alphanumeric': 0.09793627805937727, 'fraction_numerical': 0.0032585083272990588, 'mean_word_length': 1.8656639004149378, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, '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': '6331933', 'n_tokens_mistral': 1524, 'n_tokens_neox': 1445, 'n_words': 507}