<commit_before>// Right nav highlighting
var sidebarObj = (document.getElementsByClassName("sidebar")[0]) ? document.getElementsByClassName("sidebar")[0] : document.getElementsByClassName("sidebar-home")[0];

// ensure that the left nav visibly displays the current topic
var current = document.getElementsByClassName("active currentPage");
var body = document.getElementsByClassName("col-content content");
if (current[0]) {
    if (sidebarObj) {
        current[0].scrollIntoView(true);
        body[0].scrollIntoView(true);
    }
    // library hack
    if (document.location.pathname.indexOf("/samples/") > -1) {
        $(".currentPage").closest("ul").addClass("in");
    }
}

function navClicked(sourceLink) {
    var classString = document.getElementById("#item" + sourceLink).className;
    if (classString.indexOf(" in") > -1) {
        //collapse
        document.getElementById("#item" + sourceLink).className = classString.replace(" in", "");
    } else {
        //expand
        document.getElementById("#item" + sourceLink).className = classString.concat(" in");
    }
}

var outputLetNav = [];
var totalTopics = 0;

function findMyTopic(tree) {
    function processBranch(branch) {
        for (var k = 0; k < branch.length; k++) {
            if (branch[k].section) {
                processBranch(branch[k].section);
            } else {
                if (branch[k].path === pageURL && !branch[k].nosync) {
                    thisIsIt = true;
                    break;
                }
            }
        }
    }

    var thisIsIt = false;
    processBranch(tree);
    return thisIsIt;
}

function walkTree(tree) {
    for (var j = 0; j < tree.length; j++) {
        totalTopics++;
        if (tree[j].section) {
            var sectionHasPath = findMyTopic(tree[j].section);
            outputLetNav.push('<li><a onclick="navClicked(' + totalTopics + ')" data-target="#item' + totalTopics + '" data-toggle="collapse" data-parent="#stacked-menu"')
            if (sectionHasPath) {
                outputLetNav.push('aria-expanded="true"')
            } else {
                outputLetNav.push('class="collapsed" aria-expanded="false"')
            }
            outputLetNav.push(">" + tree[j].sectiontitle + '<span class="caret arrow"></span></a>');
            outputLetNav.push('<ul class="nav collapse');
            if (sectionHasPath) outputLetNav.push(" in");
            outputLetNav.push('" id="#item' + totalTopics + '" aria-expanded="');
            if (sectionHasPath) {
                outputLetNav.push("true");
            } else {
                outputLetNav.push("false");
            }
            outputLetNav.push('">');
            var subTree = tree[j].section;
            walkTree(subTree);
            outputLetNav.push("</ul></li>");
        } else {
            // just a regular old topic; this is a leaf, not a branch; render a link!
            outputLetNav.push('<li><a href="' + tree[j].path + '"')
            if (tree[j].path === pageURL && !tree[j].nosync) {
                outputLetNav.push('class="active currentPage"')
            }
            outputLetNav.push(">" + tree[j].title + "</a></li>")
        }
    }
}

function renderNav(docstoc) {
    for (var i = 0; i < docstoc.horizontalnav.length; i++) {
        var itsHere = findMyTopic(docstoc[docstoc.horizontalnav[i].node]);
        if (itsHere || docstoc.horizontalnav[i].path === pageURL) {
            // This is the current section. Set the corresponding header-nav link
            // to active, and build the left-hand (vertical) navigation
            document.getElementById(docstoc.horizontalnav[i].node).closest("li").classList.add("active")
            walkTree(docstoc[docstoc.horizontalnav[i].node]);
            document.getElementById("jsTOCLeftNav").innerHTML = outputLetNav.join("");
        }
    }
    // Scroll the current menu item into view. We actually pick the item *above*
    // the current item to give some headroom above
    scrollMenuItem("#jsTOCLeftNav a.currentPage")
}

