X-Git-Url: https://git.ladys.computer/Gitweb/blobdiff_plain/635503ec11fb1e92144d9a18670414450769d394454c0d4b56a4b15a6893769b..95ffa50f893aed551b698a71db6cd403019dba0f1c49d2e9699d98e2995a0fea:/gitweb.perl diff --git a/gitweb.perl b/gitweb.perl index bf5e641..cf34c5b 100755 --- a/gitweb.perl +++ b/gitweb.perl @@ -116,6 +116,14 @@ our $projects_list = "++GITWEB_LIST++"; # the width (in characters) of the projects list "Description" column our $projects_list_description_width = 25; +# group projects by category on the projects list +# (enabled if this variable evaluates to true) +our $projects_list_group_categories = 0; + +# default category if none specified +# (leave the empty string for no category) +our $project_list_default_category = ""; + # default order of projects list # valid values are none, project, descr, owner, and age our $default_projects_order = "project"; @@ -2585,6 +2593,12 @@ sub git_get_project_description { return git_get_file_or_project_config($path, 'description'); } +sub git_get_project_category { + my $path = shift; + return git_get_file_or_project_config($path, 'category'); +} + + # supported formats: # * $GIT_DIR/ctags/ file (in 'ctags' subdirectory) # - if its contents is a number, use it as tag weight, @@ -4810,8 +4824,9 @@ sub git_patchset_body { # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . -# fills project list info (age, description, owner, forks) for each -# project in the list, removing invalid projects from returned list +# fills project list info (age, description, owner, category, forks) +# for each project in the list, removing invalid projects from +# returned list # NOTE: modifies $projlist, but does not remove entries from it sub fill_project_list_info { my ($projlist, $check_forks) = @_; @@ -4845,12 +4860,35 @@ sub fill_project_list_info { } } $show_ctags and $pr->{'ctags'} = git_get_project_ctags($pr->{'path'}); + if ($projects_list_group_categories && !defined $pr->{'category'}) { + my $cat = git_get_project_category($pr->{'path'}) || + $project_list_default_category; + $pr->{'category'} = to_utf8($cat); + } + push @projects, $pr; } return @projects; } +# returns a hash of categories, containing the list of project +# belonging to each category +sub build_projlist_by_category { + my ($projlist, $from, $to) = @_; + my %categories; + + $from = 0 unless defined $from; + $to = $#$projlist if (!defined $to || $#$projlist < $to); + + for (my $i = $from; $i <= $to; $i++) { + my $pr = $projlist->[$i]; + push @{$categories{ $pr->{'category'} }}, $pr; + } + + return wantarray ? %categories : \%categories; +} + # print 'sort by' element, generating 'sort by $name' replay link # if that order is not selected sub print_sort_th { @@ -4973,7 +5011,26 @@ sub git_project_list_body { print "\n" . # for links "\n"; } - git_project_list_rows(\@projects, $from, $to, $check_forks); + + if ($projects_list_group_categories) { + # only display categories with projects in the $from-$to window + @projects = sort {$a->{'category'} cmp $b->{'category'}} @projects[$from..$to]; + my %categories = build_projlist_by_category(\@projects, $from, $to); + foreach my $cat (sort keys %categories) { + unless ($cat eq "") { + print "\n"; + if ($check_forks) { + print "\n"; + } + print "".esc_html($cat)."\n"; + print "\n"; + } + + git_project_list_rows($categories{$cat}, undef, undef, $check_forks); + } + } else { + git_project_list_rows(\@projects, $from, $to, $check_forks); + } if (defined $extra) { print "\n";