threads / patch / 34324

patchgitweb: allow extra breadcrumbs to prefix the trail

Subject: [PATCH] gitweb: allow extra breadcrumbs to prefix the trail

## tl;dr

15 messages between Jul 2, 2013 and Jul 7, 2013. Diffs are folded; open one to read it.

replies: 14people: 3as markdown or json

Tony Finch· Jul 2, 2013, 15:49 UTC · lore

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>
---
 Documentation/gitweb.conf.txt | 8 ++++++++
 gitweb/gitweb.perl            | 6 ++++++
 2 files changed, 14 insertions(+)
Show changes to 2 files +14 −0

Documentation/gitweb.conf.txt, gitweb/gitweb.perl

diff --git a/Documentation/gitweb.conf.txt b/Documentation/gitweb.conf.txt
index ea0526e..4579578 100644
--- a/Documentation/gitweb.conf.txt
+++ b/Documentation/gitweb.conf.txt
@@ -339,6 +339,14 @@ $home_link_str::
 	as this link leads to the list of projects.  Other popular choice it to
 	set it to the name of site.
 
+@extra_breadcrumbs::
+	Additional links to be added to the start of the breadcrumb trail,
+	that are logically "above" the gitweb projects list. For example,
+	links to the organization and department which host the gitweb
+	server. Each element of the list is a reference to an array,
+	in which element 0 is the link text and element 1 is the
+	target URL.
+
 $logo_url::
 $logo_label::
 	URI and label (title) for the Git logo link (or your site logo,
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 8d69ada..436f17a 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -85,6 +85,9 @@ our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
 # string of the home link on top of all pages
 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
 
+# extra breadcrumbs preceding the home link
+our @extra_breadcrumbs = ();
+
 # name of your site or organization to appear in page titles
 # replace this with something more descriptive for clearer bookmarks
 our $site_name = "++GITWEB_SITENAME++"
@@ -3982,6 +3985,9 @@ sub print_nav_breadcrumbs_path {
 sub print_nav_breadcrumbs {
 	my %opts = @_;
 
+	for my $crumb (@extra_breadcrumbs) {
+		print $cgi->a({-href => esc_url($crumb->[1])}, $crumb->[0]) . " / ";
+	}
 	print $cgi->a({-href => esc_url($home_link)}, $home_link_str) . " / ";
 	if (defined $project) {
 		my @dirname = split '/', $project;
-- 
1.8.3.1.605.g85318f5
Tony Finch· Jul 2, 2013, 15:49 UTC · re: Tony Finch · lore

[PATCH v2] 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>
---

This update includes the documentation improvements suggested by Jonathan Nieder and Jakub Narębski.

 Documentation/gitweb.conf.txt | 22 ++++++++++++++++++++--
 gitweb/gitweb.perl            |  6 ++++++
 2 files changed, 26 insertions(+), 2 deletions(-)
Show changes to 2 files +26 −2

Documentation/gitweb.conf.txt, gitweb/gitweb.perl

diff --git a/Documentation/gitweb.conf.txt b/Documentation/gitweb.conf.txt
index ea0526e..305db63 100644
--- a/Documentation/gitweb.conf.txt
+++ b/Documentation/gitweb.conf.txt
@@ -336,8 +336,26 @@ $home_link_str::
 	used as the first component of gitweb's "breadcrumb trail":
 	`<home link> / <project> / <action>`.  Can be set at build time using
 	the `GITWEB_HOME_LINK_STR` variable.  By default it is set to "projects",
-	as this link leads to the list of projects.  Other popular choice it to
-	set it to the name of site.
+	as this link leads to the list of projects.  Another popular choice is to
+	set it to the name of site.  Note that it is treated as raw HTML so it
+	should not be set from untrusted sources.
+
+@extra_breadcrumbs::
+	Additional links to be added to the start of the breadcrumb trail before
+	the home link, to pages that are logically "above" the gitweb projects
+	list, such as the organization and department which host the gitweb
+	server. Each element of the list is a reference to an array, in which
+	element 0 is the link text (equivalent to `$home_link_str`) and element
+	1 is the target URL (equivalent to `$home_link`).
++
+For example, the following setting produces a breadcrumb trail like
+"home / dev / projects / ..." where "projects" is the home link.
+----------------------------------------------------------------------------
+    our @extra_breadcrumbs = (
+      [ 'home' => 'https://www.example.org/' ],
+      [ 'dev'  => 'https://dev.example.org/' ],
+    );
+----------------------------------------------------------------------------
 
 $logo_url::
 $logo_label::
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 8d69ada..436f17a 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -85,6 +85,9 @@ our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
 # string of the home link on top of all pages
 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
 
+# extra breadcrumbs preceding the home link
+our @extra_breadcrumbs = ();
+
 # name of your site or organization to appear in page titles
 # replace this with something more descriptive for clearer bookmarks
 our $site_name = "++GITWEB_SITENAME++"
@@ -3982,6 +3985,9 @@ sub print_nav_breadcrumbs_path {
 sub print_nav_breadcrumbs {
 	my %opts = @_;
 
+	for my $crumb (@extra_breadcrumbs) {
+		print $cgi->a({-href => esc_url($crumb->[1])}, $crumb->[0]) . " / ";
+	}
 	print $cgi->a({-href => esc_url($home_link)}, $home_link_str) . " / ";
 	if (defined $project) {
 		my @dirname = split '/', $project;
-- 
1.8.3.1.605.g85318f5
Jonathan Nieder· Jul 3, 2013, 21:59 UTC · re: Tony Finch · lore

Re: [PATCH] gitweb: allow extra breadcrumbs to prefix the trail

(cc-ing Jakub, gitweb wrangler)
Tony Finch wrote:
> 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.
Neat.
Show 21 quoted lines
> Signed-off-by: Tony Finch <dot@dotat.at>
> ---
>  Documentation/gitweb.conf.txt | 8 ++++++++
>  gitweb/gitweb.perl            | 6 ++++++
>  2 files changed, 14 insertions(+)
> 
> diff --git a/Documentation/gitweb.conf.txt b/Documentation/gitweb.conf.txt
> index ea0526e..4579578 100644
> --- a/Documentation/gitweb.conf.txt
> +++ b/Documentation/gitweb.conf.txt
> @@ -339,6 +339,14 @@ $home_link_str::
>  	as this link leads to the list of projects.  Other popular choice it to
>  	set it to the name of site.
>  
> +@extra_breadcrumbs::
> +	Additional links to be added to the start of the breadcrumb trail,
> +	that are logically "above" the gitweb projects list. For example,
> +	links to the organization and department which host the gitweb
> +	server. Each element of the list is a reference to an array,
> +	in which element 0 is the link text and element 1 is the
> +	target URL.
Is arbitrary HTML permitted in the link text?

I think it makes sense to permit it for consistency with $home_link_str, but it might be worth mentioning in the manpage so the administrator knows not to set it to something user-controlled --- e.g.:

	The link text can contain arbitrary HTML --- to escape link
	text generated programatically, use esc_html($text).
For what it's worth, with or without such a change,
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
(Patch left unsnipped for reference.)
Show 29 quoted lines
> +
>  $logo_url::
>  $logo_label::
>  	URI and label (title) for the Git logo link (or your site logo,
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index 8d69ada..436f17a 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -85,6 +85,9 @@ our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
>  # string of the home link on top of all pages
>  our $home_link_str = "++GITWEB_HOME_LINK_STR++";
>  
> +# extra breadcrumbs preceding the home link
> +our @extra_breadcrumbs = ();
> +
>  # name of your site or organization to appear in page titles
>  # replace this with something more descriptive for clearer bookmarks
>  our $site_name = "++GITWEB_SITENAME++"
> @@ -3982,6 +3985,9 @@ sub print_nav_breadcrumbs_path {
>  sub print_nav_breadcrumbs {
>  	my %opts = @_;
>  
> +	for my $crumb (@extra_breadcrumbs) {
> +		print $cgi->a({-href => esc_url($crumb->[1])}, $crumb->[0]) . " / ";
> +	}
>  	print $cgi->a({-href => esc_url($home_link)}, $home_link_str) . " / ";
>  	if (defined $project) {
>  		my @dirname = split '/', $project;
> -- 
Jakub Narębski· Jul 3, 2013, 22:11 UTC · re: Jonathan Nieder · lore

Re: [PATCH] gitweb: allow extra breadcrumbs to prefix the trail

On Wed, Jul 3, 2013 at 11:59 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:
> Tony Finch wrote:
Show 16 quoted lines
>> +@extra_breadcrumbs::
>> +     Additional links to be added to the start of the breadcrumb trail,
>> +     that are logically "above" the gitweb projects list. For example,
>> +     links to the organization and department which host the gitweb
>> +     server. Each element of the list is a reference to an array,
>> +     in which element 0 is the link text and element 1 is the
>> +     target URL.
>
> Is arbitrary HTML permitted in the link text?
>
> I think it makes sense to permit it for consistency with $home_link_str,
> but it might be worth mentioning in the manpage so the administrator
> knows not to set it to something user-controlled --- e.g.:
>
>         The link text can contain arbitrary HTML --- to escape link
>         text generated programatically, use esc_html($text).

Nb. it would be nice to have relation of @extra_breadcrumbs with $home_link_str explained.

-- 
Jakub Narebski
Tony Finch· Jul 4, 2013, 08:44 UTC · re: Jakub Narębski · lore

Re: [PATCH] gitweb: allow extra breadcrumbs to prefix the trail

Jakub Narębski <jnareb@gmail.com> wrote:
Show 12 quoted lines
> On Wed, Jul 3, 2013 at 11:59 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:
> > Tony Finch wrote:
>
> >> +@extra_breadcrumbs::
> >> +     Additional links to be added to the start of the breadcrumb trail,
> >> +     that are logically "above" the gitweb projects list. For example,
> >> +     links to the organization and department which host the gitweb
> >> +     server. Each element of the list is a reference to an array,
> >> +     in which element 0 is the link text and element 1 is the
> >> +     target URL.
> >
> > Is arbitrary HTML permitted in the link text?

I had the same question when I was wondering about abusing $home_link_str to do this without a patch :-)

> > I think it makes sense to permit it for consistency with $home_link_str,
> > but it might be worth mentioning in the manpage so the administrator
> > knows not to set it to something user-controlled --- e.g.:

I left this detail out of the man page for consistency with the documentation for $home_link_str.

> Nb. it would be nice to have relation of @extra_breadcrumbs with
> $home_link_str explained.
I will make that clearer.
Thanks for reviewing the patch.
Tony.
-- 
f.anthony.n.finch  <dot@dotat.at>  http://dotat.at/
Forties, Cromarty: East, veering southeast, 4 or 5, occasionally 6 at first.
Rough, becoming slight or moderate. Showers, rain at first. Moderate or good,
occasionally poor at first.
Jakub Narębski· Jul 4, 2013, 14:40 UTC · re: Tony Finch · lore

Re: [PATCH] gitweb: allow extra breadcrumbs to prefix the trail

On Thu, Jul 4, 2013 at 10:44 AM, Tony Finch <dot@dotat.at> wrote:
Show 5 quoted lines
> Jakub Narębski <jnareb@gmail.com> wrote:
>> On Wed, Jul 3, 2013 at 11:59 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:
>>> Tony Finch wrote:
>>
>>>> +@extra_breadcrumbs::

BTW. perhaps (it is only an idea) @top_level_breadcrumbs or @home_breadcrumbs would be a better name for this variable.

Show 11 quoted lines
>>>> +     Additional links to be added to the start of the breadcrumb trail,
>>>> +     that are logically "above" the gitweb projects list. For example,
>>>> +     links to the organization and department which host the gitweb
>>>> +     server. Each element of the list is a reference to an array,
>>>> +     in which element 0 is the link text and element 1 is the
>>>> +     target URL.
>>>
>>> Is arbitrary HTML permitted in the link text?
>
> I had the same question when I was wondering about abusing $home_link_str
> to do this without a patch :-)

Not exactly arbitrary, as it is inside A element, so it cannot contain A links itself (hyperlinks should not be nested), but it is not esc_html-aped.

Show 7 quoted lines
>
>>> I think it makes sense to permit it for consistency with $home_link_str,
>>> but it might be worth mentioning in the manpage so the administrator
>>> knows not to set it to something user-controlled --- e.g.:
>
> I left this detail out of the man page for consistency with the
> documentation for $home_link_str.

It would be better to improve documentation, than follow current bad practice... ;-P

>> Nb. it would be nice to have relation of @extra_breadcrumbs with
>> $home_link_str explained.
>
> I will make that clearer.

Perhaps even make ( [ $home_link_str, $home_link ] ) to be default value for @extra_breadcrumbs, making new feature generalization of $home_link*, similarly to how it was done for $stylesheet -> @stylesheets transition.

What do you think about it?
-- 
Jakub Narębski
Tony Finch· Jul 4, 2013, 15:11 UTC · re: Jakub Narębski · lore

Re: [PATCH] gitweb: allow extra breadcrumbs to prefix the trail

Jakub Narębski <jnareb@gmail.com> wrote:
>
> It would be better to improve documentation, than follow current bad
> practice... ;-P
The v2 patch does just that :-)
> Perhaps even make ( [ $home_link_str, $home_link ] ) to be default
> value for @extra_breadcrumbs, making new feature generalization
> of $home_link*, similarly to how it was done for $stylesheet -> @stylesheets
> transition.

I don't think that's a win. There's a lot of existing gitweb.conf out there which sets $home_link_str, so the code would have to either print the last element of @extra_breadcrumbs or the $home_link variables depending on whether the variables were modified. And the documentation would have to explain this complicated arrangement.

Tony.
-- 
f.anthony.n.finch  <dot@dotat.at>  http://dotat.at/
Forties, Cromarty: East, veering southeast, 4 or 5, occasionally 6 at first.
Rough, becoming slight or moderate. Showers, rain at first. Moderate or good,
occasionally poor at first.
Jakub Narębski· Jul 4, 2013, 15:34 UTC · re: Tony Finch · lore

Re: [PATCH] gitweb: allow extra breadcrumbs to prefix the trail

On Thu, Jul 4, 2013 at 5:11 PM, Tony Finch <dot@dotat.at> wrote:
Show 6 quoted lines
> Jakub Narębski <jnareb@gmail.com> wrote:
>>
>> It would be better to improve documentation, than follow current bad
>> practice... ;-P
>
> The v2 patch does just that :-)
Thanks.
Show 10 quoted lines
>> Perhaps even make ( [ $home_link_str, $home_link ] ) to be default
>> value for @extra_breadcrumbs, making new feature generalization
>> of $home_link*, similarly to how it was done for $stylesheet -> @stylesheets
>> transition.
>
> I don't think that's a win. There's a lot of existing gitweb.conf out
> there which sets $home_link_str, so the code would have to either print
> the last element of @extra_breadcrumbs or the $home_link variables
> depending on whether the variables were modified. And the documentation
> would have to explain this complicated arrangement.

First, do I understand corrctly that @extra_breadcrumbs are rendered *after* $home_link*, and in exactly the same manner?

Second, I misremembered how $stylesheet / @stylesheets is handled. I was thinking more about having in gitweb.perl the following default initialization for @extra_breadcrumbs:

  our @extra_breadcrumbs = ( [ $home_link_str, $home_link ] );
Then one can add breadcrumbs with
  push @extra_breadcrumbs, [ $foo_html, $foo_url ], [
esc_html($bar_txt), $bar_url ];

But now I think that we can do better, simply put $home_link_str and $home_link in @extra_breadcrumbs / @top_level_breadcrumbs / @nav_breadcrumbs before using it, either via

  unshift @nav_breadcrumbs, [ $home_link_str, $home_link ];
or
  for $breadcrumb ([ $home_link_str, $home_link ], @nav_breadcrumbs) {
... unless we treat home link in some special way (do we?).

P.S. It is a bit late, but wouldn't { name => $link_name, href => $link_url } (like %features hash) be a better solution than [ $link_name, $link_url ], i.e. hashref (named parameters) instead of arrayref (positional parameters). You wouldn't have to remember which is first: text or URL.

-- 
Jakub Narebski
Tony Finch· Jul 4, 2013, 15:56 UTC · re: Jakub Narębski · lore

Re: [PATCH] gitweb: allow extra breadcrumbs to prefix the trail

Jakub Narębski <jnareb@gmail.com> wrote:
>
> First, do I understand corrctly that @extra_breadcrumbs are rendered *after*
> $home_link*, and in exactly the same manner?

Before the home link, and yes, in the same manner. The extra breadcrumbs are for links to parent pages above gitweb in some hierarchy.

> But now I think that we can do better, simply put $home_link_str and $home_link
> in @extra_breadcrumbs / @top_level_breadcrumbs / @nav_breadcrumbs before
> using it,
We could save a line that way:
-       print $cgi->a({-href => esc_url($home_link)}, $home_link_str) . " / ";
+       for my $crumb (@extra_breadcrumbs, [ $home_link_str => $home_link ]) {
+               print $cgi->a({-href => esc_url($crumb->[1])}, $crumb->[0]) . " / ";
+       }
> P.S. It is a bit late, but wouldn't { name => $link_name, href => $link_url }
> (like %features hash) be a better solution than [ $link_name, $link_url ],
> i.e. hashref (named parameters) instead of arrayref (positional parameters).
> You wouldn't have to remember which is first: text or URL.
I thought the fat arrow would be mnemonic enough, and less verbose.
Tony.
-- 
f.anthony.n.finch  <dot@dotat.at>  http://dotat.at/
Forties, Cromarty: East, veering southeast, 4 or 5, occasionally 6 at first.
Rough, becoming slight or moderate. Showers, rain at first. Moderate or good,
occasionally poor at first.
Jakub Narębski· Jul 4, 2013, 16:32 UTC · re: Tony Finch · lore

Re: [PATCH] gitweb: allow extra breadcrumbs to prefix the trail

On Thu, Jul 4, 2013 at 5:56 PM, Tony Finch <dot@dotat.at> wrote:
Show 7 quoted lines
> Jakub Narębski <jnareb@gmail.com> wrote:
>>
>> First, do I understand correctly that @extra_breadcrumbs are rendered *after*
>> $home_link*, and in exactly the same manner?
>
> Before the home link, and yes, in the same manner. The extra breadcrumbs
> are for links to parent pages above gitweb in some hierarchy.

Hmmm... I would have thought that they were after home link. I wonder if leaving it up to user to configure @extra_breadcrumbs to include $home_link in appropriate place (the unshift / push solution to adding to @extra_breadcrumbs, starting with $home_link) would be good idea, or over-engineering.

In what situation do you need those extra breadcrumbs useful? What necessity / itch to scratch is behind idea of this patch?

Show 10 quoted lines
>> But now I think that we can do better, simply put $home_link_str and $home_link
>> in @extra_breadcrumbs / @top_level_breadcrumbs / @nav_breadcrumbs before
>> using it,
>
> We could save a line that way:
>
> -       print $cgi->a({-href => esc_url($home_link)}, $home_link_str) . " / ";
> +       for my $crumb (@extra_breadcrumbs, [ $home_link_str => $home_link ]) {
> +               print $cgi->a({-href => esc_url($crumb->[1])}, $crumb->[0]) . " / ";
> +       }

And avoid a bit of code duplication; now we are sure that both @extra_breadcrumbs and $home_link are rendered in the same way.

Show 6 quoted lines
>> P.S. It is a bit late, but wouldn't { name => $link_name, href => $link_url }
>> (like %features hash) be a better solution than [ $link_name, $link_url ],
>> i.e. hashref (named parameters) instead of arrayref (positional parameters).
>> You wouldn't have to remember which is first: text or URL.
>
> I thought the fat arrow would be mnemonic enough, and less verbose.

Yes, hashref solution is a bit verbose. I don't like abusing fat arrow notation, but here it gives nice mnemonic (hopefully explained in documentation).

-- 
Jakub Narebski
Tony Finch· Jul 4, 2013, 17:08 UTC · re: Jakub Narębski · lore

Re: [PATCH] gitweb: allow extra breadcrumbs to prefix the trail

Jakub Narębski <jnareb@gmail.com> wrote:
>
> In what situation do you need those extra breadcrumbs useful? What
> necessity / itch to scratch is behind idea of this patch?
For an example, see https://git.csx.cam.ac.uk/x/ucs/git/git.git

I have three items in @extra_breadcrumbs which point to the University home page, my department home page, and my git server's home page; there are a number of gitolite accounts on the server each of which has a project listing which is where gitweb's home link points.

(I expect to change the link texts to make it less confusing when you happen to be looking at my department's account on the git server...)

our @extra_breadcrumbs = (
  [ cam => 'http://www.cam.ac.uk/'      ],
  [ ucs => 'http://www.ucs.cam.ac.uk/'  ],
  [ git => 'https://git.csx.cam.ac.uk/' ],
);

This is in line with our house style (none of which I have implemented on this server yet) - there are other examples of similar breadcrumb trails at https://raven.cam.ac.uk and http://new-webmail.hermes.cam.ac.uk

There is a more generic version of this description and config example in v2 of my patch. I hope it is clear enough. I'll send a v3 patch with the code tweak.

Tony.
-- 
f.anthony.n.finch  <dot@dotat.at>  http://dotat.at/
Forties, Cromarty: East, veering southeast, 4 or 5, occasionally 6 at first.
Rough, becoming slight or moderate. Showers, rain at first. Moderate or good,
occasionally poor at first.
Jakub Narębski· Jul 4, 2013, 17:31 UTC · re: Tony Finch · lore

Re: [PATCH] gitweb: allow extra breadcrumbs to prefix the trail

On Thu, Jul 4, 2013 at 7:08 PM, Tony Finch <dot@dotat.at> wrote:
Show 11 quoted lines
> Jakub Narębski <jnareb@gmail.com> wrote:
>>
>> In what situation do you need those extra breadcrumbs useful? What
>> necessity / itch to scratch is behind idea of this patch?
>
> For an example, see https://git.csx.cam.ac.uk/x/ucs/git/git.git
>
> I have three items in @extra_breadcrumbs which point to the University
> home page, my department home page, and my git server's home page; there
> are a number of gitolite accounts on the server each of which has a
> project listing which is where gitweb's home link points.

Of course those @external_breadcrumbs are really useful iff they are repeated consistently in at least similar form in all those external pages...

> (I expect to change the link texts to make it less confusing when you
> happen to be looking at my department's account on the git server...)
-- 
Jakub Narebski
Tony Finch· Jul 4, 2013, 17:02 UTC · re: Tony Finch · lore

[PATCH v3] 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>
---
 Documentation/gitweb.conf.txt | 22 ++++++++++++++++++++--
 gitweb/gitweb.perl            |  7 ++++++-
 2 files changed, 26 insertions(+), 3 deletions(-)
Show changes to 2 files +26 −3

Documentation/gitweb.conf.txt, gitweb/gitweb.perl

diff --git a/Documentation/gitweb.conf.txt b/Documentation/gitweb.conf.txt
index ea0526e..305db63 100644
--- a/Documentation/gitweb.conf.txt
+++ b/Documentation/gitweb.conf.txt
@@ -336,8 +336,26 @@ $home_link_str::
 	used as the first component of gitweb's "breadcrumb trail":
 	`<home link> / <project> / <action>`.  Can be set at build time using
 	the `GITWEB_HOME_LINK_STR` variable.  By default it is set to "projects",
-	as this link leads to the list of projects.  Other popular choice it to
-	set it to the name of site.
+	as this link leads to the list of projects.  Another popular choice is to
+	set it to the name of site.  Note that it is treated as raw HTML so it
+	should not be set from untrusted sources.
+
+@extra_breadcrumbs::
+	Additional links to be added to the start of the breadcrumb trail before
+	the home link, to pages that are logically "above" the gitweb projects
+	list, such as the organization and department which host the gitweb
+	server. Each element of the list is a reference to an array, in which
+	element 0 is the link text (equivalent to `$home_link_str`) and element
+	1 is the target URL (equivalent to `$home_link`).
++
+For example, the following setting produces a breadcrumb trail like
+"home / dev / projects / ..." where "projects" is the home link.
+----------------------------------------------------------------------------
+    our @extra_breadcrumbs = (
+      [ 'home' => 'https://www.example.org/' ],
+      [ 'dev'  => 'https://dev.example.org/' ],
+    );
+----------------------------------------------------------------------------
 
 $logo_url::
 $logo_label::
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 8d69ada..f429f75 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -85,6 +85,9 @@ our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
 # string of the home link on top of all pages
 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
 
+# extra breadcrumbs preceding the home link
+our @extra_breadcrumbs = ();
+
 # name of your site or organization to appear in page titles
 # replace this with something more descriptive for clearer bookmarks
 our $site_name = "++GITWEB_SITENAME++"
@@ -3982,7 +3985,9 @@ sub print_nav_breadcrumbs_path {
 sub print_nav_breadcrumbs {
 	my %opts = @_;
 
-	print $cgi->a({-href => esc_url($home_link)}, $home_link_str) . " / ";
+	for my $crumb (@extra_breadcrumbs, [ $home_link_str => $home_link ]) {
+		print $cgi->a({-href => esc_url($crumb->[1])}, $crumb->[0]) . " / ";
+	}
 	if (defined $project) {
 		my @dirname = split '/', $project;
 		my $projectbasename = pop @dirname;
-- 
1.8.3.1.605.g85318f5
Jakub Narębski· Jul 4, 2013, 17:42 UTC · re: Tony Finch · lore

Re: [PATCH v3] gitweb: allow extra breadcrumbs to prefix the trail

On Thu, Jul 4, 2013 at 7:02 PM, Tony Finch <dot@dotat.at> wrote:
Show 7 quoted lines
> 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>
For what it is worth:
Acked-by: Jakub Narebski <jnareb@gmail.com>
Show 18 quoted lines
> ---
>  Documentation/gitweb.conf.txt | 22 ++++++++++++++++++++--
>  gitweb/gitweb.perl            |  7 ++++++-
>  2 files changed, 26 insertions(+), 3 deletions(-)
>
> diff --git a/Documentation/gitweb.conf.txt b/Documentation/gitweb.conf.txt
> index ea0526e..305db63 100644
> --- a/Documentation/gitweb.conf.txt
> +++ b/Documentation/gitweb.conf.txt
> @@ -336,8 +336,26 @@ $home_link_str::
>         used as the first component of gitweb's "breadcrumb trail":
>         `<home link> / <project> / <action>`.  Can be set at build time using
>         the `GITWEB_HOME_LINK_STR` variable.  By default it is set to "projects",
> -       as this link leads to the list of projects.  Other popular choice it to
> -       set it to the name of site.
> +       as this link leads to the list of projects.  Another popular choice is to
> +       set it to the name of site.  Note that it is treated as raw HTML so it
> +       should not be set from untrusted sources.

I wonder if we should change this... but it is issue unrelated to current patch, which doesn't make situation worse.

> +
> +@extra_breadcrumbs::
@external_breadcrumbs ???
Show 46 quoted lines
> +       Additional links to be added to the start of the breadcrumb trail before
> +       the home link, to pages that are logically "above" the gitweb projects
> +       list, such as the organization and department which host the gitweb
> +       server. Each element of the list is a reference to an array, in which
> +       element 0 is the link text (equivalent to `$home_link_str`) and element
> +       1 is the target URL (equivalent to `$home_link`).
> ++
> +For example, the following setting produces a breadcrumb trail like
> +"home / dev / projects / ..." where "projects" is the home link.
> +----------------------------------------------------------------------------
> +    our @extra_breadcrumbs = (
> +      [ 'home' => 'https://www.example.org/' ],
> +      [ 'dev'  => 'https://dev.example.org/' ],
> +    );
> +----------------------------------------------------------------------------
>
>  $logo_url::
>  $logo_label::
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index 8d69ada..f429f75 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -85,6 +85,9 @@ our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
>  # string of the home link on top of all pages
>  our $home_link_str = "++GITWEB_HOME_LINK_STR++";
>
> +# extra breadcrumbs preceding the home link
> +our @extra_breadcrumbs = ();
> +
>  # name of your site or organization to appear in page titles
>  # replace this with something more descriptive for clearer bookmarks
>  our $site_name = "++GITWEB_SITENAME++"
> @@ -3982,7 +3985,9 @@ sub print_nav_breadcrumbs_path {
>  sub print_nav_breadcrumbs {
>         my %opts = @_;
>
> -       print $cgi->a({-href => esc_url($home_link)}, $home_link_str) . " / ";
> +       for my $crumb (@extra_breadcrumbs, [ $home_link_str => $home_link ]) {
> +               print $cgi->a({-href => esc_url($crumb->[1])}, $crumb->[0]) . " / ";
> +       }
>         if (defined $project) {
>                 my @dirname = split '/', $project;
>                 my $projectbasename = pop @dirname;
> --
> 1.8.3.1.605.g85318f5
>

← back to recent threads