Gitweb - provide site headers and footers
This allows web sites with a header and footer standard for each page to add them to the pages produced by gitweb. Two new variables $site_header and $site_footer are defined (default to null) each of which can specify a file containing the header and footer html. In addition, if the $stylesheet variable is undefined, a new array @stylesheets (which defaults to a single element of gitweb.css) can be used to specify more than one style sheet. This allows the clasical gitweb.css styles to be retained, but a site wide style sheet used within the header and footer areas. Signed-off-by: Alan Chandler <alan@chandlerfamily.org.uk> Signed-off-by: Junio C Hamano <junkio@cox.net>
Alan Chandler committed
Oct 3, 2006 at 13:49 UTC
b2d3476e15cefdbd94366d4cf46fd05c1623034f
2 files changed
+42
-7
Makefile
+4
@@ -132,6 +132,8 @@ GITWEB_HOMETEXT = indextext.html
132
GITWEB_CSS = gitweb.css
133
GITWEB_LOGO = git-logo.png
134
GITWEB_FAVICON = git-favicon.png
135
+GITWEB_SITE_HEADER =
136
+GITWEB_SITE_FOOTER =
137
138
export prefix bindir gitexecdir template_dir GIT_PYTHON_DIR
139
@@ -675,6 +677,8 @@ gitweb/gitweb.cgi: gitweb/gitweb.perl
677
-e 's|++GITWEB_CSS++|$(GITWEB_CSS)|g' \
678
-e 's|++GITWEB_LOGO++|$(GITWEB_LOGO)|g' \
679
-e 's|++GITWEB_FAVICON++|$(GITWEB_FAVICON)|g' \
680
+ -e 's|++GITWEB_SITE_HEADER++|$(GITWEB_SITE_HEADER)|g' \
681
+ -e 's|++GITWEB_SITE_FOOTER++|$(GITWEB_SITE_FOOTER)|g' \
682
$< >$@+
683
chmod +x $@+
684
mv $@+ $@
gitweb/gitweb.perl
+38
-7
@@ -41,11 +41,19 @@ our $home_link_str = "++GITWEB_HOME_LINK_STR++";
41
# replace this with something more descriptive for clearer bookmarks
42
our $site_name = "++GITWEB_SITENAME++" || $ENV{'SERVER_NAME'} || "Untitled";
43
44
+# filename of html text to include at top of each page
45
+our $site_header = "++GITWEB_SITE_HEADER++";
46
# html text to include at home page
47
our $home_text = "++GITWEB_HOMETEXT++";
48
+# filename of html text to include at bottom of each page
49
+our $site_footer = "++GITWEB_SITE_FOOTER++";
50
+
51
+# URI of stylesheets
52
+our @stylesheets = ("++GITWEB_CSS++");
53
+our $stylesheet;
54
+# default is not to define style sheet, but it can be overwritten later
55
+undef $stylesheet;
56
47
-# URI of default stylesheet
48
-our $stylesheet = "++GITWEB_CSS++";
57
# URI of GIT logo
58
our $logo = "++GITWEB_LOGO++";
59
# URI of GIT favicon, assumed to be image/png type
@@ -1366,8 +1374,17 @@ sub git_header_html {
1374
<meta name="generator" content="gitweb/$version git/$git_version"/>
1375
<meta name="robots" content="index, nofollow"/>
1376
<title>$title</title>
1369
-<link rel="stylesheet" type="text/css" href="$stylesheet"/>
1377
EOF
1378
+# print out each stylesheet that exist
1379
+ if (defined $stylesheet) {
1380
+#provides backwards capability for those people who define style sheet in a config file
1381
+ print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1382
+ } else {
1383
+ foreach my $stylesheet (@stylesheets) {
1384
+ next unless $stylesheet;
1385
+ print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1386
+ }
1387
+ }
1388
if (defined $project) {
1389
printf('<link rel="alternate" title="%s log" '.
1390
'href="%s" type="application/rss+xml"/>'."\n",
@@ -1385,8 +1402,15 @@ EOF
1402
}
1403
1404
print "</head>\n" .
1388
- "<body>\n" .
1389
- "<div class=\"page_header\">\n" .
1405
+ "<body>\n";
1406
+
1407
+ if (-f $site_header) {
1408
+ open (my $fd, $site_header);
1409
+ print <$fd>;
1410
+ close $fd;
1411
+ }
1412
+
1413
+ print "<div class=\"page_header\">\n" .
1414
"<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1415
"<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1416
"</a>\n";
@@ -1437,8 +1461,15 @@ sub git_footer_html {
1461
print $cgi->a({-href => href(project=>undef, action=>"project_index"),
1462
-class => "rss_logo"}, "TXT") . "\n";
1463
}
1440
- print "</div>\n" .
1441
- "</body>\n" .
1464
+ print "</div>\n" ;
1465
+
1466
+ if (-f $site_footer) {
1467
+ open (my $fd, $site_footer);
1468
+ print <$fd>;
1469
+ close $fd;
1470
+ }
1471
+
1472
+ print "</body>\n" .
1473
"</html>";
1474
}
1475