From 63ef27854a7eb10dd3cc06531114ca171f430cbe Mon Sep 17 00:00:00 2001 From: rich Date: Mon, 14 Aug 2006 17:56:59 +0000 Subject: [PATCH] Conservative & probably buggy implementation of breadcrumbs. --- scripts/page.ml | 60 ++++++++++++++++++++++++++++++++++++++++++++-- templates/page_header.html | 2 +- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/scripts/page.ml b/scripts/page.ml index 3592f8f..82fa0e7 100644 --- a/scripts/page.ml +++ b/scripts/page.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: page.ml,v 1.54 2006/08/14 15:53:52 rich Exp $ + * $Id: page.ml,v 1.55 2006/08/14 17:56:59 rich Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -189,8 +189,64 @@ let run r (q : cgi) dbh hostid version page page' extension = let t = template_page in let th = template_page_header in - t#set "title" title; + (*t#set "title" title; - nothing uses ::title:: on page.html - removed *) + + (* Page title, h1 and superdirs (if any). *) th#set "title" title; + + let superdirs, h1 = + match String.nsplit title "/" with + | [] -> [], "" + | [h1] -> [], h1 + | xs -> + let xs = List.rev xs in + let h1 = List.hd xs in + let superdirs = List.rev (List.tl xs) in + + (* Check the superdirs are reasonable, then convert them + * into paths or redlinks. + * If any of this fails, then there are no superdirs. + *) + try + let pathsofar = ref "" in + let superdirs = + List.mapi ( + fun i name -> + (* Path will be something like "Dir1/Dir2". We want + * a URL like "dir1/dir2". + *) + let path = + if i = 0 then name else !pathsofar ^ "/" ^ name in + (* Path so far reasonable? *) + let url, redlink = + match Wikilib.generate_url_of_title r dbh hostid path with + | Wikilib.GenURL_Duplicate url -> url, None + | Wikilib.GenURL_OK url -> url, Some path + | Wikilib.GenURL_BadURL | Wikilib.GenURL_TooShort -> + raise Exit in + pathsofar := path; + name, url, redlink + ) superdirs in + superdirs, h1 + with + Exit -> [], title in + + let superdirs = List.map ( + fun (name, url, redlink) -> + let is_redlink, redlink_title = + match redlink with + | None -> false, "" + | Some title -> true, title in + [ "url", Template.VarString url; + "name", Template.VarString name; + "is_redlink", Template.VarConditional is_redlink; + "redlink_title", Template.VarString redlink_title ] + ) superdirs in + + th#conditional "has_superdirs" (superdirs <> []); + th#table "superdirs" superdirs; + th#set "h1" h1; + t#set "last_modified_date" last_modified_date; (match description with diff --git a/templates/page_header.html b/templates/page_header.html index 6d7e209..6b4c82e 100644 --- a/templates/page_header.html +++ b/templates/page_header.html @@ -17,4 +17,4 @@ -

::title_html::

\ No newline at end of file +

::if(has_superdirs)::::table(superdirs)::::if(is_redlink)::::else::::end::::name_html:: » ::end::::end::::h1_html::

\ No newline at end of file -- 1.8.3.1