Commits

Anonymous committed 96c0123

More makefile, plus main index template and generator script.

Comments (0)

Files changed (4)

 en/examples/results
 en/html
 en/svn
+it/html
 stylesheets/system-xsl
 tools
 web/hgbook/.database.sqlite3
 
 xml-src-files := \
 	00book.xml \
-	#app*.xml \
-	ch*.xml
+	$(wildcard ch*.xml)
+	#$(wildcard app*.xml)
+	
     
 obj-web := html
+figs-web := ${obj-web}/figs
+web-global := ../web
+web-local := web
 
-html: ${obj-web}/index.html
+html: ${obj-web}/index.html ${web-local}/index-read.html.in
 
 #$(obj-web)/index.html: ../stylesheets/system-xsl .validated-00book.xml #../web/index-read.html.in
 $(obj-web)/index.html: .validated-00book.xml
 	xsltproc $(xsltproc-opts) -o $(obj-web)/x ../stylesheets/chunk-stylesheet.xsl 00book.xml
+	cp ${web-global}/styles.css ${obj-web}
+	mkdir -p ${figs-web}
+	cp -f ${web-global}/icons/*.png $(figs-web)
+	sed -i -e "s|/support/||g" ${obj-web}/*.html
 #	python ../web/texpand.py ../web/index-read.html.in html/read/index.html
 #	for i in $(obj-web-read)/*.html; do \
 #	  gzip -9 -c $$i > $$i.gz; \
 #../stylesheets/system-xsl: $(system-xsl-dir)
 #	ln -s $< $@
 
+$(web-local)/index-read.html.in: $(web-local)/genindex.py $(xml-src-files)
+	cp $(web-local)/index-template.html $(obj-web)/index.html
+	sed -i -e "s|{% block bodycontent %}{% endblock %}|$(shell cat $(web-local)/index-read.html.in)|g" ${obj-web}/index.html
+
+$(web-local)/genindex.py: $(xml-src-files)
+	cd $(web-local) && ./genindex.py
+
 valid: .validated-00book.xml
 
 .validated-00book.xml: $(xml-src-files) #examples/.run
 	xmllint $(xmllint-opts) $<
 	touch $@
 
+clean:
+	rm -f $(web-local)/index-read.html.in
+	rm -rf $(obj-web)

it/web/genindex.py

+#!C:/Programmi/Python30/python
+
+import glob, os, re
+
+chapter_re = re.compile(r'<(chapter|appendix|preface)\s+id="([^"]+)">')
+filename_re = re.compile(r'<\?dbhtml filename="([^"]+)"\?>')
+title_re = re.compile(r'<title>(.*)</title>')
+
+chapters = (sorted(glob.glob('../ch*.xml')) +
+            sorted(glob.glob('../app*.xml')))
+
+fp = open('index-read.html.in', 'w')
+
+print('''
+<div class="navheader"><h1 class="booktitle">Mercurial: la guida definitiva<div class="authors">di Bryan O'Sullivan</div></h1></div>
+<div class="book"><ul class="booktoc">''', file=fp)
+
+ch = 0
+app = 0
+ab = 0
+for c in chapters:
+    filename = None
+    title = None
+    chapid = None
+    chaptype = None
+    for line in open(c):
+        m = chapter_re.search(line)
+        if m:
+            chaptype, chapid = m.groups()
+        m = filename_re.search(line)
+        if m:
+            filename = m.group(1)
+        m = title_re.search(line)
+        if m:
+            title = m.group(1)
+        if filename and title and chapid:
+            if chaptype == 'appendix':
+                num = chr(ord('A') + app)
+                app += 1
+            else:
+                num = ch
+                ch += 1
+            ab += 1
+            date = os.popen('hg log -l1 --template "{date|isodate}" ' + c).read().split(None, 1)[0]
+            args = {
+                'ab': "ab"[ab % 2],
+                'date': date,
+                'chapid': chapid,
+                'num': num,
+                'filename': filename,
+                'title': title,
+                }
+            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)
+            break
+
+print('</ul></div>', file=fp)
+
+fp.close()

it/web/index-template.html

+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+  <head>
+    <title>Mercurial: la guida definitiva</title>
+    <link rel="stylesheet" href="styles.css" type="text/css"/>
+    <!--
+    <link rel="alternate" type="application/atom+xml" title="Comments"
+      href="/feeds/comments/"/>
+    -->
+    <link rel="shortcut icon" type="image/png" href="figs/favicon.png"/>
+    <!-- No comment system for italian translation
+    <script type="text/javascript" src="/support/jquery.js"></script>
+      <script type="text/javascript" src="/support/form.js"></script>
+    <script type="text/javascript" src="/support/hsbook.js"></script>
+    -->
+  </head>
+
+  <body>
+    {% block bodycontent %}{% endblock %}
+
+    <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>
+    </div>
+
+    <!-- Also, no need for Google Analytics on the italian translation
+    <script type="text/javascript">
+    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
+    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
+    </script>
+    <script type="text/javascript">
+    try {
+    var pageTracker = _gat._getTracker("UA-1805907-5");
+    pageTracker._trackPageview();
+    } catch(err) {}</script>
+    -->
+  </body>
+</html>