219 lines
No EOL
6.7 KiB
Text
219 lines
No EOL
6.7 KiB
Text
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()* := ()) {
|
||
<head>
|
||
<script src="/static/jquery-3.7.1.min.js">
|
||
</script>
|
||
|
||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.min.css"/>
|
||
|
||
<link rel="stylesheet" href="{web:create-url('/static/abaev-html.css')}"/>
|
||
|
||
{$script}
|
||
|
||
<title>{$title}</title>
|
||
</head>
|
||
};
|
||
|
||
(: Navigation header :)
|
||
declare function page:header() {
|
||
<header>
|
||
<nav>
|
||
<ul>
|
||
<li><strong>Abaevdict</strong></li>
|
||
</ul>
|
||
<ul>
|
||
<li><a href="./home">Home</a></li>
|
||
<li><a href="./dict">Dictionary</a></li>
|
||
<li><a href="./index">Index</a></li>
|
||
<li><a href="#">References</a></li>
|
||
</ul>
|
||
</nav>
|
||
</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) {
|
||
<html>
|
||
{page:head('HEDO – Dictionary',
|
||
(<script src="/static/infinite-scroll.pkgd.min.js">
|
||
</script>,
|
||
<script src="/static/plotly-3.0.1.min.js" charset="utf-8"></script>,
|
||
<script src="/static/abaev.js"></script>))}
|
||
|
||
<body>
|
||
{page:header()}
|
||
|
||
<!-- Sidebar with entry list -->
|
||
<button id="open-leftbar">
|
||
{html:doc('../static/chevron-right.svg')}
|
||
</button>
|
||
<button id="close-leftbar">
|
||
{html:doc('../static/chevron-left.svg')}
|
||
</button>
|
||
<aside id="leftbar">
|
||
<input type="text" id="filter-entries" placeholder="Quick filter…"/>
|
||
<nav id="entrylist">
|
||
<ul>
|
||
{for $doc in $page:sorted
|
||
return <li id="link_{$doc/@xml:id}">
|
||
<a href="./dict/{$doc/@xml:id}">
|
||
{$doc/text()}
|
||
</a>
|
||
</li>
|
||
}
|
||
</ul>
|
||
</nav>
|
||
</aside>
|
||
|
||
<!-- The dictionary itself. The entries are displayed as articles retrieved
|
||
from the database in HTML. On-the-fly generation is only when required -->
|
||
<main>
|
||
{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}
|
||
</main>
|
||
|
||
<!-- Footer for page navigation -->
|
||
<footer>
|
||
<nav class="pagination">
|
||
<ul>
|
||
<li>
|
||
{if ($p > 1) then <a href="?page={$p - 1}">Previous page</a> else ()}
|
||
</li>
|
||
</ul>
|
||
<!-- <ul><li>Page {$p} of {$page:total}</li></ul> -->
|
||
<ul>
|
||
<li>
|
||
{if ($p < $page:total) then
|
||
<a class="pagination__next" href="?page={$p + 1}">Next page</a> else ()}
|
||
</li>
|
||
</ul>
|
||
</nav>
|
||
</footer>
|
||
|
||
<!-- Modal for map display -->
|
||
<dialog id="modal_map">
|
||
<article>
|
||
<header><button class="abv-close-map" aria-label="Close" rel="prev"></button>
|
||
<p>Map</p>
|
||
</header>
|
||
<p>
|
||
<div id="map_display" style="width:100%;height:80%;"></div>
|
||
</p>
|
||
<footer><button class="abv-close-map">Close</button></footer>
|
||
</article>
|
||
</dialog>
|
||
</body>
|
||
</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
|
||
<html>
|
||
{page:head('HEDO – Index', <script src="/static/abaev-index.js"></script>)}
|
||
<body>
|
||
{page:header()}
|
||
<main>
|
||
<div class="index">
|
||
<div class="langs">
|
||
<label>Languages</label>
|
||
<select id="abv-select-lang" size="99999">
|
||
{
|
||
for $mlang in $mlangs
|
||
let $mlang-id := $mlang/code/text()
|
||
let $mlang-name := if ($lang = 'ru') then $mlang/ru/text() else $mlang/en/text()
|
||
where $mlang-name != ''
|
||
return
|
||
<option value="{$mlang-id}">
|
||
{
|
||
$mlang-name
|
||
}
|
||
</option>
|
||
}
|
||
</select>
|
||
</div>
|
||
<div class="forms">
|
||
<Label>Forms</Label>
|
||
<select id="abv-select-word" size="99999">
|
||
</select>
|
||
</div>
|
||
<div class="entries">
|
||
<Label>Entries</Label>
|
||
<select id="abv-select-entry" size="99999">
|
||
</select>
|
||
</div>
|
||
</div>
|
||
</main>
|
||
</body>
|
||
</html>
|
||
};
|
||
|
||
(: Default to English :)
|
||
declare %rest:path("index")
|
||
%output:method("html")
|
||
%output:html-version('5')
|
||
function page:index() {
|
||
page:index('en')
|
||
}; |