Skip to content

Commit b2d3476

Browse files
akc42Junio C Hamano
authored andcommitted
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>
1 parent c8aeaaf commit b2d3476

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ GITWEB_HOMETEXT = indextext.html
132132
GITWEB_CSS = gitweb.css
133133
GITWEB_LOGO = git-logo.png
134134
GITWEB_FAVICON = git-favicon.png
135+
GITWEB_SITE_HEADER =
136+
GITWEB_SITE_FOOTER =
135137

136138
export prefix bindir gitexecdir template_dir GIT_PYTHON_DIR
137139

@@ -675,6 +677,8 @@ gitweb/gitweb.cgi: gitweb/gitweb.perl
675677
-e 's|++GITWEB_CSS++|$(GITWEB_CSS)|g' \
676678
-e 's|++GITWEB_LOGO++|$(GITWEB_LOGO)|g' \
677679
-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' \
678682
$< >$@+
679683
chmod +x $@+
680684
mv $@+ $@

gitweb/gitweb.perl

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,19 @@
4141
# replace this with something more descriptive for clearer bookmarks
4242
our $site_name = "++GITWEB_SITENAME++" || $ENV{'SERVER_NAME'} || "Untitled";
4343

44+
# filename of html text to include at top of each page
45+
our $site_header = "++GITWEB_SITE_HEADER++";
4446
# html text to include at home page
4547
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;
4656

47-
# URI of default stylesheet
48-
our $stylesheet = "++GITWEB_CSS++";
4957
# URI of GIT logo
5058
our $logo = "++GITWEB_LOGO++";
5159
# URI of GIT favicon, assumed to be image/png type
@@ -1366,8 +1374,17 @@ sub git_header_html {
13661374
<meta name="generator" content="gitweb/$version git/$git_version"/>
13671375
<meta name="robots" content="index, nofollow"/>
13681376
<title>$title</title>
1369-
<link rel="stylesheet" type="text/css" href="$stylesheet"/>
13701377
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+
}
13711388
if (defined $project) {
13721389
printf('<link rel="alternate" title="%s log" '.
13731390
'href="%s" type="application/rss+xml"/>'."\n",
@@ -1385,8 +1402,15 @@ sub git_header_html {
13851402
}
13861403

13871404
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" .
13901414
"<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
13911415
"<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
13921416
"</a>\n";
@@ -1437,8 +1461,15 @@ sub git_footer_html {
14371461
print $cgi->a({-href => href(project=>undef, action=>"project_index"),
14381462
-class => "rss_logo"}, "TXT") . "\n";
14391463
}
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" .
14421473
"</html>";
14431474
}
14441475

0 commit comments

Comments
 (0)