Skip to content

Commit

Permalink
made app:word-of-the-day() more robust when failing to fetch letters
Browse files Browse the repository at this point in the history
  • Loading branch information
peterstadler committed Jan 10, 2018
1 parent a926892 commit 1e582c2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions modules/app.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -532,12 +532,17 @@ declare
function app:word-of-the-day($node as node(), $model as map(*), $lang as xs:string) as map(*) {
let $words := core:getOrCreateColl('letters', 'A002068', true())//tei:seg[@type='wordOfTheDay']
let $random :=
if(count($words) gt 1) then util:random(count($words) - 1) + 1 (: util:random may return 0! :)
else 1
if(count($words) gt 1) then util:random(count($words) - 1) + 1 (: util:random may return 0 and takes as argument positiveInteger! :)
else if(count($words) eq 1) then 1
else core:logToFile('info', 'app:word-of-the-day(): no words of the day found')
return
map {
'wordOfTheDay' := str:enquote(str:normalize-space(string-join(str:txtFromTEI($words[$random], $lang), '')), $lang),
'wordOfTheDayURL' := app:createUrlForDoc(core:doc($words[$random]/ancestor::tei:TEI/string(@xml:id)), $lang)
'wordOfTheDay' :=
if($random) then str:enquote(str:normalize-space(string-join(str:txtFromTEI($words[$random], $lang), '')), $lang)
else str:normalize-space($node/xhtml:h1),
'wordOfTheDayURL' :=
if($random) then app:createUrlForDoc(core:doc($words[$random]/ancestor::tei:TEI/string(@xml:id)), $lang)
else '#'
}
};

Expand Down

0 comments on commit 1e582c2

Please sign in to comment.