<commit_before>// Functionality to load up a t1 page from data.json


/*
 * Sets the window title and h1 text.
 */
function setTitle(title) {
	$( "title" ).html( title )
	$( "h1" ).html( title )
}


/*
 * Builds an absolute link to the given filename.
 */
function link(filename) {

	// Get the current path:
	var result = window.location.pathname

	// This is to help when editing templates:
	if (result.indexOf(".") != -1)
		result = result.substring(0, result.lastIndexOf("/"))

	// Add a trailing slash if necessary:
	if (result.substring(result.length - 1) != "/") {
		result += "/"
	}

	// Append the filename:
	result += filename

	return result
}


/*
 * Builds an absolute link to the data.json file.
 */
function dataPath() {

	var dataPath =  link("data.json")

	console.log("Data at: "+dataPath)
	return dataPath
}

function populateDetail(detail, template) {

	var detailItem = template.clone()

	$("a", detailItem).text(detail.name)
	$(".stat__figure", detailItem).text(detail.number)
	$(".stat__figure__unit", detailItem).text(detail.unit)
	$(".stat__description", detailItem).text(detail.date)

	return detailItem
}

function buildBreadcrumb(breadcrumbItem) {

	var breadcrumb = $(".breadcrumb")
	
	var breadcrumbHome = breadcrumbItem.clone()
	$("a", breadcrumbHome).text("Home").attr("href", "/")
	breadcrumb.append(breadcrumbHome)
}

/*
 * Main function to populate the page.
 */
$( document ).ready(function() {

	/* Deconstruct the template: */

	// Title
	setTitle("Home")

	// Breadcrumb
	var breadcrumb = $(".breadcrumb")
	var breadcrumbItem = $("li:eq(0)", breadcrumb)
	breadcrumbItem.detach()
	$("li", breadcrumb).remove()

	var section = new Array();
	var header = new Array();
	var sectionItem = new Array();
	var footer = new Array();

	for (var i = 0; i < 4; i++) {

		// Section blocks
		section.push($(".nav-panel--stats:eq("+i+")"))

		// Section headers - set placeholders:
		header.push($("header", section[i]))
		$("h2", header[i]).text("Loading..")

		// Section items
		// - detach one to use as a template and remove the rest:
		sectionItem.push($("li:eq(0)", section[i]))
		sectionItem[i].detach()
		$("li", section[i]).remove()

		// Section footers
		// - detach these to use as a template:
		footer.push($("footer", section[i]))
		footer[i].detach()
	}

	/* Get the data.json file to populate the page: */

	$.get( dataPath(), function( data ) {

		// Titles:
		setTitle(data.name)

		// Lede and reveal:
		$("p", ".lede").text(data.lede);
		$(".content-reveal__hidden").text(data.more)

		for (var i = 0; i < 4; i++) {

			// Sections
			if (data.children.length > 0) {
				var item = data.children.shift()
				$("h2", header[i]).text(item.name)
				while (item.detail.length > 0) {
					var detailItem = populateDetail(item.detail.shift(), sectionItem[i])
					$("ul", section[i]).append(detailItem)
				}
				$("a", footer[i]).text("View all " + item.name).attr("href", link(item.fileName))
				section[i].append(footer[i])
			}
		}

		// Breadcrumb
		buildBreadcrumb(breadcrumbItem)

	});

});<commit_msg>T1 Javascript now loads detail from JSON in sections below rather than duplicating it it the T1 JSON.<commit_after>// Functionality to load up a t1 page from data.json


/*
 * Sets the window title and h1 text.
 */
function setTitle(title) {
	$( "title" ).html( title )
	$( "h1" ).html( title )
}


/*
 * Builds an absolute link to the given filename.
 */
function link(filename) {

	// Get the current path:
	var result = window.location.pathname

	// This is to help when editing templates:
	if (result.indexOf(".") != -1)
		result = result.substring(0, result.lastIndexOf("/"))

	// Add a trailing slash if necessary:
	if (result.substring(result.length - 1) != "/") {
		result += "/"
	}

	// Append the filename:
	result += filename

	return result
}


