hgbook

changeset 722:96c012342355

More makefile, plus main index template and generator script.
author Giulio@puck
date Mon Jun 08 22:59:15 2009 +0200 (2009-06-08)
parents 716f76ea4a34
children 24f554c2067e
files .hgignore it/Makefile it/web/genindex.py it/web/index-template.html
line diff
     1.1 --- a/.hgignore	Mon Jun 08 18:34:23 2009 +0200
     1.2 +++ b/.hgignore	Mon Jun 08 22:59:15 2009 +0200
     1.3 @@ -24,6 +24,7 @@
     1.4  en/examples/results
     1.5  en/html
     1.6  en/svn
     1.7 +it/html
     1.8  stylesheets/system-xsl
     1.9  tools
    1.10  web/hgbook/.database.sqlite3
     2.1 --- a/it/Makefile	Mon Jun 08 18:34:23 2009 +0200
     2.2 +++ b/it/Makefile	Mon Jun 08 22:59:15 2009 +0200
     2.3 @@ -2,16 +2,24 @@
     2.4  
     2.5  xml-src-files := \
     2.6  	00book.xml \
     2.7 -	#app*.xml \
     2.8 -	ch*.xml
     2.9 +	$(wildcard ch*.xml)
    2.10 +	#$(wildcard app*.xml)
    2.11 +	
    2.12      
    2.13  obj-web := html
    2.14 +figs-web := ${obj-web}/figs
    2.15 +web-global := ../web
    2.16 +web-local := web
    2.17  
    2.18 -html: ${obj-web}/index.html
    2.19 +html: ${obj-web}/index.html ${web-local}/index-read.html.in
    2.20  
    2.21  #$(obj-web)/index.html: ../stylesheets/system-xsl .validated-00book.xml #../web/index-read.html.in
    2.22  $(obj-web)/index.html: .validated-00book.xml
    2.23  	xsltproc $(xsltproc-opts) -o $(obj-web)/x ../stylesheets/chunk-stylesheet.xsl 00book.xml
    2.24 +	cp ${web-global}/styles.css ${obj-web}
    2.25 +	mkdir -p ${figs-web}
    2.26 +	cp -f ${web-global}/icons/*.png $(figs-web)
    2.27 +	sed -i -e "s|/support/||g" ${obj-web}/*.html
    2.28  #	python ../web/texpand.py ../web/index-read.html.in html/read/index.html
    2.29  #	for i in $(obj-web-read)/*.html; do \
    2.30  #	  gzip -9 -c $$i > $$i.gz; \
    2.31 @@ -20,9 +28,19 @@
    2.32  #../stylesheets/system-xsl: $(system-xsl-dir)
    2.33  #	ln -s $< $@
    2.34  
    2.35 +$(web-local)/index-read.html.in: $(web-local)/genindex.py $(xml-src-files)
    2.36 +	cp $(web-local)/index-template.html $(obj-web)/index.html
    2.37 +	sed -i -e "s|{% block bodycontent %}{% endblock %}|$(shell cat $(web-local)/index-read.html.in)|g" ${obj-web}/index.html
    2.38 +
    2.39 +$(web-local)/genindex.py: $(xml-src-files)
    2.40 +	cd $(web-local) && ./genindex.py
    2.41 +
    2.42  valid: .validated-00book.xml
    2.43  
    2.44  .validated-00book.xml: $(xml-src-files) #examples/.run
    2.45  	xmllint $(xmllint-opts) $<
    2.46  	touch $@
    2.47  
    2.48 +clean:
    2.49 +	rm -f $(web-local)/index-read.html.in
    2.50 +	rm -rf $(obj-web)
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/it/web/genindex.py	Mon Jun 08 22:59:15 2009 +0200
     3.3 @@ -0,0 +1,58 @@
     3.4 +#!C:/Programmi/Python30/python
     3.5 +
     3.6 +import glob, os, re
     3.7 +
     3.8 +chapter_re = re.compile(r'<(chapter|appendix|preface)\s+id="([^"]+)">')
     3.9 +filename_re = re.compile(r'<\?dbhtml filename="([^"]+)"\?>')
    3.10 +title_re = re.compile(r'<title>(.*)</title>')
    3.11 +
    3.12 +chapters = (sorted(glob.glob('../ch*.xml')) +
    3.13 +            sorted(glob.glob('../app*.xml')))
    3.14 +
    3.15 +fp = open('index-read.html.in', 'w')
    3.16 +
    3.17 +print('''
    3.18 +<div class="navheader"><h1 class="booktitle">Mercurial: la guida definitiva<div class="authors">di Bryan O'Sullivan</div></h1></div>
    3.19 +<div class="book"><ul class="booktoc">''', file=fp)
    3.20 +
    3.21 +ch = 0
    3.22 +app = 0
    3.23 +ab = 0
    3.24 +for c in chapters:
    3.25 +    filename = None
    3.26 +    title = None
    3.27 +    chapid = None
    3.28 +    chaptype = None
    3.29 +    for line in open(c):
    3.30 +        m = chapter_re.search(line)
    3.31 +        if m:
    3.32 +            chaptype, chapid = m.groups()
    3.33 +        m = filename_re.search(line)
    3.34 +        if m:
    3.35 +            filename = m.group(1)
    3.36 +        m = title_re.search(line)
    3.37 +        if m:
    3.38 +            title = m.group(1)
    3.39 +        if filename and title and chapid:
    3.40 +            if chaptype == 'appendix':
    3.41 +                num = chr(ord('A') + app)
    3.42 +                app += 1
    3.43 +            else:
    3.44 +                num = ch
    3.45 +                ch += 1
    3.46 +            ab += 1
    3.47 +            date = os.popen('hg log -l1 --template "{date|isodate}" ' + c).read().split(None, 1)[0]
    3.48 +            args = {
    3.49 +                'ab': "ab"[ab % 2],
    3.50 +                'date': date,
    3.51 +                'chapid': chapid,
    3.52 +                'num': num,
    3.53 +                'filename': filename,
    3.54 +                'title': title,
    3.55 +                }
    3.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)
    3.57 +            break
    3.58 +
    3.59 +print('</ul></div>', file=fp)
    3.60 +
    3.61 +fp.close()
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/it/web/index-template.html	Mon Jun 08 22:59:15 2009 +0200
     4.3 @@ -0,0 +1,36 @@
     4.4 +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
     4.5 +<html>
     4.6 +  <head>
     4.7 +    <title>Mercurial: la guida definitiva</title>
     4.8 +    <link rel="stylesheet" href="styles.css" type="text/css"/>
     4.9 +    <!--
    4.10 +    <link rel="alternate" type="application/atom+xml" title="Comments"
    4.11 +      href="/feeds/comments/"/>
    4.12 +    -->
    4.13 +    <link rel="shortcut icon" type="image/png" href="figs/favicon.png"/>
    4.14 +    <!-- No comment system for italian translation
    4.15 +    <script type="text/javascript" src="/support/jquery.js"></script>
    4.16 +      <script type="text/javascript" src="/support/form.js"></script>
    4.17 +    <script type="text/javascript" src="/support/hsbook.js"></script>
    4.18 +    -->
    4.19 +  </head>
    4.20 +
    4.21 +  <body>
    4.22 +    {% block bodycontent %}{% endblock %}
    4.23 +
    4.24 +    <div class="hgbookfooter"> <p><img src="figs/rss.png"> Volete rimanere aggiornati? Abbonatevi al feed delle modifiche per qualsiasi capitolo o per <a class="feed" href="/feeds/comments/">l'intero libro</a>.</p> <p>Copyright 2006, 2007, 2008, 2009 Bryan O'Sullivan. Icone realizzate da <a href="mailto:mattahan@gmail.com">Paul Davey</a> alias <a href="http://mattahan.deviantart.com/">Mattahan</a>.</p>
    4.25 +    </div>
    4.26 +
    4.27 +    <!-- Also, no need for Google Analytics on the italian translation
    4.28 +    <script type="text/javascript">
    4.29 +    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    4.30 +    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    4.31 +    </script>
    4.32 +    <script type="text/javascript">
    4.33 +    try {
    4.34 +    var pageTracker = _gat._getTracker("UA-1805907-5");
    4.35 +    pageTracker._trackPageview();
    4.36 +    } catch(err) {}</script>
    4.37 +    -->
    4.38 +  </body>
    4.39 +</html>