<commit_before>#  (c) <NAME>
#  https://github.com/aarongustafson/jekyll-webmention_io 
#  Licence : MIT
#  
#  JS stuff
#

module Jekyll
  module WebmentionIO
    using StringInflection
    class WebmentionJSTag < Liquid::Tag
      def render(context)
        # Configuration porting
        js = '<script>'
        js << 'if ( ! ( \'JekyllWebmentionIO\' in window ) ){ window.JekyllWebmentionIO = {}; }'
        js << 'window.JekyllWebmentionIO.types = { '
        js_types = []
        Jekyll::WebmentionIO::types.each do |type|
          js_types.push "'#{type}': '#{type.to_singular}'"
        end
        js << js_types.join(',')
        js << '};</script>'

        # JS file
        site = context.registers[:site]
        js_folder = 'js'
        if site.config['webmentions']['js'] and site.config['webmentions']['js']['destination']
          js_folder = site.config['webmentions']['js']['destination']
        end
        js_file_path = "#{site.config['baseurl']}/#{js_folder}/JekyllWebmentionIO.js"
        js << "<script src=\"#{js_file_path}\" async></script>"
        
        templates = ''
        template_files = Jekyll::WebmentionIO::types + ['count', 'webmentions']
        template_files.each do |template|
          if Jekyll::WebmentionIO::config.has_key? 'templates' and Jekyll::WebmentionIO::config['templates'].has_key? template
            # Jekyll::WebmentionIO::log 'info', "Using custom #{template} template"
            template_file = Jekyll::WebmentionIO::config['templates'][template]
          else
            # Jekyll::WebmentionIO::log 'info', "Using default #{template} template"
            template_file = File.join(File.dirname(File.expand_path(__FILE__)), "../templates/#{template}.html")
          end
          # Jekyll::WebmentionIO::log 'info', "Template file: #{template_file}"
          handler = File.open(template_file, 'rb')
          template_contents = handler.read

          templates << "<template id=\"webmention-#{template}\">#{template_contents}</template>"
        end
        
        "#{js}\n#{templates}"
      end
    end
  end
end

Liquid::Template.register_tag('webmentions_js', Jekyll::WebmentionIO::WebmentionJSTag)<commit_msg>Adding the ability to turn off JS<commit_after>#  (c) <NAME>
#  https://github.com/aarongustafson/jekyll-webmention_io 
#  Licence : MIT
#  
#  JS stuff
#

module Jekyll
  module WebmentionIO
    using StringInflection
    class WebmentionJSTag < Liquid::Tag
      def render(context)
        site = context.registers[:site]

        # JS can be turned off too
        if site.config['webmentions']['js'] == false
          return
        end

        # Configuration porting
        js = '<script>'
        js << 'if ( ! ( \'JekyllWebmentionIO\' in window ) ){ window.JekyllWebmentionIO = {}; }'
        js << 'window.JekyllWebmentionIO.types = { '
        js_types = []
        Jekyll::WebmentionIO::types.each do |type|
          js_types.push "'#{type}': '#{type.to_singular}'"
        end
        js << js_types.join(',')
        js << '};</script>'

        # JS file
        js_folder = 'js'
        if site.config['webmentions']['js'] and site.config['webmentions']['js']['destination']
          js_folder = site.config['webmentions']['js']['destination']
        end
        js_file_path = "#{site.config['baseurl']}/#{js_folder}/JekyllWebmentionIO.js"
        js << "<script src=\"#{js_file_path}\" async></script>"
        
        templates = ''
        template_files = Jekyll::WebmentionIO::types + ['count', 'webmentions']
        template_files.each do |template|
          if Jekyll::WebmentionIO::config.has_key? 'templates' and Jekyll::WebmentionIO::config['templates'].has_key? template
            # Jekyll::WebmentionIO::log 'info', "Using custom #{template} template"
            template_file = Jekyll::WebmentionIO::config['templates'][template]
          else
            # Jekyll::WebmentionIO::log 'info', "Using default #{template} template"
            template_file = File.join(File.dirname(File.expand_path(__FILE__)), "../templates/#{template}.html")
          end
          # Jekyll::WebmentionIO::log 'info', "Template file: #{template_file}"
          handler = File.open(template_file, 'rb')
          template_contents = handler.read

          templates << "<template id=\"webmention-#{template}\">#{template_contents}</template>"
        end
        
        "#{js}\n#{templates}"
      end
    end
  end
end

Liquid::Template.register_tag('webmentions_js', Jekyll::WebmentionIO::WebmentionJSTag)
{'fraction_non_alphanumeric': 0.15303197353914003, 'fraction_numerical': 0.0, 'mean_word_length': 2.802179379715004, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 17, 'https://': 2, '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': '1059248', 'n_tokens_mistral': 1412, 'n_tokens_neox': 1411, 'n_words': 248}