Search:
Template:News/Forums/Polls/Q&A > Template:News

Template:News

    Table of contents
    No headers
    /**
        Author: Blake Harms
        additional tweaks by Neil Weinstock
        version: 1.0.7
        
        HOW TO USE:
        Create a dekiscript block and add:
            bblog();
    (Tina says - I have changed bblog to News Flash and replaced instanced of 'blog' with'Notice' in the code)
        Change the page permissions to whatever you would like. But if you only want you to be able to add a post, set it to semi-public and give ONLY you permission to create.
    */
    /******************* Configurable options *********************/
    var postsPerPage = $0 ?? $postsPerPage ?? 2;                   // # of posts to show per page
    var recentNum    = $1 ?? $recentNum ?? 5;                      // # of recent posts to show in sidebar
    var commentsNum  = $2 ?? $commentsNum ?? 10;                   // # of recent comments to show in sidebar
    var categoriesNum= $3 ?? $categoriesNum ?? 5;                  // # of top categories to show in sidebar
    var path         = $4 ?? $path ?? page.path;                   // path of blog homepage
    var collapse     = $5 ?? $collapse ?? true;                    // collapse categories listings (requires CollapseItem())
    if (collapse && !#wiki.getpage("template:collapseItem")) {
        let collapse = false;
        <div style="color:red; font-weight:bold"> "NEWS FLASH ERROR: collapse option requires CollapseItem template" </div>;
    }
    /****************** /Configurable options  ********************/
    
    var startAt = __request.args.start ?? 0;
    
    <html><head>
    <style type="text/css">"
    /* main */
        #posts {    width:72%; float:left;margin-left:0%;    }
        .post {    padding-right:5px;    }
        .post .post-head a {    color:#663366!important;   }
        .post .post-subhead {     padding-left:50px;font-size:12px;    }
        .post .post-subhead .post-date {    padding:0px; margin:0px;    }
        .post .post-subhead .post-author {     padding:0px; margin:0px; font-weight:bold; font-size:14px;    }
        .post .post-subhead .post-author a {     color:#999999;    }
        .post .post-body {    padding:15px;    }
        .post .post-footer .post-edited {    font-style:italic; color: #AAA; padding:10px;    }
        .post .post-footer .post-links a {    padding-right:20px;    }
        .post .post-footer .post-tags a {    padding-right: 5px; color:black !important;    }
    /* sidebar */
        #notice-sidebar {    float:right; width:25%;    }
        #notice-sidebar {    border-left: 2px solid black; padding-left:2%; padding-bottom:21px;    }
        #notice-sidebar ul {    margin-top:5px; list-style-type:none; padding-left:20px;    }
    /* paginate */
        #paginator {    padding:15px; clear:both;    }
        #paginator a.paginate-previous {    float:left; text-align:left;    }
        #paginator a.paginate-next {    float:right; text-align:right;    }
    "</style>
    </head></html>
    var homepage = wiki.getpage(path);
    var allNotice = list.sort([ p foreach var p in homepage.subpages ], _, true, "date.compare($left.date,$right.date)");
    var notice = allNotice;
    if(startAt > 0){
        if(startAt < #notice){
            let notice = List.splice(notice, 0, startAt);
        }
    }
    wiki.create("Post New Item",path,_,true,"Item No." .. #allNotice);
    <div id="notice-body">
        <div id="posts">
        if(#notice> 0){
            var shown = 0;
            foreach(var p in notice where __index < postsPerPage) {
            <div class="post">
                <div class="post-head">
                     <h2> web.link(p.uri, p.title)</h2>
                                                          /* <h2> p.title</h2>
                                                                                */
                </div>
                <div class="post-subhead">
                    "by ";
                    <span class="post-author">
                        var author= p.revisions[0].author;
                        /*web.link(author.homepage.uri, author.name);
                                                                      */         
                       author.name</span>
                    " on ";
                    <span class="post-date">
                        p.revisions[0].date;
                    </span>
                </div>
                <div class="post-body">
                    wiki.page(p.path);
                </div>
                <div class="post-footer">
                    if(#p.revisions >1){
                        <div class="post-edited">
                            "Last Edited: "..p.date .. " ";
                            "by ";
                            /*web.link(p.author.homepage.uri, p.author.name);
                                                                              */
                            p.author.name;
                                      
                            </div>
                    }
                    <div class="post-links">
                        web.link(p.uri.."#comment", "Comments ("..#p.comments..")");
                        web.link(p.uri, "Views: "..p.viewcount);
                    </div>
                    if(#p.tags >0) {
                    <div class="post-tags">
                        "Tags: ";
                        var tags = Map.keys(p.tags);
                        foreach(var tag in tags){
                            web.link(site.uri & "/Special:Tags" & {tag:tag}, tag);
                        }
                    </div>
                    }
                </div>
            </div>
                let shown+=1;
            }
        }
        else {
            "No posts";
        }
            <div id="paginator">
            if(startAt > 0){
                var previous = 0;
                if(startAt - postsPerPage > 0){
                    let previous = startAt - postsPerPage;
                }
                <a href=(uri.build(page.uri,_,{start:previous})) class="paginate-previous"> "<Previous"</a>
            }
            if(startAt + postsPerPage <= #homepage.subpages -1){
                var next = startAt + postsPerPage;
                <a href=(uri.build(page.uri,_,{start:next})) class="paginate-next"> "Next>"</a>
            }
            </div>
        </div>
        <div id="notice-sidebar">
            <div id="recentPosts">
                <h3><span style="color:#663366;">"Recent Posts"</span></h3>
                <ul>
                    if(#allNotice> 1) {
                        foreach(var post in allNotice where __index < recentNum){
                            <li> web.link(post.uri, post.title) </li>
                        }
                    }
                    else {
                        <li>"No recent posts."</li>
                    }
                </ul>
            </div>
            <div id="recentComments">
                <h3><span style="color:#663366;">"Recent Comments"</span></h3>
                var comments= [];
                foreach(var p in allNotice) {
                    let comments ..= [ c..{ number:__index+1 } foreach var c in p.comments ];
                }
                if(#comments != 0) {
                    let comments = list.sort(comments, _, true, "date.compare($left.date, $right.date)");
                    <ul>
                        foreach (var c in comments where __index < commentsNum) {
                            <li>
                                web.link(c.page.uri, c.page.title);
                                " ("; web.link(c.page.uri & ("#comment"..c.number), c.number); ")";
                            </li>;
                        }
                    </ul>;
                }
            </div>
            <div id="cagtegories">
                <h3><span style="color:#663366;">"Top Categories"</span></h3>
                // Get subpages tags. Credit: SteveB (TagDirectory)
                var tagmap = { }; 
                var tag_count = [ ];
                foreach(var p in allNotice) { 
                    var tags = p.tags; 
    
                    // check if page has no tags; if so make up a default list
                    if(!#tags) {
                        let tags = [ { name: '(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
                    foreach(var tag in map.keys(tagmap)) { 
                        let tag_count ..= [ { 'tag': tag, 'count': #tagmap[tag] } ]; 
                    } 
                }
                let tag_count = List.splice(List.Sort(tag_count, 'count',true),categoriesNum);
                <ul>
                    foreach(var category in tag_count){
                        <li>
                            if (collapse) {
                                var id = "categoryList_"..@id.."_"..__index;
                                collapseItem(id, category.tag, category.tag, "slide");
                                " ("..category.count..")";
                                <ul id=(id)>
                                    foreach (var cp in tagmap[category.tag])
                                        <li> web.link(cp.uri, cp.title) </li>;
                                </ul>;
                            }
                            else {
                                <a href=("/Special:Tags?tag=" .. category.tag)> category.tag </a>;
                                " ("..category.count..")";
                            }
                        </li>;
                    }
                </ul>;
            </div>;
        </div>;
    </div>;

    Files (0)

     

    Comments (0)

    You must login to post a comment.