module namespace page = 'http://ossetic-studies.org/ns/abaevdict-site';
declare namespace tei = "http://www.tei-c.org/ns/1.0";
import module namespace abv-m = 'http://ossetic-studies.org/ns/abaevdict-mod' at './abv-mod.xqm';
(: =========================================================== :)
(: ================== GLOBAL VARIABLES ======================= :)
(: =========================================================== :)
(: Number of items per page :)
declare variable $page:items as xs:integer := 20;
(: These variables are declared in module scope because they are needed in
different places, but they are still dynamically evaluated :)
declare variable $page:lookup := doc('abaevdict_index/lookup.xml')/tei:table/tei:entry;
declare variable $page:total := ceiling(count($page:lookup) div $page:items);
declare variable $page:sorted := abv-m:sort-nodes($page:lookup);
(: =============================================================== :)
(: ======================= COMMON STUFF ========================== :)
(: =============================================================== :)
declare function page:head($title as xs:string, $script as node()* := ()) {
{$script}
{$title}
};
(: Navigation header :)
declare function page:header() {
};
(: =============================================================== :)
(: ======================= THE PAGES ============================= :)
(: =============================================================== :)
(: If no language defined, default to English :)
declare %rest:path("dict")
%output:method("html")
%output:html-version('5')
function page:dict() {
web:forward('/en/dict')
};
(: The main dictionary view :)
declare %rest:path("{$lang}/dict")
%rest:query-param("page","{$p}", 1)
%output:method("html")
%output:html-version('5')
function page:dict($lang, $p) {
{page:head('HEDO – Dictionary',
(,
,
))}
{page:header()}
{for $doc at $i in $page:sorted
where $i > ($p - 1) * $page:items and $i <= $p * $page:items
let $html := doc(`abaevdict_{$lang}/html/{$doc/@xml:id}.html`)
return $html}
};
(: == ENTRY BY ID == :)
(: English as default language :)
declare %rest:path("dict/{$id}")
%output:method("html")
%output:html-version('5')
function page:by-id($id) {
page:by-id('en',$id)
};
declare %rest:path("{$lang}/dict/{$id}")
%output:method("html")
%output:html-version('5')
function page:by-id($lang, $id) {
let $doc-index := index-of($page:sorted, $page:sorted[@xml:id=`{$id}`])
let $pagenum := ceiling($doc-index div $page:items)
return web:redirect('../dict', {'page': $pagenum}, web:decode-url($id))
};
(: Mentioned index :)
declare %rest:path("{$lang}/index")
%output:method("html")
%output:html-version('5')
function page:index($lang) {
let $mlangs := doc(`abaevdict_index/langnames.xml`)/csv[1]/record
return
{page:head('HEDO – Index', )}
{page:header()}
};
(: Default to English :)
declare %rest:path("index")
%output:method("html")
%output:html-version('5')
function page:index() {
page:index('en')
};