/*
 * Builds an absolute link to the data.json file.
 */
function dataPath() {

	var dataPath =  link("data.json")

	console.log("Data at: "+dataPath)
	return dataPath
}


/*
 * Builds an absolute link to the data.json file.
 */
function dataChildPath(child) {

	var dataPath =  link(child.fileName + "/data.json")

	console.log("Data for "+child.name+" at: "+dataPath)
	return dataPath
}

function populateDetail(detail, template) {

	var detailItem = template.clone()

	$("a", detailItem).text(detail.name)
	$(".stat__figure", detailItem).text(detail.number)
	$(".stat__figure__unit", detailItem).text(detail.unit)
	$(".stat__description", detailItem).text(detail.date)

	return detailItem
}

function buildBreadcrumb(breadcrumbItem) {

	var breadcrumb = $(".breadcrumb")
	
	var breadcrumbHome = breadcrumbItem.clone()
	$("a", breadcrumbHome).text("Home").attr("href", "/")
	breadcrumb.append(breadcrumbHome)
}


// Breadcrumb
var breadcrumb
var breadcrumbItem

var section = new Array();
var header = new Array();
var sectionItem = new Array();
var footer = new Array();

/**
  * Deconstructs the page into chunks of markup template. 
  */
var deconstruct = function() {

	// Title
	setTitle("Home")

	// Breadcrumb
	breadcrumb = $(".breadcrumb")
	breadcrumbItem = $("li:eq(0)", breadcrumb)
	breadcrumbItem.detach()
	$("li", breadcrumb).remove()

	for (var i = 0; i < 4; i++) {

		// Section blocks
		section.push($(".nav-panel--stats:eq("+i+")"))

		// Section headers - set placeholders:
		header.push($("header", section[i]))
		$("h2", header[i]).text("Loading..")

		// Section items
		// - detach one to use as a template and remove the rest:
		sectionItem.push($("li:eq(0)", section[i]))
		sectionItem[i].detach()
		$("li", section[i]).remove()

		// Section footers
		// - detach these to use as a template:
		footer.push($("footer", section[i]))
		footer[i].detach()
	}
}

var populateChild = function(child, section, template) {

	$.get( dataChildPath(child), function( data ) {

		// Sections
		var i = 0;
		while (data.children.length > 0 && i++ < 4) {
			var item = data.children.shift()
			console.log("Setting up: "+item.name+" in "+child.name)
			var itemMarkup = template.clone()

			$("a", itemMarkup).text(item.name)
			$(".stat__figure", itemMarkup).text(item.number)
			$(".stat__figure__unit", itemMarkup).text(item.unit)
			$(".stat__description", itemMarkup).text(item.date)

			$("ul", section).append(itemMarkup)
		}
	})
}

/*
 * Main function to populate the page.
 */
$( document ).ready(function() {

	deconstruct();

	/* Get the data.json file to populate the page: */

	$.get( dataPath(), function( data ) {

		// Titles:
		setTitle(data.name)

		// Lede and reveal:
		$("p", ".lede").text(data.lede);
		$(".content-reveal__hidden").text(data.more)

		for (var i = 0; i < 4; i++) {

			// Sections
			if (data.children.length > 0) {
				var item = data.children.shift()
				$("h2", header[i]).text(item.name)
				var detail = populateChild(item, section[i], sectionItem[i])
				$("a", footer[i]).text("View all " + item.name).attr("href", link(item.fileName))
				section[i].append(footer[i])
			}
		}

		// Breadcrumb
		buildBreadcrumb(breadcrumbItem)

	})

})
{'fraction_non_alphanumeric': 0.17852042273636104, 'fraction_numerical': 0.005141388174807198, 'mean_word_length': 3.607236842105263, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, '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': '7303554', 'n_tokens_mistral': 2609, 'n_tokens_neox': 2367, 'n_words': 601}