Skip to content

Instantly share code, notes, and snippets.

@grantmacken
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grantmacken/9084989 to your computer and use it in GitHub Desktop.
Save grantmacken/9084989 to your computer and use it in GitHub Desktop.
Xquery 3 function that uses 'group by' to list entries by year month day
declare
function post:archive-feed($node as node(), $model as map(*)) {
let $itemCount := function( $seq ){
if( count( $seq ) eq 1 )
then( string(count( $seq )) || ' post')
else( string(count( $seq )) || ' posts') }
let $getMonth := function( $month ){
('January', 'February', 'March', 'April', 'May', 'June','July', 'August', '
September', 'October', 'November', 'December')[$month]
}
let $seqItem := for $item in collection($model('data-posts-path'))//atom:entry
group by $year := year-from-dateTime($item/atom:published)
order by $year descending
return <div><strong>{$year}</strong>: {count($item)} posts
<div>{
for $itm in $item
group by $month := month-from-dateTime($itm/atom:published)
order by $month descending
return
<div> <strong>{$getMonth($month)}</strong>: {$itemCount($itm)}
{
for $i in $itm
order by day-from-dateTime($i/atom:published) descending
return
<article class="h-entry h-as-{post:getPostType($i)}">
<div>
{post:getTitle($i)}
</div>
{post:getDivPublishedDate($i)}
<div class="e-summary">
{post:getSummary($i) }
</div>
</article>
}
</div>
}</div>
</div>
return
<section id="main" role="main">
{$seqItem}
</section>
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment