<commit_before>require 'rubygems'
require 'json'
require 'net/http'
require 'cgi'

module Jekyll

	class XkcdEmbed < Liquid::Tag
		def	initialize(tag_name, number, tokens)
			super
			@number = number.strip
		end
		
		def render(context)
			url = "\"https://xkcd.com/" + @number + "\""
			jsonUrl = "https://xkcd.com/" + @number + "/info.0.json"
			resp = Net::HTTP.get_response(URI.parse(jsonUrl))			
			if resp.code == '404'
				"<span><a href=" + url + ">xkcd-" + @number + "</a></span>"
			else
				result = JSON.parse(resp.body)
				"<figure class=\"xkcd-embed\">
					<a href=" + url + ">" + 
						"<img" + 
							" src=\"" + result["img"] + "\"" + 
							" title=\"" + CGI::escapeHTML(result["alt"]) + "\"" + 
							" alt=" + url + 
						">" +
					"</a>" + 
					"<figcaption>" +
						"\"" + CGI::escapeHTML(result["title"]) + "\" - created by <a href=\"http://xkcd.com\">xkcd</a>" + 
					"</figcaption>" +
				"</figure>"
			end
		end
	end
end

Liquid::Template.register_tag('xkcd', Jekyll::XkcdEmbed)<commit_msg>add xkcd embed plugin<commit_after>require 'rubygems'
require 'json'
require 'net/http'
require 'cgi'

module Jekyll

	class XkcdEmbed < Liquid::Tag
		def	initialize(tag_name, number, tokens)
			super
			@number = number.strip
		end
		
		def render(context)
			@env = Jekyll::env
			if @env != "production"
				return
			end
			url = "\"https://xkcd.com/" + @number + "\""
			jsonUrl = "https://xkcd.com/" + @number + "/info.0.json"
			resp = Net::HTTP.get_response(URI.parse(jsonUrl))			
			if resp.code == '404'
				"<span><a href=" + url + ">xkcd-" + @number + "</a></span>"
			else
				result = JSON.parse(resp.body)
				"<figure class=\"xkcd-embed\">
					<a href=" + url + ">" + 
						"<img" + 
							" src=\"" + result["img"] + "\"" + 
							" title=\"" + CGI::escapeHTML(result["alt"]) + "\"" + 
							" alt=" + url + 
						">" +
					"</a>" + 
					"<figcaption>" +
						"\"" + CGI::escapeHTML(result["title"]) + "\" - created by <a href=\"http://xkcd.com\">xkcd</a>" + 
					"</figcaption>" +
				"</figure>"
			end
		end
	end
end

Liquid::Template.register_tag('xkcd', Jekyll::XkcdEmbed)
{'fraction_non_alphanumeric': 0.22175339896858884, 'fraction_numerical': 0.003750586029067042, 'mean_word_length': 2.60472972972973, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 29, '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': '3685963', 'n_tokens_mistral': 1016, 'n_tokens_neox': 809, 'n_words': 151}