Last active
August 29, 2015 13:56
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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