hgbook

annotate web/genindex.py @ 864:9afafe9af05f

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