comparison mercurial/hgweb.py @ 2148:c72e618c1204

Add MOTD display to hgweb and hgwebdir. The hgweb "footer" template now has space for an optional message of the day (MOTD). This is used in two contexts: 1) On the hgwebdir index page 2) On various pages of each individual repo For both cases, the MOTD is read out of an entry named "motd" in the [web] section of a config file -- the only difference is which file is used. For #1, you need to add the section to hgweb.config; for #2, you need to add to the repo's .hgrc file. I suggest something like this: [web] motd = <p>To download these repositories, <a href="http://www.selenic.com/mercurial">get Mercurial</a> and then type something like:</p><p><pre>hg clone http://gs3080.sp.cs.cmu.edu/hg.cgi/cpmpy</pre></p>You can also click the Download links to get an archive of the latest revision. An online sample is available here: http://gs3080.sp.cs.cmu.edu/hg.cgi
author Colin McMillen <mcmillen@cs.cmu.edu>
date Thu, 27 Apr 2006 22:11:13 -0700
parents 8a85dbbadddf
children 29eeb2717915
comparison
equal deleted inserted replaced
2147:b7225adb2e0b 2148:c72e618c1204
725 725
726 def header(**map): 726 def header(**map):
727 yield self.t("header", **map) 727 yield self.t("header", **map)
728 728
729 def footer(**map): 729 def footer(**map):
730 yield self.t("footer", **map) 730 yield self.t("footer",
731 motd=self.repo.ui.config("web", "motd", ""),
732 **map)
731 733
732 def expand_form(form): 734 def expand_form(form):
733 shortcuts = { 735 shortcuts = {
734 'cl': [('cmd', ['changelog']), ('rev', None)], 736 'cl': [('cmd', ['changelog']), ('rev', None)],
735 'cs': [('cmd', ['changeset']), ('node', None)], 737 'cs': [('cmd', ['changeset']), ('node', None)],
1004 class hgwebdir(object): 1006 class hgwebdir(object):
1005 def __init__(self, config): 1007 def __init__(self, config):
1006 def cleannames(items): 1008 def cleannames(items):
1007 return [(name.strip(os.sep), path) for name, path in items] 1009 return [(name.strip(os.sep), path) for name, path in items]
1008 1010
1011 self.motd = ""
1009 if isinstance(config, (list, tuple)): 1012 if isinstance(config, (list, tuple)):
1010 self.repos = cleannames(config) 1013 self.repos = cleannames(config)
1011 elif isinstance(config, dict): 1014 elif isinstance(config, dict):
1012 self.repos = cleannames(config.items()) 1015 self.repos = cleannames(config.items())
1013 self.repos.sort() 1016 self.repos.sort()
1014 else: 1017 else:
1015 cp = ConfigParser.SafeConfigParser() 1018 cp = ConfigParser.SafeConfigParser()
1016 cp.read(config) 1019 cp.read(config)
1017 self.repos = [] 1020 self.repos = []
1021 if cp.has_section('web') and cp.has_option('web', 'motd'):
1022 self.motd = cp.get('web', 'motd')
1018 if cp.has_section('paths'): 1023 if cp.has_section('paths'):
1019 self.repos.extend(cleannames(cp.items('paths'))) 1024 self.repos.extend(cleannames(cp.items('paths')))
1020 if cp.has_section('collections'): 1025 if cp.has_section('collections'):
1021 for prefix, root in cp.items('collections'): 1026 for prefix, root in cp.items('collections'):
1022 for path in util.walkrepos(root): 1027 for path in util.walkrepos(root):
1030 def run(self, req=hgrequest()): 1035 def run(self, req=hgrequest()):
1031 def header(**map): 1036 def header(**map):
1032 yield tmpl("header", **map) 1037 yield tmpl("header", **map)
1033 1038
1034 def footer(**map): 1039 def footer(**map):
1035 yield tmpl("footer", **map) 1040 yield tmpl("footer", motd=self.motd, **map)
1036 1041
1037 m = os.path.join(templater.templatepath(), "map") 1042 m = os.path.join(templater.templatepath(), "map")
1038 tmpl = templater.templater(m, templater.common_filters, 1043 tmpl = templater.templater(m, templater.common_filters,
1039 defaults={"header": header, 1044 defaults={"header": header,
1040 "footer": footer}) 1045 "footer": footer})