<commit_before>#  (c) <NAME>
#  https://github.com/aarongustafson/jekyll-webmention_io 
#  Licence : MIT
#  
#  this liquid plugin insert a webmentions into your Octopress or Jekill blog
#  using http://webmention.io/ and the following syntax:
#   
require_relative 'webmention_io/version'

require 'json'
require 'net/http'
require 'uri'
require 'openssl'
require 'string_inflection'
require 'webmention'

module Jekyll
  module WebmentionIO
    
    @logger_prefix = '[jekyll-webmention_io]'

    @api_url = 'https://webmention.io/api'
    @api_endpoint = @api_url
    @api_suffix = ''
    
    @types = ['likes','links','posts','replies','reposts']

    def self.bootstrap()
      # @jekyll_config = Jekyll.configuration({ 'quiet' => true })
      @jekyll_config = Jekyll::configuration({})
      @config = @jekyll_config['webmentions'] || {}
      
      # Set up the cache folder & files
      @cache_folder = @config['cache_folder'] || '.jekyll-cache'
      Dir.mkdir(@cache_folder) unless File.exists?(@cache_folder)
      @file_prefix = ''
      if ! @cache_folder.include? 'webmention'
        @file_prefix = 'webmention_io_'
      end
      @cache_files = {
        'incoming' => "#{@cache_folder}/#{@file_prefix}received.yml",
        'outgoing' => "#{@cache_folder}/#{@file_prefix}outgoing.yml",
        'bad_uris' => "#{@cache_folder}/#{@file_prefix}bad_uris.yml"
      }
      @cache_files.each do |key, file|
        if ! File.exists?(file)
          File.open(file, 'w') { |f| YAML.dump({}, f) }
        end
      end
    end

    # Attributes
    def self.config
      @config
    end
    def self.jekyll_config
      @jekyll_config
    end
    def self.cache_files
      @cache_files
    end
    def self.cache_folder
      @cache_folder
    end
    def self.file_prefix
      @file_prefix
    end
    def self.types
      @types
    end
    
    def self.get_cache_file_path( key )
      path = false
      if @cache_files.has_key? key
        path = @cache_files[key]
      end
      return path
    end

    # API helpers
    #def uri_params_for(api_params)
    #  api_params.keys.sort.map do |k|
    #    "#{CGI::escape(k)}=#{CGI::escape(api_params[k])}"
    #  end.join('&')
    #end

    def self.set_api_endpoint(path)
      @api_endpoint = "#{@api_url}/#{path}"
    end
    
    def self.set_api_suffix(suffix)
      @api_suffix = suffix
    end

    def self.get_response(api_params)
      api_params << @api_suffix
      source = get_uri_source(@api_endpoint + "?#{api_params}")
      if source
        JSON.parse(source)
      else
        ""
      end
    end
    
    def self.get_webmention_endpoint( uri )
      # log 'info', "Looking for webmention endpoint at #{uri}"
      begin
        endpoint = Webmention::Client.supports_webmention?( uri )
        # if ! endpoint
        #   log 'info', "No webmention endpoint at #{uri}"
        # end<commit_msg>Tweaking the logging a bit<commit_after>#  (c) <NAME>
#  https://github.com/aarongustafson/jekyll-webmention_io 
#  Licence : MIT
#  
#  this liquid plugin insert a webmentions into your Octopress or Jekill blog
#  using http://webmention.io/ and the following syntax:
#   
require_relative 'webmention_io/version'

require 'json'
require 'net/http'
require 'uri'
require 'openssl'
require 'string_inflection'
require 'webmention'

module Jekyll
  module WebmentionIO
    
    @logger_prefix = '[jekyll-webmention_io]'

    @api_url = 'https://webmention.io/api'
    @api_endpoint = @api_url
    @api_suffix = ''
    
    @types = ['likes','links','posts','replies','reposts']

    def self.bootstrap()
      # @jekyll_config = Jekyll.configuration({ 'quiet' => true })
      @jekyll_config = Jekyll::configuration({})
      @config = @jekyll_config['webmentions'] || {}
      
      # Set up the cache folder & files
      @cache_folder = @config['cache_folder'] || '.jekyll-cache'
      Dir.mkdir(@cache_folder) unless File.exists?(@cache_folder)
      @file_prefix = ''
      if ! @cache_folder.include? 'webmention'
        @file_prefix = 'webmention_io_'
      end
      @cache_files = {
        'incoming' => "#{@cache_folder}/#{@file_prefix}received.yml",
        'outgoing' => "#{@cache_folder}/#{@file_prefix}outgoing.yml",
        'bad_uris' => "#{@cache_folder}/#{@file_prefix}bad_uris.yml"
      }
      @cache_files.each do |key, file|
        if ! File.exists?(file)
          File.open(file, 'w') { |f| YAML.dump({}, f) }
        end
      end
    end

    # Attributes
    def self.config
      @config
    end
    def self.jekyll_config
      @jekyll_config
    end
    def self.cache_files
      @cache_files
    end
    def self.cache_folder
      @cache_folder
    end
    def self.file_prefix
      @file_prefix
    end
    def self.types
      @types
    end
    
    def self.get_cache_file_path( key )
      path = false
      if @cache_files.has_key? key
        path = @cache_files[key]
      end
      return path
    end

    # API helpers
    #def uri_params_for(api_params)
    #  api_params.keys.sort.map do |k|
    #    "#{CGI::escape(k)}=#{CGI::escape(api_params[k])}"
    #  end.join('&')
    #end

    def self.set_api_endpoint(path)
      @api_endpoint = "#{@api_url}/#{path}"
    end
    
    def self.set_api_suffix(suffix)
      @api_suffix = suffix
    end

    def self.get_response(api_params)
      api_params << @api_suffix
      source = get_uri_source(@api_endpoint + "?#{api_params}")
      if source
        JSON.parse(source)
      else
        ""
      end
    end
    
    def self.get_webmention_endpoint( uri )
      # log 'info', "Looking for webmention endpoint at #{uri}"
      begin
        endpoint = Webmention::Client.supports_webmention?( uri )
        if ! endpoint
          log 'info', "Could not find a webmention endpoint at #{uri}"
        end
{'fraction_non_alphanumeric': 0.12778065183652354, 'fraction_numerical': 0.0, 'mean_word_length': 2.54306658521686, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 4, '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': '92728', 'n_tokens_mistral': 2010, 'n_tokens_neox': 1991, 'n_words': 402}