git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / Atom feed
* [PATCH] gitweb: allow extra breadcrumbs to prefix the trail
@ 2013-07-02 15:49 Tony Finch
  2013-07-02 15:49 ` [PATCH v2] " Tony Finch
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Tony Finch @ 2013-07-02 15:49 UTC (permalink / raw)
  To: git

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(+)

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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v2] gitweb: allow extra breadcrumbs to prefix the trail
  2013-07-02 15:49 [PATCH] gitweb: allow extra breadcrumbs to prefix the trail Tony Finch
@ 2013-07-02 15:49 ` Tony Finch
  2013-07-03 21:59 ` [PATCH] " Jonathan Nieder
  2013-07-04 17:02 ` [PATCH v3] " Tony Finch
  2 siblings, 0 replies; 15+ messages in thread
From: Tony Finch @ 2013-07-02 15:49 UTC (permalink / raw)
  To: git

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(-)

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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] gitweb: allow extra breadcrumbs to prefix the trail
  2013-07-02 15:49 [PATCH] gitweb: allow extra breadcrumbs to prefix the trail Tony Finch
  2013-07-02 15:49 ` [PATCH v2] " Tony Finch
@ 2013-07-03 21:59 ` Jonathan Nieder
  2013-07-03 22:11   ` Jakub Narębski
  2013-07-04 17:02 ` [PATCH v3] " Tony Finch
  2 siblings, 1 reply; 15+ messages in thread
From: Jonathan Nieder @ 2013-07-03 21:59 UTC (permalink / raw)
  To: Tony Finch; +Cc: git, Jakub Narebski

(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.

> 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.)
> +
>  $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;
> -- 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] gitweb: allow extra breadcrumbs to prefix the trail
  2013-07-03 21:59 ` [PATCH] " Jonathan Nieder
@ 2013-07-03 22:11   ` Jakub Narębski
  2013-07-04  8:44     ` Tony Finch
  0 siblings, 1 reply; 15+ messages in thread
From: Jakub Narębski @ 2013-07-03 22:11 UTC (permalink / raw)
  To: Jonathan Nieder; +Cc: Tony Finch, git

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 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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] gitweb: allow extra breadcrumbs to prefix the trail
  2013-07-03 22:11   ` Jakub Narębski
@ 2013-07-04  8:44     ` Tony Finch
  2013-07-04 14:40       ` Jakub Narębski
  0 siblings, 1 reply; 15+ messages in thread
From: Tony Finch @ 2013-07-04  8:44 UTC (permalink / raw)
  To: Jakub Narębski; +Cc: Jonathan Nieder, git

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1474 bytes --]

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::
> >> +     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.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] gitweb: allow extra breadcrumbs to prefix the trail
  2013-07-04  8:44     ` Tony Finch
@ 2013-07-04 14:40       ` Jakub Narębski
  2013-07-04 15:11         ` Tony Finch
  0 siblings, 1 reply; 15+ messages in thread
From: Jakub Narębski @ 2013-07-04 14:40 UTC (permalink / raw)
  To: Tony Finch; +Cc: Jonathan Nieder, git

On Thu, Jul 4, 2013 at 10:44 AM, Tony Finch <dot@dotat.at> wrote:
> 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.

>>>> +     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.

>
>>> 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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] gitweb: allow extra breadcrumbs to prefix the trail
  2013-07-04 14:40       ` Jakub Narębski
@ 2013-07-04 15:11         ` Tony Finch
  2013-07-04 15:34           ` Jakub Narębski
  0 siblings, 1 reply; 15+ messages in thread
From: Tony Finch @ 2013-07-04 15:11 UTC (permalink / raw)
  To: Jakub Narębski; +Cc: Jonathan Nieder, git

[-- Attachment #1: Type: TEXT/PLAIN, Size: 997 bytes --]

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.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] gitweb: allow extra breadcrumbs to prefix the trail
  2013-07-04 15:11         ` Tony Finch
@ 2013-07-04 15:34           ` Jakub Narębski
  2013-07-04 15:56             ` Tony Finch
  0 siblings, 1 reply; 15+ messages in thread
From: Jakub Narębski @ 2013-07-04 15:34 UTC (permalink / raw)
  To: Tony Finch; +Cc: Jonathan Nieder, git

On Thu, Jul 4, 2013 at 5:11 PM, Tony Finch <dot@dotat.at> wrote:
> 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.

>> 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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] gitweb: allow extra breadcrumbs to prefix the trail
  2013-07-04 15:34           ` Jakub Narębski
@ 2013-07-04 15:56             ` Tony Finch
  2013-07-04 16:32               ` Jakub Narębski
  0 siblings, 1 reply; 15+ messages in thread
