2 of 2 found this page helpful

List Newest Pages or Changes

     

    Introduction

    This template will provide you will the newest items within a given path.  It allows you to control the number of items returned, as well as how deep to drill down the tree.  This template will also count comments as changes if desired.  

    NOTE:  This was one of my first templates that I built and can be improved.  I will update page this with ver. 2 soon.  I will likely incorporate a page viewed ranking within the same template as well.

    PERFORMANCE:  For best performance it is a good idea to keep your max results and depth as small as needed.

    History

    Version Date Author Description
    1.3.1 27/07/2010 neilw Put in a small check to avoid throwing an error if a page is unreadable (don't know why this should be necessary, but apparently it is)
    1.3 19/03/2010 neilw Use @pageid to extract page list from wiki.tree(), for more reliable handling of pages with special characters in their names
    1.2 28/08/2009 rberinger Change from using div id's to div classes for css.  Added ability to order pages by original creation date.
    1.1 27/08/2009 rberinger Optimized Code, Added: Styles, Date Formating, Div Containers 
     1.0 22/05/2009  rberinger  Initial template 

    Requirements

    • This template requires Mindtouch Deki Version: This is pure dekiscript and I believe should work on all recent versions.  I have only tested this on Lyons.

    How do I install it?

    1. Create a template, call it "Template:WhatsNew" (or rename as you desire).  You must have "unsafecontent" permission for this to work.
    2. Create a "Dekiscript" block on the template page (use the "Style" menu in the editor")
    3. Copy the code from the end of this page and paste it into the Dekiscript block.  To copy, click "expand source", then mouse over the top right corner of the source code, and click the "view source" button.  This will pop up a window with the source code.  Select all, then copy to clipboard.
    4. Make sure there isn't an extra blank paragraph after the Dekiscript block! Do this every time you edit!!!  
    5. Save.

     

    A quick note about the examples on this page

    For all the examples on this page, the code is shown before the working example.  The code is shown with the syntax extension, and looks like this:

    WhatsNew{arguments}

    This means that the actual code on the page should be enclosed in a Dekiscript block.  If you want to copy the code from this page, then use the same procedure as described in steps 2-4 above. 

    How do I use it?

     Simply create a dekiscript block where you would like to have the Whats New list appear and make a call to the template.  See the example below.

    Arguments

    Name Type Default Description
     title str  Whats New!  This string will become the title of the results 
     path str  page.path 

    The path to serve as the starting point 

    max num 10 The maximum number of results to display
    depth num 10 The tree depth to look for pages (just like wiki.tree) 
    comments bool true Test comment dates against page dates.
    dateformat str 'MM/dd/yyyy' Any valid date format mask.
    blockstyle str See Template Any valid in-line css.  Controls container that wraps entire template
    titlestyle str See Template Any valid in-line css. Control Title Section
    bodystyle str See Template Any valid in-line css. Controls the body or content section.
    onlynew bool false If true will only evaluate pages by their original creation date.  This provides a true newest pages list not just a newest updated list.  NOTE:  If set to true the comments argument is ignored as well as the page edited date.

    Examples

    The following example limits the results to the top 5 newly updated or created pages (including comments).  The styling also shrinks the template and centers within the container.

    WhatsNew {
        title: 'New or updated App Catalog entries with comments',
        path: 'app catalog',
        max: 5,
        depth: 1, 
        dateformat: 'MM/dd/yyyy',
        blockstyle: 'width:50%; margin: 0 auto;',
        titlestyle: 'background-color: rgb(234, 234, 234);text-align: center;padding: 2px;font-weight: bold;font-size: 16px;border-style: outset;'
    }
    New or updated App Catalog entries with Comments
    Hover Popup Navigation - Comment Added on: 05/16/2012
    Tab/Accordion Template - Page Edited on: 04/26/2012
    Highcharts - a wrapper for the Highcharts JavaScript graphing package - Comment Added on: 03/26/2012
    Skype - Page Edited on: 03/10/2012
    TsTable: Sortable, Paginated, and Zebrified Tables + flexible table generator - Comment Added on: 02/28/2012

     

     

    The following example limits the results to the top 10 newly updated or created pages (NOT including comments) and will evaluate pages down 2 levels from the start page.

    WhatsNew {
        title: 'New or updated App Catalog entries no comments',
        path: 'app catalog',
        max: 10,
        depth: 2,
        comments: false,
        titlesyle: 'background-color: rgb(234, 234, 234);text-align: center;padding: 2px;font-weight: bold;font-size: 16px;border-style: outset;'
    }
    New or updated App Catalog entries no comments
    Tab/Accordion Template - Page Edited on: 04/26/2012 11:37:02
    Graphviz with URIs - Page Edited on: 04/20/2012 08:58:39
    Skype - Page Edited on: 03/10/2012 01:49:38
    data - Page Edited on: 02/20/2012 12:05:51
    SectionUI: Transform the UI of sections on a page (tab and accordion styles) - Page Edited on: 12/08/2011 04:42:50
    Simple Blog - Page Edited on: 12/01/2011 01:12:42
    Integrated Bug and Issue Tracker - Page Edited on: 12/01/2011 11:46:51
    HideElements: Selectively Hide Page Elements (tags, files, images, comments, ratings) - Page Edited on: 11/18/2011 09:33:21
    Collapsible Table of Contents - Page Edited on: 10/13/2011 07:57:28
    test - Page Edited on: 10/03/2011 10:56:08

     

     

    The following example limits the results to the top 10 newly created pages and will evaluate pages down 2 levels from the start page.

    WhatsNew {
        title: 'Newest App Catalog entries',
        path: 'app catalog',
        max: 10,
        depth: 2,
        onlynew: true,
        titlesyle: background-color: rgb(234, 234, 234);text-align: center;padding: 2px;font-weight: bold;font-size: 16px;border-style: outset;'
    }
    Newest App Catalog entries
    Skype - Page Created on: 03/10/2012 01:49:38
    test - Page Created on: 10/03/2011 10:56:08
    hide page ratings - Page Created on: 03/22/2011 08:30:28
    aaxis manual - Page Created on: 12/15/2010 12:33:27
    Bar charts on Chrome - Page Created on: 10/12/2010 09:19:33
    PrettyPrint - nicely display DekiScript data structures - Page Created on: 10/01/2010 02:54:49
    Highcharts - a wrapper for the Highcharts JavaScript graphing package - Page Created on: 09/28/2010 08:48:55
    Multipoll - Page Created on: 08/30/2010 12:36:05
    Methodology - Page Created on: 08/28/2010 06:09:01
    ToDo Rullup - Page Created on: 07/26/2010 10:00:50

    Reference(s)

     None.

    Credits/Special Thanks

    Everyone in the MindTouch Community Forum

     Template/Extension Source Code

    /* WARNING
     * WARNING: this community-contributed template is not fit for production use as it performs a complete db-scan with every invocation
     * WARNING
     */
    
    // Parameters:
    //   title: The title text
    //   Path:  path to the starting page
    //   max:  Maximum number of items to list
    //   comments:  Include comment date when checking for newest changes
    //   dateformat:  Date Format mask
    //   blockstyle:  Any valid styling.  The entire template is wrapped in this template
    //   titlestyle:  Any valid styling.  This controls the title area of this template
    //   bodystyle:  Any valid styling.  This control the content or body of this template
    //   onlynew:  Only list the newest pages by original creation date.
    
    /*
      In a dekiscript block:
        whatsnew2{ title: 'testing', 
                   path: '/resources', 
                   max: 5, 
                   depth: 1, 
                   comments: true, 
                   dateformat:'MM/dd/yyyy'
                 };
    
    Vesion History: 1.0 - Initial release
                    1.1 - Optimized code, added: Styles, DateFormat Options, Div Containers
                    1.2 - Changed from using div id's to div classes
                          Added the ability to order pages by original creation date
                    1.3 - (neilw) switched to using @pageid to look up pages
    */
    
    var title = ($0 ?? args.title ?? 'Whats New!');
    var path = ($1 ?? args.path ?? page.path);
    var maxnum = ($2 ?? args.max ?? 10);
    var depth = ($3 ?? args.depth ?? 10);
    var tstcmts = ($4 ?? args.comments ?? true);
    var dteformat = ($5 ?? args.dateformat ?? 'MM/dd/yyyy hh:mm:ss');
    var blockstyle = ($6 ?? args.blockstyle ?? 'width:100%');
    var titlestyle = ($7 ?? args.titlestyle ?? 'background-color: rgb(234, 234, 234);text-align: center;padding: 2px;font-weight: bold;font-size: 16px;border-style: outset;');
    var bodystyle = ($87 ?? args.bodystyle ?? 'background-color: #FFF;padding: 2px;border-style: solid;border-width: 1px;text-align: left;');
    var onlynew = ($9 ?? args.onlynew ?? false);
    
    
    var cmtdte = '';
    var pagedte='';
    var latestdte='';
    var lst = [];
    var cmtoredit = '';
    
    var pxml = wiki.tree(path,depth);
       foreach(var pid in xml.list(pxml, "//a/@pageid")) {
          let p = wiki.getpage(num.cast(pid));
          let pagedte = p.date;
          if (pagedte is nil) continue;
    
          if(onlynew == false) {
             if(tstcmts == true) {
                let cmtdte = (p.comments[#p.comments-1].date ?? p.date);
                // let latestdte = ((date.format(p.date,'s') > date.format(cmtdte,'s')) ? p.date : cmtdte);
                // let cmtoredit = ((date.format(p.date,'s') >= date.format(cmtdte,'s')) ? 'p' : 'c');
    
                let latestdte = ((date.compare(p.date, cmtdte) >=0 ) ? p.date : cmtdte);
                let cmtoredit = ((date.compare(p.date, cmtdte) >=0 ) ? 'p' : 'c');
    
             } else {
                let latestdte = date.format(p.date,'s');
                let cmtoredit = 'p';
             }
    
             let latestdte = ((date.isvalid(latestdte) == 'true') ? date.format(latestdte, 's') : '01/01/2099');
             let lst ..=[ {uri: p.uri, path: p.path, title: p.title, pagedate: pagedte, cmtdate: cmtdte, latestdate: latestdte, pgorcmt: cmtoredit } ];
          } else {
             let lst ..=[ {uri: p.uri, path: p.path, title: p.title, pagedate: p.date, latestdate: date.format(p.revisions[0].date,'s'), pgorcmt: 'n' } ];
          }
       }
    
    let lst = list.sort(lst, 'latestdate', true);
    <div class="whtsnew" style=(blockstyle)>
      <div class="whtsnewttl" style=(titlestyle)>
       title;
      </div>
    
      <div class="whtsnewbdy" style=(bodystyle)>
        foreach(var p in lst) {
          if(__count >= maxnum) {break;}
     
          if(p.uri) {
    
           if(onlynew == false) {
              web.link(p.uri, p.title); <span style="font-size: xx-small;">;' - ' ..((p.pgorcmt == 'p') ? ' Page Edited on: ' : ' Comment Added on: ') ..date.format(p.latestdate, dteformat); </span> <br/>;
           } else { 
              web.link(p.uri, p.title); <span style="font-size: xx-small;">;' - ' ..' Page Created on: ' ..date.format(p.latestdate, dteformat); </span> <br/>;       
           }
    
          }
    
        }
      </div>
    </div>
    
    // styles
    <html>
       <head>
          <style type="text/css">"
    
              div.whtsnew {
                 width: 100%;
             }
    
              div.whtsnewttl {
                 background-color: rgb(234, 234, 234);
                 text-align: center;
                 padding: 2px;
                 font-weight: bold;
                 font-size: 16px;
                 border-style: outset; 
              }
        
              div.whtsnewbdy {
                 background-color: #FFF;
                 padding: 2px;
                 border-style: solid;
                 border-width: 1px;
                 text-align: left;
              }
           "
           </style>
       </head>
    </html>

     

    Disclaimers

    None.

    Was this page helpful?
    Tag page
    Viewing 15 of 20 comments: view all
    Send me what you have and I'll take a look. Better performance is always welcome. The time zones are unchanged so should be GMT. It would be fairly trivial to update to users timezone if they have it set.

    Oh yeah... Thank you for your kind comments. edited 10:40, 31 Aug 2009
    Posted 10:37, 31 Aug 2009
    I put the API feed info in the forum thread, I can't use the code style in the comments and it doesn't belong in the wiki page unless you actually use it.
    Posted 11:46, 31 Aug 2009
    @rberinger I don't know why, but the script is not working on the root page! I get the following failure: function date.compare failed.
    On every other page the template is working! edited 04:31, 17 Dec 2009
    Posted 01:09, 15 Dec 2009
    @SeGo I will have to take a look. Can you provide a sample on how your calling the Template please so I can recreate.
    Posted 07:26, 17 Dec 2009
    @rberinger I made a template and then just tried different calls:

    {{NewPages()}}
    {{NewPages{title: 'Newest Pages', max: 6, depth: 4, path:page.parent.path}}}

    I tried it also from a different page with the following:
    NewPages{title: 'Newest Pages', path:''}

    All of them with the message: /content/body/pre, function 'date.compare' failed (click for details)
    Posted 02:30, 21 Dec 2009
    I have modified the style to match the wiki and it looks really cool! This is gonna be useful..Thanks for this and the 'popular pages' one!
    Posted 07:56, 16 Feb 2010
    I'm getting the same date.compare failed error. No error when setting the depth to 1 but then upping it to 2 or higher gives the error. Did anyone find a way around this?
    Posted 08:14, 8 Mar 2010
    @jlpp @SeGo
    The "date.compare" failure should be fixed now with the new version. Give it a try.
    Posted 05:54, 19 Mar 2010
    @neilw - PagesMonitor can manage all this functionality, just:

    {{ PagesMonitor{favorites:false, paths:[ "path to monitor"]} }} edited 07:10, 19 Mar 2010
    Posted 07:10, 19 Mar 2010
    There doesn't appear to be any source code on the page. The expanding Source Code just has ten lines of code comments.
    Posted 14:29, 28 May 2010
    Hi, The source code is MISSING..! Please fix!
    Posted 00:52, 2 Jun 2010
    Hi, The source code is MISSING..! Please fix!
    Posted 00:57, 2 Jun 2010
    @orangechicken @MikeOwen @tdrealizer
    Source code is back, sorry about that folks.
    Posted 11:21, 17 Jun 2010
    Thanks!
    Posted 12:42, 17 Jun 2010
    I also got the "function date.compare failed" error. It seems to happen with pages and/or users with "view" permission.
    Posted 12:51, 26 Jun 2010
    Viewing 15 of 20 comments: view all
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by