Mercurial > hgbook
comparison web/genindex.py @ 698:9e8e5292acaa
Generate a nice readable index.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Fri, 27 Mar 2009 00:41:15 -0700 |
parents | |
children | 0ffae4ee4c47 |
comparison
equal
deleted
inserted
replaced
697:7893b3824715 | 698:9e8e5292acaa |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 import glob, os, re | |
4 | |
5 chapter_re = re.compile(r'<(chapter|appendix|preface)\s+id="([^"]+)">') | |
6 filename_re = re.compile(r'<\?dbhtml filename="([^"]+)"\?>') | |
7 title_re = re.compile(r'<title>(.*)</title>') | |
8 | |
9 chapters = glob.glob('../en/ch*.xml') + glob.glob('../en/app*.xml') | |
10 | |
11 fp = open('index-read.html.in', 'w') | |
12 | |
13 print >> fp, '''<!-- -*- html -*- --> | |
14 {% extends "boilerplate.html" %} | |
15 {% block bodycontent %} | |
16 <div class="navheader"><h1 class="booktitle">Mercurial: The Definitive Guide<div class="authors">by Bryan O'Sullivan</div></h1></div> | |
17 <div class="book"><ul class="booktoc">''' | |
18 | |
19 ch = 0 | |
20 app = 0 | |
21 ab = 0 | |
22 for c in chapters: | |
23 filename = None | |
24 title = None | |
25 chapid = None | |
26 chaptype = None | |
27 for line in open(c): | |
28 m = chapter_re.search(line) | |
29 if m: | |
30 chaptype, chapid = m.groups() | |
31 m = filename_re.search(line) | |
32 if m: | |
33 filename = m.group(1) | |
34 m = title_re.search(line) | |
35 if m: | |
36 title = m.group(1) | |
37 if filename and title and chapid: | |
38 if chaptype == 'appendix': | |
39 num = chr(ord('A') + app) | |
40 app += 1 | |
41 else: | |
42 num = ch | |
43 ch += 1 | |
44 ab += 1 | |
45 date = os.popen('hg log -l1 --template "{date|isodate}" ' + c).read().split(None, 1)[0] | |
46 args = { | |
47 'ab': "ab"[ab % 2], | |
48 'date': date, | |
49 'chapid': chapid, | |
50 'num': num, | |
51 'filename': filename, | |
52 'title': title, | |
53 } | |
54 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 | |
55 break | |
56 | |
57 print >> fp, '''</ul></div> | |
58 {% endblock %}''' | |
59 | |
60 fp.close() |