<commit_before>module Jekyll
  require "pp"
  require "json"
  require File.dirname(__FILE__) + "/CfeUtils.rb"

  class SiteNavigation < Jekyll::Generator
    safe true
    priority :lowest
    
    $CfeUtils = CFE::CfeUtils.new
    
    CONST_MaxSubLevels = 5   # - maximul alloved sublevels in left navigation
    
    ## sort keys inside hash
    def sort_by_key(data, recursive=false, &block)
      data.keys.sort(&block).reduce({}) do |seed, key|
        seed[key] = data[key]
        if recursive && seed[key].is_a?(Hash)
          seed[key] = sort_by_key(seed[key], true, &block)
        end
        seed
      end
    end
    
    
    def sortNavBySortingKey(data, recursive=false)
      data.each  do |k, arr|
          if (recursive && arr.has_key?('childrens') && !arr['childrens'].empty?)
              data[k]['childrens'] = sortNavBySortingKey(arr['childrens'], true)
          end
      end
      
      
      begin
          return data.sort_by { |i, v| v['sorting'] }<commit_msg>Sort left hand nav by sorting and title ¯\_(ツ)_/¯<commit_after>module Jekyll
  require "pp"
  require "json"
  require File.dirname(__FILE__) + "/CfeUtils.rb"

  class SiteNavigation < Jekyll::Generator
    safe true
    priority :lowest
    
    $CfeUtils = CFE::CfeUtils.new
    
    CONST_MaxSubLevels = 5   # - maximul alloved sublevels in left navigation
    
    ## sort keys inside hash
    def sort_by_key(data, recursive=false, &block)
      data.keys.sort(&block).reduce({}) do |seed, key|
        seed[key] = data[key]
        if recursive && seed[key].is_a?(Hash)
          seed[key] = sort_by_key(seed[key], true, &block)
        end
        seed
      end
    end
    
    
    def sortNavBySortingKey(data, recursive=false)
      data.each  do |k, arr|
          if (recursive && arr.has_key?('childrens') && !arr['childrens'].empty?)
              data[k]['childrens'] = sortNavBySortingKey(arr['childrens'], true)
          end
      end
      
      
      begin
          # Sort by sorting and then alphabetically.
          # https://stackoverflow.com/questions/4309723/ruby-sort-by-multiple-values
          # https://www.ruby-forum.com/topic/162413#1097691
          return data.sort_by { |i, v| [v.sorting, v.title]  }
{'fraction_non_alphanumeric': 0.12282268870031264, 'fraction_numerical': 0.00982581509602501, 'mean_word_length': 2.3333333333333335, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, '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': '6925236', 'n_tokens_mistral': 764, 'n_tokens_neox': 731, 'n_words': 163}