-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
news.xql
58 lines (50 loc) · 2.51 KB
/
news.xql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
xquery version "3.0";
declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization";
declare namespace wiki="http://exist-db.org/xquery/wiki";
declare namespace atom="http://www.w3.org/2005/Atom";
declare option output:method "html5";
declare option output:media-type "text/html";
import module namespace http = "http://expath.org/ns/http-client";
declare variable $local:WIKI_ROOT := "https://exist-db.org/exist/apps/wiki";
declare variable $local:FEED := "/blogs/eXist/";
declare variable $local:LAST_ENTRIES := $local:WIKI_ROOT || "/atom" || $local:FEED || "?count=3";
response:set-header("Cache-Control", "no-cache"),
let $request := <http:request method="GET" href="{$local:LAST_ENTRIES}"/>
let $response := http:send-request($request)
let $entries :=
for $entry in $response[2]//atom:entry
let $date := ($entry/atom:updated, $entry/atom:published)[1]
order by xs:dateTime($date) descending
return $entry
return
<ul class="news" style="display:none;">
{
for $entry in subsequence($entries, 1, 3)
let $dateStr := ($entry/atom:updated, $entry/atom:published)[1]
let $date := xs:dateTime($dateStr/text())
let $age := current-dateTime() - $date
let $minutesSince := minutes-from-duration($age)
let $hoursSince := hours-from-duration($age)
let $daysSince := days-from-duration($age)
let $path := $local:WIKI_ROOT || $local:FEED || substring-after(util:collection-name($entry), "/db/apps/wiki/data")
return
<li>
<div class="date">
{
if ($age < xs:dayTimeDuration("PT1H")) then
let $minutes := if ($minutesSince = 1) then ' minute' else ' minutes'
return $minutesSince || $minutes || " ago"
else if ($age < xs:dayTimeDuration("P1D")) then
let $hours := if ($hoursSince = 1) then ' hour' else ' hours'
return $hoursSince || $hours || " ago"
else if ($age < xs:dayTimeDuration("P14D")) then
let $days := if ($daysSince = 1) then ' day' else ' days'
return $daysSince || $days || " ago"
else
format-dateTime($date, "[MNn] [D00] [Y0000]", "en", (), ())
}
</div>
<a href="{$path}{$entry/wiki:id/string()}">{ $entry/atom:title/string() }</a>
</li>
}
</ul>