// Scroll the given menu item into view. We actually pick the item *above*
// the current item to give some headroom above
function scrollMenuItem(selector) {
    let item = document.querySelector(selector)
    if (item) {<commit_msg>js/docs: don't traverse full TOC if we have a direct match<commit_after>// Right nav highlighting
var sidebarObj = (document.getElementsByClassName("sidebar")[0]) ? document.getElementsByClassName("sidebar")[0] : document.getElementsByClassName("sidebar-home")[0];

// ensure that the left nav visibly displays the current topic
var current = document.getElementsByClassName("active currentPage");
var body = document.getElementsByClassName("col-content content");
if (current[0]) {
    if (sidebarObj) {
        current[0].scrollIntoView(true);
        body[0].scrollIntoView(true);
    }
    // library hack
    if (document.location.pathname.indexOf("/samples/") > -1) {
        $(".currentPage").closest("ul").addClass("in");
    }
}

function navClicked(sourceLink) {
    var classString = document.getElementById("#item" + sourceLink).className;
    if (classString.indexOf(" in") > -1) {
        //collapse
        document.getElementById("#item" + sourceLink).className = classString.replace(" in", "");
    } else {
        //expand
        document.getElementById("#item" + sourceLink).className = classString.concat(" in");
    }
}

var outputLetNav = [];
var totalTopics = 0;

function pageIsInSection(tree) {
    function processBranch(branch) {
        for (let k = 0; k < branch.length; k++) {
            if (branch[k].section) {
                processBranch(branch[k].section);
            } else {
                if (branch[k].path === pageURL && !branch[k].nosync) {
                    found = true;
                    break;
                }
            }
        }
    }

    let found = false;
    processBranch(tree);
    return found;
}

function walkTree(tree) {
    for (let j = 0; j < tree.length; j++) {
        totalTopics++;
        if (tree[j].section) {
            let sectionHasPath = pageIsInSection(tree[j].section);
            outputLetNav.push('<li><a onclick="navClicked(' + totalTopics + ')" data-target="#item' + totalTopics + '" data-toggle="collapse" data-parent="#stacked-menu"')
            if (sectionHasPath) {
                outputLetNav.push('aria-expanded="true"')
            } else {
                outputLetNav.push('class="collapsed" aria-expanded="false"')
            }
            outputLetNav.push(">" + tree[j].sectiontitle + '<span class="caret arrow"></span></a>');
            outputLetNav.push('<ul class="nav collapse');
            if (sectionHasPath) outputLetNav.push(" in");
            outputLetNav.push('" id="#item' + totalTopics + '" aria-expanded="');
            if (sectionHasPath) {
                outputLetNav.push("true");
            } else {
                outputLetNav.push("false");
            }
            outputLetNav.push('">');
            walkTree(tree[j].section);
            outputLetNav.push("</ul></li>");
        } else {
            // just a regular old topic; this is a leaf, not a branch; render a link!
            outputLetNav.push('<li><a href="' + tree[j].path + '"')
            if (tree[j].path === pageURL && !tree[j].nosync) {
                outputLetNav.push('class="active currentPage"')
            }
            outputLetNav.push(">" + tree[j].title + "</a></li>")
        }
    }
}

function renderNav(docstoc) {
    for (let i = 0; i < docstoc.horizontalnav.length; i++) {
        if (docstoc.horizontalnav[i].path === pageURL || pageIsInSection(docstoc[docstoc.horizontalnav[i].node])) {
            // This is the current section. Set the corresponding header-nav link
            // to active, and build the left-hand (vertical) navigation
            document.getElementById(docstoc.horizontalnav[i].node).closest("li").classList.add("active")
            walkTree(docstoc[docstoc.horizontalnav[i].node]);
            document.getElementById("jsTOCLeftNav").innerHTML = outputLetNav.join("");
        }
    }
    // Scroll the current menu item into view. We actually pick the item *above*
    // the current item to give some headroom above
    scrollMenuItem("#jsTOCLeftNav a.currentPage")
}

// Scroll the given menu item into view. We actually pick the item *above*
// the current item to give some headroom above
function scrollMenuItem(selector) {
    let item = document.querySelector(selector)
    if (item) {
{'fraction_non_alphanumeric': 0.14656793606017865, 'fraction_numerical': 0.0028208744710860366, 'mean_word_length': 2.46457654723127, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 31, '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': '7673627', 'n_tokens_mistral': 2425, 'n_tokens_neox': 2392, 'n_words': 534}