gitweb: allow extra breadcrumbs to prefix the trail
There are often parent pages logically above the gitweb projects list, e.g. home pages of the organization and department that host the gitweb server. This change allows you to include links to those pages in gitweb's breadcrumb trail. Signed-off-by: Tony Finch <dot@dotat.at> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Acked-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Tony Finch committed
Jul 4, 2013 at 18:02 UTC
ad9c2e22cade795cf5f3ad3dbd9cf33d2012af77
2 files changed
+26
-3
Documentation/gitweb.conf.txt
+20
-2
@@ -336,8 +336,26 @@ $home_link_str::
336
used as the first component of gitweb's "breadcrumb trail":
337
`<home link> / <project> / <action>`. Can be set at build time using
338
the `GITWEB_HOME_LINK_STR` variable. By default it is set to "projects",
339
- as this link leads to the list of projects. Other popular choice it to
340
- set it to the name of site.
339
+ as this link leads to the list of projects. Another popular choice is to
340
+ set it to the name of site. Note that it is treated as raw HTML so it
341
+ should not be set from untrusted sources.
342
+
343
+@extra_breadcrumbs::
344
+ Additional links to be added to the start of the breadcrumb trail before
345
+ the home link, to pages that are logically "above" the gitweb projects
346
+ list, such as the organization and department which host the gitweb
347
+ server. Each element of the list is a reference to an array, in which
348
+ element 0 is the link text (equivalent to `$home_link_str`) and element
349
+ 1 is the target URL (equivalent to `$home_link`).
350
++
351
+For example, the following setting produces a breadcrumb trail like
352
+"home / dev / projects / ..." where "projects" is the home link.
353
+----------------------------------------------------------------------------
354
+ our @extra_breadcrumbs = (
355
+ [ 'home' => 'https://www.example.org/' ],
356
+ [ 'dev' => 'https://dev.example.org/' ],
357
+ );
358
+----------------------------------------------------------------------------
359
360
$logo_url::
361
$logo_label::
gitweb/gitweb.perl
+6
-1
@@ -85,6 +85,9 @@ our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
85
# string of the home link on top of all pages
86
our $home_link_str = "++GITWEB_HOME_LINK_STR++";
87
88
+# extra breadcrumbs preceding the home link
89
+our @extra_breadcrumbs = ();
90
+
91
# name of your site or organization to appear in page titles
92
# replace this with something more descriptive for clearer bookmarks
93
our $site_name = "++GITWEB_SITENAME++"
@@ -3982,7 +3985,9 @@ sub print_nav_breadcrumbs_path {
3985
sub print_nav_breadcrumbs {
3986
my %opts = @_;
3987
3985
- print $cgi->a({-href => esc_url($home_link)}, $home_link_str) . " / ";
3988
+ for my $crumb (@extra_breadcrumbs, [ $home_link_str => $home_link ]) {
3989
+ print $cgi->a({-href => esc_url($crumb->[1])}, $crumb->[0]) . " / ";
3990
+ }
3991
if (defined $project) {
3992
my @dirname = split '/', $project;
3993
my $projectbasename = pop @dirname;