changeset 4084:51e52db6b40d

hgweb: allow static files to be served directly by the HTTP server
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Thu, 15 Feb 2007 08:51:32 -0200
parents 33c369afec94
children 719488a98ebe
files doc/hgrc.5.txt mercurial/hgweb/hgweb_mod.py mercurial/hgweb/hgwebdir_mod.py templates/gitweb/header.tmpl templates/header.tmpl
diffstat 5 files changed, 19 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/doc/hgrc.5.txt	Wed Feb 14 15:20:06 2007 -0700
+++ b/doc/hgrc.5.txt	Thu Feb 15 08:51:32 2007 -0200
@@ -507,6 +507,11 @@
   push_ssl;;
     Whether to require that inbound pushes be transported over SSL to
     prevent password sniffing.  Default is true.
+  staticurl;;
+    Base URL to use for static files. If unset, static files (e.g.
+    the hgicon.png favicon) will be served by the CGI script itself.
+    Use this setting to serve them directly with the HTTP server.
+    Example: "http://hgserver/static/"
   stripes;;
     How many lines a "zebra stripe" should span in multiline output.
     Default is 1; set to 0 to disable.
--- a/mercurial/hgweb/hgweb_mod.py	Wed Feb 14 15:20:06 2007 -0700
+++ b/mercurial/hgweb/hgweb_mod.py	Thu Feb 15 08:51:32 2007 -0200
@@ -772,6 +772,9 @@
         port = req.env["SERVER_PORT"]
         port = port != "80" and (":" + port) or ""
         urlbase = 'http://%s%s' % (req.env['SERVER_NAME'], port)
+        staticurl = self.config("web", "staticurl") or req.url + 'static/'
+        if not staticurl.endswith('/'):
+            staticurl += '/'
 
         if not self.reponame:
             self.reponame = (self.config("web", "name")
@@ -780,6 +783,7 @@
 
         self.t = templater.templater(mapfile, templater.common_filters,
                                      defaults={"url": req.url,
+                                               "staticurl": staticurl,
                                                "urlbase": urlbase,
                                                "repo": self.reponame,
                                                "header": header,
--- a/mercurial/hgweb/hgwebdir_mod.py	Wed Feb 14 15:20:06 2007 -0700
+++ b/mercurial/hgweb/hgwebdir_mod.py	Thu Feb 15 08:51:32 2007 -0200
@@ -88,6 +88,10 @@
         if not url.endswith('/'):
             url += '/'
 
+        staticurl = config('web', 'staticurl') or url + 'static/'
+        if not staticurl.endswith('/'):
+            staticurl += '/'
+
         style = self.style
         if style is None:
             style = config('web', 'style', '')
@@ -98,7 +102,8 @@
                                    defaults={"header": header,
                                              "footer": footer,
                                              "motd": motd,
-                                             "url": url})
+                                             "url": url,
+                                             "staticurl": staticurl})
 
         def archivelist(ui, nodeid, url):
             allowed = ui.configlist("web", "allow_archive", untrusted=True)
--- a/templates/gitweb/header.tmpl	Wed Feb 14 15:20:06 2007 -0700
+++ b/templates/gitweb/header.tmpl	Thu Feb 15 08:51:32 2007 -0200
@@ -4,7 +4,7 @@
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
 <head>
-<link rel="icon" href="{url}static/hgicon.png" type="image/png">
+<link rel="icon" href="{staticurl}hgicon.png" type="image/png">
 <meta name="robots" content="index, nofollow"/>
-<link rel="stylesheet" href="{url}static/style-gitweb.css" type="text/css" />
+<link rel="stylesheet" href="{staticurl}style-gitweb.css" type="text/css" />
 
--- a/templates/header.tmpl	Wed Feb 14 15:20:06 2007 -0700
+++ b/templates/header.tmpl	Thu Feb 15 08:51:32 2007 -0200
@@ -3,6 +3,6 @@
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html>
 <head>
-<link rel="icon" href="#url#static/hgicon.png" type="image/png">
+<link rel="icon" href="#staticurl#hgicon.png" type="image/png">
 <meta name="robots" content="index, nofollow" />
-<link rel="stylesheet" href="#url#static/style.css" type="text/css" />
+<link rel="stylesheet" href="#staticurl#style.css" type="text/css" />