<commit_before>function ddg_spice_news(api_result) {
    "use strict";

    // Words that we have to skip in DDG.isRelevant.
    var skip = [
        "news",
        "headline",
        "headlines",
        "latest",
        "breaking",
        "update",
        "s:d",
        "sort:date"
    ];

    // Check if the word news is in the query.
    var generic = false;
    if((/\bnews\b/i).test(DDG.get_query())) {
        generic = true;
    }

    // Some sources need to be set by us.
    var getSource = function(story) {
        switch(story.syndicate) {
            case "Topsy":
            story.source = story.author || "Topsy";
            break;
            case "NewsCred":
            story.source = story.source + " by " + story.author;
            break;
        }
    };

    for(var i = 0, story; story = api_result[i]; i++) {
	story.title = story.title.replace(/<b>|<\/b>|:/g, "");
	var words = story.title.split(" ");

	// Limit the number of chars to 55.
	var result = [];
	var count = 0;
	for(var j = 0; j < words.length; j++) {
	    count += words[j].length + 1;
	    if(count < 55) {
		result.push(words[j]);
	    }
	}

	if(words.length > result.length) {
	    result.push("...");
	}

	story.title = result.join(" ");
    }

    var good_stories = [];
    if(generic) {
        good_stories = api_result;
    } else {
        for(var i = 0, story; story = api_result[i]; i++) {
            if(DDG.isRelevant(story.title, skip, 3)) {
                getSource(story);
                good_stories.push(story);
            }
        }
    }

    // Exit if we didn't get any results.
    if(good_stories.length === 0) {
        return;
    }

    // Limit the number of stories to 5.
    // good_stories.splice(5);

    // Display the plugin.
    Spice.render({
        header1: good_stories[0].query +  " (News)",
	source_url: good_stories[0].url,
	source_name: good_stories[0].source,

	spice_name: "news",

	template_frame: "carousel",
	template_options: {
	    items: good_stories,
	    template_item: "news",
	    li_width: 196,
	    li_height: 155
	},

	force_big_header: true,
	force_no_fold: true
    });
}

Handlebars.registerHelper("getIcon", function(url) {
    return Handlebars.helpers.favicon.call({source_url: url, forces: {}});
});

Handlebars.registerHelper("getDomain", function(url) {
    re = new RegExp('^.*?\/\/([^\/\?\:\#]+)');
    if(re.test(url)) {
	return RegExp.$1;
    }
});

Handlebars.registerHelper("getTime", function(relative_time) {
    relative_time = relative_time.match(/([0-9]+)([a-z]+).*/);
    console.log(relative_time);
    if(+relative_time[1] > 1) {
	return relative_time[1] + " " + (relative_time[2] === "hr" ? "hrs" : "mins");
    }
    return relative_time[1] + " " + relative_time[2];
});
<commit_msg>News: Trimmed the excerpt.<commit_after>function ddg_spice_news(api_result) {
    "use strict";

    // Words that we have to skip in DDG.isRelevant.
    var skip = [
        "news",
        "headline",
        "headlines",
        "latest",
        "breaking",
        "update",
        "s:d",
        "sort:date"
    ];

    // Check if the word news is in the query.
    var generic = false;
    if((/\bnews\b/i).test(DDG.get_query())) {
        generic = true;
    }

    // Some sources need to be set by us.
    var getSource = function(story) {
        switch(story.syndicate) {
            case "Topsy":
            story.source = story.author || "Topsy";
            break;
            case "NewsCred":
            story.source = story.source + " by " + story.author;
            break;
        }
    };

    var ellipsis = function(text, limit) {
	var result = [];
	var count = 0;
	var words = text.split(" ");

	for(var i = 0; i < words.length; i++) {
	    count += words[i].length + 1;
	    if(count < limit) {
		result.push(words[i]);
	    }
	}

	if(words.length > result.length) {
	    result.push("...");
	}	   

	return result.join(" ");
    };

    for(var i = 0, story; story = api_result[i]; i++) {
	story.title = story.title.replace(/<b>|<\/b>|:/g, "");

	story.title = ellipsis(story.title, 55);
	story.excerpt = ellipsis(story.excerpt, 140);
    }

    var good_stories = [];
    if(generic) {
        good_stories = api_result;
    } else {
        for(var i = 0, story; story = api_result[i]; i++) {
            if(DDG.isRelevant(story.title, skip, 3)) {
                getSource(story);
                good_stories.push(story);
            }
        }
    }

    // Exit if we didn't get any results.
    if(good_stories.length === 0) {
        return;
    }

    // Limit the number of stories to 5.
    // good_stories.splice(5);

    // Display the plugin.
    Spice.render({
        header1: good_stories[0].query +  " (News)",
	source_url: good_stories[0].url,
	source_name: good_stories[0].source,

	spice_name: "news",

	template_frame: "carousel",
	template_options: {
	    items: good_stories,
	    template_item: "news",
	    li_width: 196,
	    li_height: 155
	},

	force_big_header: true,
	force_no_fold: true
    });
}

Handlebars.registerHelper("getIcon", function(url) {
    return Handlebars.helpers.favicon.call({source_url: url, forces: {}});
});

Handlebars.registerHelper("getDomain", function(url) {
    re = new RegExp('^.*?\/\/([^\/\?\:\#]+)');
    if(re.test(url)) {
	return RegExp.$1;
    }
});

Handlebars.registerHelper("getTime", function(relative_time) {
    relative_time = relative_time.match(/([0-9]+)([a-z]+).*/);
    console.log(relative_time);
    if(+relative_time[1] > 1) {
	return relative_time[1] + " " + (relative_time[2] === "hr" ? "hrs" : "mins");
    }
    return relative_time[1] + " " + relative_time[2];
});

{'fraction_non_alphanumeric': 0.17073602264685067, 'fraction_numerical': 0.011500353857041755, 'mean_word_length': 2.2432587492828455, 'pattern_counts': {'":': 4, '<': 11, '<?xml version=': 0, '>': 11, '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': '205778', 'n_tokens_mistral': 2091, 'n_tokens_neox': 1973, 'n_words': 400}