Template:TagDirectory

    Tabla de contenidos
    No hay encabezados
    /***
        USAGE:
    
        TagDirectory() 
            build a two-column tag directory for the immediate sub-pages of the current page.
    
        TagDirectory(UNCLASSIFIED_CAPTION,PATH)
            build a two-column tag directory for the page at PATH.
    ***/
    
    var basepath = $0 ?? $path;
    var base = basepath ? wiki.getpage(basepath) : page;
    
    //new
    var lang=Culture.Iso2Code(Page.Language);
    var loc_unclassified='', loc_views='';
    if (lang == 'en')
    {
        let loc_unclassified='untagged';
        let loc_views='views';
    }
    else if (lang == 'eu')
    {
        let loc_unclassified='etiketatu gabea';
        let loc_views='ikustaldi';
    }
    else if (lang == 'es')
    {
        let loc_unclassified='sin etiquetar';
        let loc_views='visitas';
    }
    else if (lang == 'fr')
    {
        let loc_unclassified='sans etiqueter';
        let loc_views='visites';
    }
    
    // build map of all tags in subpages
    var tagmap = { }; 
    foreach(var p in base.subpages) { 
        var tags = p.tags; 
    
        // check if page has no tags; if so make up a default list
        if(!#tags) {
            //mod
            let tags = [ { name: '('..loc_unclassified..')', type: 'text' } ];
        }
    
        // foreach tag on the page, append the page to that tag's list
        foreach(var t in tags where t.type == 'text') {
            let tagmap ..= { (t.name) : tagmap[t.name] .. [ p ] };
        } 
    }
    if(#tagmap) {
    
        // count how many pages each tag has
        var tag_count = [ ]; 
        foreach(var tag in map.keys(tagmap)) { 
            let tag_count ..= [ { tag: tag, count: #tagmap[tag] } ]; 
        } 
    
        // balance the left and right columns so that the columns are as equal in height as possible
        var left_tags = []; 
        var left_tags_sum = 0; 
        var right_tags = []; 
        var right_tags_sum = 0; 
        foreach(var t in list.sort(tag_count, 'count', true)) { 
            if(left_tags_sum > right_tags_sum) { 
                let right_tags_sum += t.count; 
                let right_tags ..= [ t.tag ]; 
            } else { 
                let left_tags_sum += t.count; 
                let left_tags ..= [ t.tag ]; 
            } 
        }
    
        // emit the table with the two columns
        <table width="100%" cellspacing="0" cellpadding="5" border="0" style="table-layout: fixed;">
            <tr valign="top">
                <td style="padding-right: 20px;">
                    foreach(var tag in list.sort(left_tags)) {
                        <h5>string.tocamelcase(tag)</h5>
                        var pages = list.sort(tagmap[tag], 'viewcount', _, '$right - $left');
                        <ul>
                            foreach(var p in pages) {
                                <li>
                                    <span style="font-size: small;">web.link(p.uri, string.startswith(p.title, 'How do I... ', true) ? string.substr(p.title, 12) : p.title)</span>
                                    <span style="color: rgb(128, 128, 128); font-size: small;">' (' .. num.format(p.viewcount, '#,##0') .. ' ' .. loc_views .. ')'</span>
                                </li>
                            }
                        </ul>
                    }
                </td>
                <td style="padding-right: 20px;">
                    foreach(var tag in list.sort(right_tags)) {
                        <h5>string.tocamelcase(tag)</h5>
                        var pages = list.sort(tagmap[tag], 'viewcount', _, '$right - $left');
                        <ul>
                            foreach(var p in pages) {
                                <li>
                                    <span style="font-size: small;">web.link(p.uri, string.startswith(p.title, 'How do I... ', true) ? string.substr(p.title, 12) : p.title)</span>
                                    <span style="color: rgb(128, 128, 128); font-size: small;">' (' .. num.format(p.viewcount, '#,##0') .. ' ' .. loc_views .. ')'</span>
                                </li>
                            }
                        </ul>
                    }
                </td>
            </tr>
        </table>
    }
    

     

    Etiquetas (Edit tags)
    • No tags
    Debe inicie sesión para enviar un comentario.