Skip to content

Commit d71aee8

Browse files
committed
Merge: Nitiwiki: fix isues with relative paths and the root href
close #1872 Can you try it @Morriar ? Pull-Request: #1874 Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org> Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
2 parents c3bcb93 + db2a497 commit d71aee8

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
wiki.name=MyWiki
22
wiki.desc=proudly powered by nit
33
wiki.logo=assets/logo.png
4-
wiki.root_dir=/full/path/to/your/wiki/root/dir
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<header>
2-
<a href="#"><img src="%ROOT_URL%/%LOGO%" alt="logo"/></a>
2+
<a href="%ROOT_URL%/index.html"><img src="%ROOT_URL%/%LOGO%" alt="logo"/></a>
33
<h2>%SUBTITLE%</h2>
44
<h1>%TITLE%</h1>
55
</header>

contrib/nitiwiki/examples/nitiwiki/templates/menu.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<span class="icon-bar"></span>
99
<span class="icon-bar"></span>
1010
</button>
11-
<a class="navbar-brand" href="%ROOT_URL%index.html">%TITLE%</a>
11+
<a class="navbar-brand" href="%ROOT_URL%/index.html">%TITLE%</a>
1212
</div>
1313
<!-- Collect the nav links, forms, and other content for toggling -->
1414
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">

contrib/nitiwiki/src/wiki_html.nit

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,7 @@ redef class WikiArticle
189189
fun load_template(template_file: String): TemplateString do
190190
var tpl = wiki.load_template(template_file)
191191
if tpl.has_macro("ROOT_URL") then
192-
var root_dir = href.dirname.relpath("")
193-
# Avoid issues if the macro is just followed by a `/` (as with url prefix)
194-
if root_dir == "" then root_dir = "."
195-
tpl.replace("ROOT_URL", root_dir)
192+
tpl.replace("ROOT_URL", root_href)
196193
end
197194
return tpl
198195
end

contrib/nitiwiki/src/wiki_links.nit

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,23 @@ redef class WikiEntry
100100
# Relative path to `self` from the target root_url
101101
fun href: String do return breadcrumbs.join("/")
102102

103+
# Relative path to the directory `self` from the target root_url
104+
fun dir_href: String do return href.dirname
105+
106+
# Relative path to the root url from `self`
107+
fun root_href: String do
108+
var root_dir = dir_href.relpath("")
109+
# Avoid issues if used as a macro just followed by a `/` (as with url prefix)
110+
if root_dir == "" then root_dir = "."
111+
return root_dir
112+
end
113+
103114
# A relative `href` to `self` from the page `context`.
104115
#
105116
# Should be used to navigate between documents.
106117
fun href_from(context: WikiEntry): String
107118
do
108-
var res = context.href.dirname.relpath(href)
119+
var res = context.dir_href.relpath(href)
109120
return res
110121
end
111122

@@ -174,6 +185,8 @@ redef class WikiSection
174185
end
175186
return new WikiSectionIndex(wiki, "index", self)
176187
end
188+
189+
redef fun dir_href do return href
177190
end
178191

179192
redef class WikiArticle
@@ -212,6 +225,8 @@ class WikiSectionIndex
212225
redef fun title do return section.title
213226

214227
redef fun href do return section.href
228+
229+
redef fun dir_href do return section.dir_href
215230
end
216231

217232
# A MarkdownProcessor able to parse wiki links.

0 commit comments

Comments
 (0)