/***
PageDirectory
creates a searchable directory of pages organized by tabs and filtered by tags
Arguments:
path : str (optional, default: currnt page path)
page path the the parent page where the subpages to be organized are located
most_popular : map (optional, default: none)
show section for most popular pages that have a given tag
tag : str
tag to used for the split between left and right columns for most popular;
left pages have the tag, right pages do not
title : str
title shown for left column
tabs : list (optional, default: empty list)
list of maps describing each tab to show; map entries may contain the following fields
label : str
label for the tab
key : str
key used to identify the selected tab
featured_limit : num (optional, default: 15)
number of pages to show in the "Featured" category
cache_prefix : str (optional, default: none)
when set, caches the page directory for a given view using this key
tag_constraint : str -or- list (optional, default: none)
only list pages that have all of the specified tags
***/
// read parameters
var path = $path ?? page.path;
var most_popular = $most_popular;
var tabs = $tabs ?? [ ];
var featured_limit = $featured_limit ?? 15;
var cache_prefix = $cache_prefix;
var tag_constraint = $tag_constraint;
// check how the current page is being invoked
var query = __request.args.q;
var view = __request.args.v ?? (query ? 'search' : 'featured');
// define variables
var label_featured = 'View Featured';
var render;
var cache_id;
var pages;
var constraint = 'type:wiki AND path:' .. string.searchescape(path) .. '*';
if(tag_constraint is str) {
let constraint ..= ' AND tag:"' .. string.escape(tag_constraint) .. '"';
} else if(tag_constraint is list) {
let constraint ..= ' AND ' .. string.join([ ' AND tag:"' .. string.escape(tag) .. '"' foreach var tag in tag_constraint where tag is str ], ' AND ');
}
// check if a search was requested
if(query) {
if(path[-1] != '/') {
let path = path .. '/';
}
let pages = wiki.getsearch(query, 1000, _, constraint);
} else {
let pages = wiki.getsearch(constraint, 1000);
if(cache_prefix) {
let cache_id = cache_prefix .. '-cache-' .. view;
let render = webcache.fetch(cache_id);
}
}
<p> "There are "; num.format(#pages, "#,##0"); " entries." </p>;
if(!render) {
let render = (
<p> string.nbsp </p>
// remove pages starting with '*'
let parent_page = wiki.getpage(path);
let pages = [ p foreach var p in pages where !string.startswith(p.name ?? '', '*') && p.parent.id == parent_page.id ];
// show directory based on current views
<table width="100%" cellspacing="0" cellpadding="0" border="1">
<tr>
<td>
if(view == 'featured') {
<strong> label_featured </strong>;
} else {
web.link(page.uri, label_featured);
}
</td>
foreach(var tab in tabs) {
<td>
if(view == tab.key) {
<strong> tab.label </strong>;
} else {
web.link(page.uri & { v: tab.key }, tab.label);
}
</td>
}
<td>
<form method="get" action=(page.uri)>
if(view == 'search') <strong> 'Search: ' </strong>; else 'Search: ';
<input name="q" type="text" value=(query ?? '') />
<input type="submit" value="Go" />
</form>
</td>
</tr>
</table>
switch(view) {
case 'featured':
// show 'Most Popular' and 'Recently Added' entries
<table width="100%" cellspacing="0" cellpadding="5" border="0" style="table-layout: fixed;">
if(most_popular && most_popular.tag && most_popular.title) {
<tr valign="top">
<td>
<h3> "Most Popular - " .. most_popular.title; </h3>
ListPages{ pages: [ p foreach var p in pages where p.tags[most_popular.tag] is not nil ], sort: 'viewcount', reverse: true, limit: featured_limit, style: 'bullets' }
</td>
<td>
<h3> "Most Popular - Other" </h3>
ListPages{ pages: [ p foreach var p in pages where p.tags[most_popular.tag] is nil ], sort: 'viewcount', reverse: true, limit: featured_limit, style: 'bullets' }
</td>
</tr>
}
<tr valign="top">
<td>
<h3> "Recently Added"</h3>
ListPages{ pages: pages, sort: 'created', reverse: true, limit: featured_limit, style: 'bullets' }
</td>
<td>
<h3> "Recently Updated"</h3>
ListPages{ pages: pages, sort: 'updated', reverse: true, limit: featured_limit, style: 'bullets' }
</td>
</tr>
</table>
case 'search':
<h3> "Search Results" </h3>
ListPages{ pages: pages, sort: 'viewcount', reverse: true };
default:
<h3> "Directory by "; string.tocamelcase(view) </h3>
TagDirectory{ pages: pages, tagprefix: view, columns: 3, listpagesoptions: { sort: 'title', reverse: false } }
}
<br/><hr/><br/>
);
if(cache_id) {
webcache.store(cache_id, render);
} else {
render;
}
} else {
render;
}
| Images 0 | ||
|---|---|---|
| No images to display in the gallery. |
Copyright © 2011 MindTouch, Inc. Powered by