nitiwiki: macro ROOT_URL is now relative
authorJean Privat <jean@pryen.org>
Fri, 12 Jun 2015 15:14:58 +0000 (11:14 -0400)
committerJean Privat <jean@pryen.org>
Fri, 12 Jun 2015 23:21:03 +0000 (19:21 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

contrib/nitiwiki/src/wiki_base.nit
contrib/nitiwiki/src/wiki_html.nit

index 09b499b..3e0f329 100644 (file)
@@ -194,9 +194,6 @@ class Nitiwiki
                end
                var file = expand_path(config.root_dir, config.templates_dir, name)
                var tpl = new TemplateString.from_file(file)
-               if tpl.has_macro("ROOT_URL") then
-                       tpl.replace("ROOT_URL", config.root_url)
-               end
                if tpl.has_macro("TITLE") then
                        tpl.replace("TITLE", config.wiki_name)
                end
index a296a95..a937351 100644 (file)
@@ -185,6 +185,12 @@ redef class WikiArticle
        # Load a template and resolve page-related macros
        fun load_template(template_file: String): TemplateString do
                var tpl = wiki.load_template(template_file)
+               if tpl.has_macro("ROOT_URL") then
+                       var root_dir = href.dirname.relpath("")
+                       # Avoid issues if the macro is just followed by a `/` (as with url prefix)
+                       if root_dir == "" then root_dir = "."
+                       tpl.replace("ROOT_URL", root_dir)
+               end
                return tpl
        end