hgbook
diff it/web/genindex.py @ 731:68c4d16d2bf4
Adding JavaScript for TOC effects in single chapter pages.
author | Giulio@puck |
---|---|
date | Wed Jun 17 18:18:09 2009 +0200 (2009-06-17) |
parents | |
children | 23ebfe2bd091 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/it/web/genindex.py Wed Jun 17 18:18:09 2009 +0200 1.3 @@ -0,0 +1,58 @@ 1.4 +#!C:/Programmi/Python30/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 = (sorted(glob.glob('../ch*.xml')) + 1.13 + sorted(glob.glob('../app*.xml'))) 1.14 + 1.15 +fp = open('index-read.html.in', 'w') 1.16 + 1.17 +print(''' 1.18 +<div class="navheader"><h1 class="booktitle">Mercurial: la guida definitiva<div class="authors">di Bryan O'Sullivan</div></h1></div> 1.19 +<div class="book"><ul class="booktoc">''', file=fp) 1.20 + 1.21 +ch = 0 1.22 +app = 0 1.23 +ab = 0 1.24 +for c in chapters: 1.25 + filename = None 1.26 + title = None 1.27 + chapid = None 1.28 + chaptype = None 1.29 + for line in open(c): 1.30 + m = chapter_re.search(line) 1.31 + if m: 1.32 + chaptype, chapid = m.groups() 1.33 + m = filename_re.search(line) 1.34 + if m: 1.35 + filename = m.group(1) 1.36 + m = title_re.search(line) 1.37 + if m: 1.38 + title = m.group(1) 1.39 + if filename and title and chapid: 1.40 + if chaptype == 'appendix': 1.41 + num = chr(ord('A') + app) 1.42 + app += 1 1.43 + else: 1.44 + num = ch 1.45 + ch += 1 1.46 + ab += 1 1.47 + date = os.popen('hg log -l1 --template "{date|isodate}" ' + c).read().split(None, 1)[0] 1.48 + args = { 1.49 + 'ab': "ab"[ab % 2], 1.50 + 'date': date, 1.51 + 'chapid': chapid, 1.52 + 'num': num, 1.53 + 'filename': filename, 1.54 + 'title': title, 1.55 + } 1.56 + print('<li class="zebra_%(ab)s"><span class="chapinfo">%(date)s<a href="/feeds/comments/%(chapid)s/"><img src="figs/rss.png"/></a></span>%(num)s. <a href="%(filename)s">%(title)s</a></li>' % args, file=fp) 1.57 + break 1.58 + 1.59 +print('</ul></div>', file=fp) 1.60 + 1.61 +fp.close()