From: Tony Finch @ 2013-07-04 15:56 UTC (permalink / raw)
  To: Jakub Narębski; +Cc: Jonathan Nieder, git

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1405 bytes --]

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.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] gitweb: allow extra breadcrumbs to prefix the trail
  2013-07-04 15:56             ` Tony Finch
@ 2013-07-04 16:32               ` Jakub Narębski
  2013-07-04 17:08                 ` Tony Finch
  0 siblings, 1 reply; 15+ messages in thread
From: Jakub Narębski @ 2013-07-04 16:32 UTC (permalink / raw)
  To: Tony Finch; +Cc: Jonathan Nieder, git

On Thu, Jul 4, 2013 at 5:56 PM, Tony Finch <dot@dotat.at> wrote:
> 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?

>> 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.

>> 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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v3] gitweb: allow extra breadcrumbs to prefix the trail
  2013-07-02 15:49 [PATCH] gitweb: allow extra breadcrumbs to prefix the trail Tony Finch
  2013-07-02 15:49 ` [PATCH v2] " Tony Finch
  2013-07-03 21:59 ` [PATCH] " Jonathan Nieder
@ 2013-07-04 17:02 ` Tony Finch
  2013-07-04 17:42   ` Jakub Narębski
  2013-07-07  1:05   ` Jonathan Nieder
  2 siblings, 2 replies; 15+ messages in thread
From: Tony Finch @ 2013-07-04 17:02 UTC (permalink / raw)
  To: git; +Cc: Jakub Narębski, Jonathan Nieder

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(-)

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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] gitweb: allow extra breadcrumbs to prefix the trail
  2013-07-04 16:32               ` Jakub Narębski
@ 2013-07-04 17:08                 ` Tony Finch
  2013-07-04 17:31                   ` Jakub Narębski
  0 siblings, 1 reply; 15+ messages in thread
From: Tony Finch @ 2013-07-04 17:08 UTC (permalink / raw)
  To: Jakub Narębski; +Cc: Jonathan Nieder, git

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1464 bytes --]

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.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] gitweb: allow extra breadcrumbs to prefix the trail
  2013-07-04 17:08                 ` Tony Finch
@ 2013-07-04 17:31                   ` Jakub Narębski
  0 siblings, 0 replies; 15+ messages in thread
From: Jakub Narębski @ 2013-07-04 17:31 UTC (permalink / raw)
  To: Tony Finch; +Cc: Jonathan Nieder, git

On Thu, Jul 4, 2013 at 7:08 PM, Tony Finch <dot@dotat.at> wrote:
> 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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v3] gitweb: allow extra breadcrumbs to prefix the trail
  2013-07-04 17:02 ` [PATCH v3] " Tony Finch
@ 2013-07-04 17:42   ` Jakub Narębski
  2013-07-07  1:05   ` Jonathan Nieder
  1 sibling, 0 replies; 15+ messages in thread
From: Jakub Narębski @ 2013-07-04 17:42 UTC (permalink / raw)
  To: Tony Finch; +Cc: git, Jonathan Nieder

On Thu, Jul 4, 2013 at 7:02 PM, Tony Finch <dot@dotat.at> 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.
>
> 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>

> ---
>  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 ???

> +       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
>

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v3] gitweb: allow extra breadcrumbs to prefix the trail
  2013-07-04 17:02 ` [PATCH v3] " Tony Finch
  2013-07-04 17:42   ` Jakub Narębski
@ 2013-07-07  1:05   ` Jonathan Nieder
  1 sibling, 0 replies; 15+ messages in thread
From: Jonathan Nieder @ 2013-07-07  1:05 UTC (permalink / raw)
  To: Tony Finch; +Cc: git, Jakub Narębski

Tony Finch wrote:

> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

Yep, fwiw this version looks perfect to me. :)

Thanks.

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2013-07-07  1:06 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-02 15:49 [PATCH] gitweb: allow extra breadcrumbs to prefix the trail Tony Finch
2013-07-02 15:49 ` [PATCH v2] " Tony Finch
2013-07-03 21:59 ` [PATCH] " Jonathan Nieder
2013-07-03 22:11   ` Jakub Narębski
2013-07-04  8:44     ` Tony Finch
2013-07-04 14:40       ` Jakub Narębski
2013-07-04 15:11         ` Tony Finch
2013-07-04 15:34           ` Jakub Narębski
2013-07-04 15:56             ` Tony Finch
2013-07-04 16:32               ` Jakub Narębski
2013-07-04 17:08                 ` Tony Finch
2013-07-04 17:31                   ` Jakub Narębski
2013-07-04 17:02 ` [PATCH v3] " Tony Finch
2013-07-04 17:42   ` Jakub Narębski
2013-07-07  1:05   ` Jonathan Nieder

git@vger.kernel.org list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ https://public-inbox.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for the project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git