git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] gitweb: add HTML ids for categories and projects

From
AIAlexandre Erwin Ittner <alexandre@ittner.com.br>
Date
Oct 9, 2014, 02:16 UTC
Message-ID
<20141008231631.8466676f4f808cb919c677e4@ittner.com.br>

Add the attribute "id" to category headers and project rows in the web interface. These ids are intended to work as anchors, allowing links with the fragment component pointing to a given category, which may be useful when dealing with long project lists.

IDs are generated from the category name and project paths prefixed with "category-" and "project-", respectively, so links may follow the format http://example.com/gitweb/#category-drivers. Spaces are replaced by an "-" and special characters are escaped but, to ensure uniqueness, no other changes are made.

Signed-off-by: Alexandre Erwin Ittner <alexandre@ittner.com.br>
---
 gitweb/gitweb.perl |   21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index a9f57d6..07f03b1 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1718,6 +1718,19 @@ sub project_in_list {
 	return @list && scalar(grep { $_->{'path'} eq $project } @list);
 }
 
+
+# Make a XHTML entity ID from the given string(s).
+# All arguments are concatenated with an "-", spaces are replaced by "-",
+# and other characters are escaped so the name can be used within a XML
+# attribute.
+# Eg. make_xhtml_id("project", "foo.git")   -->  "project-foo.git"
+sub make_xhtml_id {
+	my $id = join("-", @_);
+	$id =~ s/\s/-/g;
+	return esc_attr($id);
+}
+
+
 ## ----------------------------------------------------------------------
 ## HTML aware string manipulation
 
@@ -5681,11 +5694,12 @@ sub git_project_list_rows {
 	my $alternate = 1;
 	for (my $i = $from; $i <= $to; $i++) {
 		my $pr = $projlist->[$i];
+		my $pr_id = make_xhtml_id("project", $pr->{'path'});
 
 		if ($alternate) {
-			print "<tr class=\"dark\">\n";
+			print "<tr id=\"$pr_id\" class=\"dark\">\n";
 		} else {
-			print "<tr class=\"light\">\n";
+			print "<tr id=\"$pr_id\" class=\"light\">\n";
 		}
 		$alternate ^= 1;
 
@@ -5802,7 +5816,8 @@ sub git_project_list_body {
 				if ($check_forks) {
 					print "<td></td>\n";
 				}
-				print "<td class=\"category\" colspan=\"5\">".esc_html($cat)."</td>\n";
+				my $cat_id = make_xhtml_id("category", $cat);
+				print "<td id=\"$cat_id\" class=\"category\" colspan=\"5\">".esc_html($cat)."</td>\n";
 				print "</tr>\n";
 			}
 
-- 
1.7.9.5
Message 1 of 1 in “gitweb: add HTML ids for categories and projects”
  1. gitweb: add HTML ids for categories and projectsAlexandre Erwin Ittner, Oct 9, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.