#
# Returns `null` if no article can be found.
fun lookup_entry_by_path(context: WikiEntry, path: String): nullable WikiEntry do
- var entry: nullable WikiEntry = context.parent or else context
+ var entry = context.parent or else context
var parts = path.split_with("/")
if path.has_prefix("/") then
entry = root_section
while not parts.is_empty do
var name = parts.shift
if name.is_empty then continue
+ if entry.name == name then continue
if not entry.children.has_key(name) then return null
entry = entry.children[name]
end
redef class WikiEntry
- # Url to `self` once generated.
- fun url: String do return wiki.config.root_url.join_path(breadcrumbs.join("/"))
+ # Absolute url to `self` once generated.
+ # If you use this, the generated files will hard-code `root_url`
+ fun url: String do return wiki.config.root_url / href
+
+ # Relative path to `self` from the target root_url
+ fun href: String do return breadcrumbs.join("/")
+
+ # A relative `href` to `self` from the page `context`.
+ #
+ # Should be used to navigate between documents.
+ fun href_from(context: WikiEntry): String
+ do
+ var res = context.href.dirname.relpath(href)
+ return res
+ end
redef fun render do
super
# Checks if `self.name == "index"`.
fun is_index: Bool do return name == "index"
- redef fun url do
+ redef fun href do
if parent == null then
- return wiki.config.root_url.join_path("{name}.html")
+ return "{name}.html"
else
- return parent.url.join_path("{name}.html")
+ return parent.href.join_path("{name}.html")
end
end
redef fun title do return section.title
- redef fun url do return section.url
+ redef fun href do return section.href
end
# A MarkdownProcessor able to parse wiki links.
end
if target != null then
if name == null then name = target.title
- link = target.url
+ link = target.href_from(context)
else
var loc = context.src_path or else context.name
wiki.message("Warning: unknown wikilink `{link}` (in {loc})", 0)