<commit_before>module Jekyll
  require File.dirname(__FILE__) + "/CfeUtils.rb"
  class Navigation < Generator
    $CfeUtils = CFE::CfeUtils.new
    $menu_items = {}

    def generate(site)
      site.pages.each do |page|
        if page.data["published"] != true || !page.data.key?("title") || page.data['categories'] == nil || page.data['categories'].first() == "index"
          next
        end
        writePageIntoMenuItems(page)
      end
      site.config["mainNavigation"] = "<ul>" + buildHtmlMenu($menu_items, 1) + "</ul>";
    end

    def writePageIntoMenuItems(page)
      tmp = $menu_items
      i = 0
      page.data['categories'].each do |category|
        i += 1
        category = $CfeUtils.removeUnvantedChars(category)
        tmp = initCategory(tmp, category)

        # write title and url to the last category which is page
        if page.data['categories'].length == i
          tmp['title'] ||= page.data['title']
          tmp['url'] ||= page.data['alias']
        end
        tmp = tmp['children']
      end
    end

    def initCategory(obj, category)
      if obj.has_key?(category) == false
        obj[category] ||= {}
        obj[category]['children'] ||= {}
      end
      return obj[category]
    end

    def buildHtmlMenu(items, level)
      html = ""
      items.sort_by{|k, v| v["title"]}.each do |key, item|
        hasChildren = !item["children"].nil? && !item["children"].empty?
        html += "<li class=\"#{(hasChildren ? 'parent' : '')} level-#{level}\" data-url=\"#{item["url"]}\"><a href=\"#{item["url"]}\">#{item["title"]}</a>"
        if hasChildren
          html += '<ul>'
          html += buildHtmlMenu(item["children"], level + 1)
          html += '</ul>'
        end
        html += "</li>"
      end
      return html
    end
  end
end
<commit_msg>Sort left navigation by sorting column and title<commit_after>module Jekyll
  require File.dirname(__FILE__) + "/CfeUtils.rb"
  class Navigation < Generator
    $CfeUtils = CFE::CfeUtils.new
    $menu_items = {}

    def generate(site)
      site.pages.each do |page|
        if page.data["published"] != true || !page.data.key?("title") || page.data['categories'] == nil || page.data['categories'].first() == "index"
          next
        end
        writePageIntoMenuItems(page)
      end
      site.config["mainNavigation"] = "<ul>" + buildHtmlMenu($menu_items, 1) + "</ul>";
    end

    def writePageIntoMenuItems(page)
      tmp = $menu_items
      i = 0
      page.data['categories'].each do |category|
        i += 1
        category = $CfeUtils.removeUnvantedChars(category)
        tmp = initCategory(tmp, category)

        # write title and url to the last category which is page
        if page.data['categories'].length == i
          tmp['title'] ||= page.data['title']
          tmp['url'] ||= page.data['alias']
        end
        if page.data['sorting'] == nil
          tmp['sorting'] = 100
        else
          tmp['sorting'] = page.data['sorting'].to_i
        end
        tmp = tmp['children']
      end
    end

    def initCategory(obj, category)
      if obj.has_key?(category) == false
        obj[category] ||= {}
        obj[category]['children'] ||= {}
      end
      return obj[category]
    end

    def buildHtmlMenu(items, level)
      html = ""
      items.sort_by{|k, v| [v["sorting"], v["title"]]}.each do |key, item|
        hasChildren = !item["children"].nil? && !item["children"].empty?
        html += "<li class=\"#{(hasChildren ? 'parent' : '')} level-#{level}\" data-url=\"#{item["url"]}\"><a href=\"#{item["url"]}\">#{item["title"]}</a>"
        if hasChildren
          html += '<ul>'
          html += buildHtmlMenu(item["children"], level + 1)
          html += '</ul>'
        end
        html += "</li>"
      end
      return html
    end
  end
end

{'fraction_non_alphanumeric': 0.17160850170558908, 'fraction_numerical': 0.0028863815271582263, 'mean_word_length': 2.3556338028169015, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, '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': '1839114', 'n_tokens_mistral': 1174, 'n_tokens_neox': 1155, 'n_words': 265}