hgbook
diff web/genindex.py @ 662:bc9dc4f2f912
Add tip.png and warning.png
author | Dongsheng Song <dongsheng.song@gmail.com> |
---|---|
date | Tue Mar 31 11:11:43 2009 +0800 (2009-03-31) |
parents | |
children | 0ffae4ee4c47 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/web/genindex.py Tue Mar 31 11:11:43 2009 +0800 1.3 @@ -0,0 +1,60 @@ 1.4 +#!/usr/bin/env python 1.5 + 1.6 +import glob, os, re 1.7 + 1.8 +chapter_re = re.compile(r'<(chapter|appendix|preface)\s+id="([^"]+)">') 1.9 +filename_re = re.compile(r'<\?dbhtml filename="([^"]+)"\?>') 1.10 +title_re = re.compile(r'<title>(.*)</title>') 1.11 + 1.12 +chapters = glob.glob('../en/ch*.xml') + glob.glob('../en/app*.xml') 1.13 + 1.14 +fp = open('index-read.html.in', 'w') 1.15 + 1.16 +print >> fp, '''<!-- -*- html -*- --> 1.17 +{% extends "boilerplate.html" %} 1.18 +{% block bodycontent %} 1.19 +<div class="navheader"><h1 class="booktitle">Mercurial: The Definitive Guide<div class="authors">by Bryan O'Sullivan</div></h1></div> 1.20 +<div class="book"><ul class="booktoc">''' 1.21 + 1.22 +ch = 0 1.23 +app = 0 1.24 +ab = 0 1.25 +for c in chapters: 1.26 + filename = None 1.27 + title = None 1.28 + chapid = None 1.29 + chaptype = None 1.30 + for line in open(c): 1.31 + m = chapter_re.search(line) 1.32 + if m: 1.33 + chaptype, chapid = m.groups() 1.34 + m = filename_re.search(line) 1.35 + if m: 1.36 + filename = m.group(1) 1.37 + m = title_re.search(line) 1.38 + if m: 1.39 + title = m.group(1) 1.40 + if filename and title and chapid: 1.41 + if chaptype == 'appendix': 1.42 + num = chr(ord('A') + app) 1.43 + app += 1 1.44 + else: 1.45 + num = ch 1.46 + ch += 1 1.47 + ab += 1 1.48 + date = os.popen('hg log -l1 --template "{date|isodate}" ' + c).read().split(None, 1)[0] 1.49 + args = { 1.50 + 'ab': "ab"[ab % 2], 1.51 + 'date': date, 1.52 + 'chapid': chapid, 1.53 + 'num': num, 1.54 + 'filename': filename, 1.55 + 'title': title, 1.56 + } 1.57 + print >> fp, '<li class="zebra_%(ab)s"><span class="chapinfo">%(date)s<a href="/feeds/comments/%(chapid)s/"><img src="/support/figs/rss.png"/></a></span>%(num)s. <a href="%(filename)s">%(title)s</a></li>' % args 1.58 + break 1.59 + 1.60 +print >> fp, '''</ul></div> 1.61 +{% endblock %}''' 1.62 + 1.63 +fp.close()