Skip to content

Commit 84b4a22

Browse files
authored
Merge pull request #107 from line-o/next-version
2 parents 72c28f4 + 35a6610 commit 84b4a22

File tree

20 files changed

+711
-179
lines changed

20 files changed

+711
-179
lines changed

src/main/xar-resources/collection.xconf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<collection xmlns="http://exist-db.org/collection-config/1.0">
22
<index xmlns:xqdoc="http://www.xqdoc.org/1.0">
3-
<fulltext default="none" attributes="false"/>
3+
<range>
4+
<create qname="xqdoc:uri" />
5+
<create qname="xqdoc:location" />
6+
</range>
47
<ngram qname="xqdoc:name"/>
58
<ngram qname="xqdoc:signature"/>
69
<ngram qname="xqdoc:description"/>

src/main/xar-resources/controller.xq

Lines changed: 106 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,60 +4,128 @@ import module namespace login="http://exist-db.org/xquery/login" at "resource:or
44

55
declare namespace json="http://www.json.org";
66

7-
declare variable $exist:root external;
87
declare variable $exist:prefix external;
98
declare variable $exist:controller external;
109
declare variable $exist:path external;
1110
declare variable $exist:resource external;
1211

13-
if ($exist:path eq '') then (
12+
declare variable $local:method := lower-case(request:get-method());
13+
declare variable $local:is-get := $local:method eq 'get';
14+
declare variable $local:user := login:set-user("org.exist.login", (), false());
15+
16+
declare function local:map-type-to-where ($type as xs:string?) as xs:string {
17+
(
18+
map:get(
19+
map {
20+
"name": "everywhere",
21+
"signature": "signature",
22+
"desc": "description"
23+
},
24+
$type
25+
),
26+
'everywhere'
27+
)[1]
28+
};
29+
30+
declare function local:render-view($view as xs:string) {
1431
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
15-
<redirect url="{concat(request:get-uri(), '/')}"/>
32+
<forward url="templates/pages/{$view}.html"/>
33+
<view>
34+
<forward url="{$exist:controller}/modules/view.xq">
35+
<set-attribute name="$exist:prefix" value="{$exist:prefix}"/>
36+
<set-attribute name="$exist:controller" value="{$exist:controller}"/>
37+
</forward>
38+
</view>
1639
</dispatch>
17-
) else if ($exist:path eq "/") then (
18-
(: forward root path to index.xql :)
40+
};
41+
42+
declare function local:render-parameters ($parameters as map(*)) {
43+
map:for-each($parameters, function ($k, $v) {
44+
if (empty($v)) then () else (
45+
$k || '=' || escape-uri($v, true())
46+
)
47+
})
48+
=> string-join('&amp;')
49+
};
50+
51+
(: redirects :)
52+
if ($local:is-get and $exist:path eq '') then (
1953
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
20-
<redirect url="index.html"/>
54+
<redirect url="{concat(request:get-uri(), '/')}"/>
2155
</dispatch>
22-
) else if (ends-with($exist:resource, ".html")) then (
23-
let $loggedIn := login:set-user("org.exist.login", (), true())
56+
) else if ($local:is-get and $exist:path eq '/index.html') then (
57+
let $url := substring-before(request:get-uri(), 'index.html')
58+
59+
let $parameters := map{
60+
'q': request:get-parameter('q', ()),
61+
'action': 'search',
62+
'where': local:map-type-to-where(request:get-parameter('type', ()))
63+
}
64+
2465
return
25-
(: the html page is run through view.xql to expand templates :)
2666
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
27-
<view>
28-
<forward url="{$exist:controller}/modules/view.xq">
29-
<set-attribute name="$exist:prefix" value="{$exist:prefix}"/>
30-
<set-attribute name="$exist:controller" value="{$exist:controller}"/>
31-
</forward>
32-
</view>
67+
<redirect url="{$url}?{local:render-parameters($parameters)}" />
3368
</dispatch>
34-
) else if (ends-with($exist:resource, ".md")) then (
35-
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
36-
<forward url="{$exist:controller}{$exist:path}" />
37-
</dispatch>
38-
) else if (matches($exist:path, "/resources/(css|fonts|images|scripts|svg|css)/.+")) then (
39-
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
40-
<forward url="{$exist:controller}{$exist:path}" />
41-
</dispatch>
42-
) else if ($exist:resource eq "login") then (
43-
let $loggedIn := login:set-user("org.exist.login", (), true())
69+
) else if ($local:is-get and $exist:path eq '/view.html') then (
70+
let $url := substring-before(request:get-uri(), '.html')
71+
let $parameters := map{
72+
'location': request:get-parameter('location', ()),
73+
'uri': request:get-parameter('uri', ()),
74+
'function': request:get-parameter('function', ())
75+
}
76+
4477
return
45-
try {
46-
util:declare-option("exist:serialize", "method=json"),
47-
<status>
48-
<user>{request:get-attribute("org.exist.login.user")}</user>
49-
<isAdmin json:literal="true">{ sm:is-dba(request:get-attribute("org.exist.login.user")) }</isAdmin>
50-
</status>
51-
} catch * {
52-
response:set-status-code(401),
53-
<status>{$err:description}</status>
54-
}
55-
) else if ($exist:path = "/regenerate") then (
56-
let $loggedIn := login:set-user("org.exist.login", (), false())
78+
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
79+
<redirect url="{$url}?{local:render-parameters($parameters)}" />
80+
</dispatch>
81+
82+
) else if ($local:is-get and $exist:path eq '/browse.html') then (
83+
let $url := substring-before(request:get-uri(), '.html')
84+
let $parameters := map{
85+
'w3c': request:get-parameter('w3c', ()),
86+
'extensions': request:get-parameter('extensions', ()),
87+
'appmodules': request:get-parameter('appmodules', ())
88+
}
89+
5790
return
5891
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
59-
<forward url="{$exist:controller}/modules/regenerate.xq" />
92+
<redirect url="{$url}?{local:render-parameters($parameters)}" />
6093
</dispatch>
94+
) else if ($local:is-get and $exist:path eq "/") then (
95+
local:render-view('index')
96+
) else if ($local:is-get and $exist:path eq "/view") then (
97+
local:render-view('view')
98+
) else if ($local:is-get and $exist:path eq "/browse") then (
99+
local:render-view('browse')
100+
) else if ($local:method eq 'post' and $exist:path eq "/query") then (
101+
local:render-view('query')
102+
) else if ($local:is-get and $exist:path eq "/login") then (
103+
try {
104+
util:declare-option("exist:serialize", "method=json"),
105+
<status>
106+
<user>{request:get-attribute("org.exist.login.user")}</user>
107+
<isAdmin json:literal="true">{ sm:is-dba(request:get-attribute("org.exist.login.user")) }</isAdmin>
108+
</status>
109+
} catch * {
110+
response:set-status-code(401),
111+
<status>{$err:description}</status>
112+
}
113+
) else if ($local:is-get and matches($exist:path, ".+\.md$")) then (
114+
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
115+
<forward url="{$exist:controller}{$exist:path}">
116+
<set-header name="Cache-Control" value="max-age=73600; must-revalidate;"/>
117+
</forward>
118+
</dispatch>
119+
) else if ($local:is-get and matches($exist:path, "/resources/(css|fonts|images|scripts|svg|css)/.+")) then (
120+
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
121+
<forward url="{$exist:controller}{$exist:path}">
122+
<set-header name="Cache-Control" value="max-age=73600; must-revalidate;"/>
123+
</forward>
124+
</dispatch>
125+
) else if ($local:is-get and $exist:path = "/regenerate") then (
126+
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
127+
<forward url="{$exist:controller}/modules/regenerate.xq" />
128+
</dispatch>
61129
) else (
62130
response:set-status-code(404),
63131
<data>Not Found</data>

src/main/xar-resources/finish.xq

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import module namespace generate = "http://exist-db.org/apps/fundocs/generate" at "modules/generate.xqm";
2+
3+
generate:fundocs(),
4+
util:log("info", "Finished generating function documentation for fundocs")

src/main/xar-resources/index.html

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)