Commit 6f1a2ba3 authored by Mathias Goebel's avatar Mathias Goebel 🎠 Committed by mrodzis
Browse files

Feature/forward from docs

parent 06cffab6
xquery version "3.1";
(:~ This is the URL rewriting engine.
: It routes all requests to the modules and
: evaluates the RESTlike pathes.
: Set up REST pathes in here!
(:~ This is the URL rewriting engine. It routes all requests to the modules and
: evaluates the RESTlike pathes. Set up REST pathes in here, when RESTXQ is
: not an option.
:)
import module namespace config="https://sade.textgrid.de/ns/config" at "modules/config.xqm";
......@@ -13,6 +12,11 @@ declare variable $exist:prefix external;
declare variable $exist:root external;
let $exist:resource := replace($exist:resource, "%3A", ":")
(: count "/docs" parts in the path, to redirect them to lowest level. :)
let $count := index-of( tokenize($exist:path, "/"), "docs" ) => count()
(: prepare a redirect url :)
let $redirectUrl := string-join((for $i in 1 to $count return "../")) || $exist:resource
return
if ($exist:path eq '') then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
......@@ -25,6 +29,11 @@ else if ($exist:path eq "/") then
<redirect url="index.html"/>
</dispatch>
else if ( ends-with($exist:resource, ".html") ) then
if(starts-with($exist:path, "/docs")) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<redirect url="{ $redirectUrl }"/>
</dispatch>
else
(: the html page is run through view.xq to expand templates :)
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/templates{$exist:path}" method="get"/>
......@@ -38,6 +47,7 @@ else if ( ends-with($exist:resource, ".html") ) then
<forward url="{$exist:controller}/modules/view.xq"/>
</error-handler>
</dispatch>
(: Resource paths starting with ~assets are loaded from the sade-assets app :)
else if (contains($exist:path, "/~assets/")) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
......@@ -45,6 +55,7 @@ else if (contains($exist:path, "/~assets/")) then
<set-header name="Cache-Control" value="max-age=3600, must-revalidate"/>
</forward>
</dispatch>
(: redirect textgrid URIs to their renderings :)
else if(starts-with($exist:resource, "textgrid")) then
let $preserveRevision := config:get("textgrid.preserveRevision") = "true"
......@@ -73,17 +84,22 @@ else if(starts-with($exist:resource, "textgrid")) then
</error-handler>
</dispatch>
(: redirect markdown files from documentation to the content.html :)
(: forward markdown files from documentation to the content.html :)
else if(ends-with($exist:resource, ".md")) then
if(starts-with($exist:path, "/docs") and $count gt 1) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<redirect url="{ $redirectUrl }"/>
</dispatch>
else
if(starts-with($exist:path, "/docs"))
then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/templates/content.html" method="get"/>
<view>
<forward url="{$exist:controller}/modules/view.xq">
<add-parameter name="id" value="{$exist:path}" />
<add-parameter name="exist-resource" value="{$exist:resource}" />
</forward>
<view>
<forward url="{$exist:controller}/modules/view.xq">
<add-parameter name="id" value="{$exist:path}" />
<add-parameter name="exist-resource" value="{$exist:resource}" />
</forward>
</view>
<error-handler>
<forward url="{$exist:controller}/templates/error.html" method="get"/>
......@@ -92,7 +108,7 @@ else if(ends-with($exist:resource, ".md")) then
</dispatch>
else
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<redirect url="content.html?id=docs/{$exist:resource}"/>
<redirect url="docs/{$exist:resource}"/>
</dispatch>
else if($exist:resource = "sitemap.xml") then
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
......
# Limitations
## documentation structure and URL rewriting
A flat hierarchy must be applied to the [`/docs`](./) directory and so there are no
directories allowed within. The reason is that we want to be able to view the
documentation within the git repo\`s webinterface and at the SADE website.
Therefore we use a set of redirections and forwards within the `controller.xql`.
The documentation is available via direct URL like `/docs/about.md`. Additionally
the markdown files are parsed via `content.html?id=/docs/about.md`, but images
(or other binary data) is available only when using the direct URL mentioned at
first.
<?xml version="1.0" encoding="UTF-8"?>
<navigation>
<submenu label="Dokumentation" label-en="Documentation">
<item label="Anpassen des Portals" label-en="Customization" link="content.html?id=docs/customization.md"/>
<item label="Facetierte Suche" link="content.html?id=docs/faceted-search.md"/>
<item label="Anpassen des Portals" label-en="Customization" link="docs/customization.md"/>
<item label="Facetierte Suche" link="docs/faceted-search.md"/>
<item label="Publizieren aus TextGridLab" link="docs/publish.md"/>
</submenu>
<submenu label="Weiterführende Links" label-en="Further Links">
......
......@@ -93,13 +93,13 @@
<h3 class="footer__header"> More about SADE </h3>
<ul class="footer__content">
<li>
<a href="content.html?id=docs/about.md">Features</a>
<a href="docs/about.md">Features</a>
</li>
<li>
<a href="content.html?id=docs/develop.md">Developer Guide</a>
<a href="docs/develop.md">Developer Guide</a>
</li>
<li>
<a href="content.html?id=docs/publish.md">Publish Data via TextGrid</a>
<a href="docs/publish.md">Publish Data via TextGrid</a>
</li>
<li>
<a href="sitemap.xml">Sitemap</a>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment