[Kimchi-devel] [PATCH 2/2] doc: Generate index.html to join all help pages

Aline Manera alinefm at linux.vnet.ibm.com
Mon Feb 17 19:56:20 UTC 2014


From: Aline Manera <alinefm at br.ibm.com>

This patch generates help/index.html automatically based on all .dita
files during build time.
For each dita file it generates a link on index.html

Signed-off-by: Aline Manera <alinefm at br.ibm.com>
---
 ui/pages/help/Makefile.am  |    3 ++-
 ui/pages/help/gen-index.py |   64 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 1 deletion(-)
 create mode 100755 ui/pages/help/gen-index.py

diff --git a/ui/pages/help/Makefile.am b/ui/pages/help/Makefile.am
index 81d7e90..5146692 100644
--- a/ui/pages/help/Makefile.am
+++ b/ui/pages/help/Makefile.am
@@ -18,7 +18,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 
 DITA_HTML_FILES = $(patsubst %.dita,%.html,$(wildcard *.dita))
-HTML_FILES = $(if $(wildcard *.html), $(wildcard *.html), $(DITA_HTML_FILES))
+HTML_FILES = $(if $(wildcard *.html), $(wildcard *.html), $(DITA_HTML_FILES) index.html)
 DITA_XSL_FILE = dita-help.xsl
 
 helpdir = $(datadir)/kimchi/ui/pages/help
@@ -27,5 +27,6 @@ dist_help_DATA = $(HTML_FILES) $(NULL)
 
 %.html: %.dita $(DITA_XSL_FILE)
 	xsltproc -o $@ $(DITA_XSL_FILE) $<
+	$(shell pwd)/gen-index.py
 
 CLEANFILES = $(HTML_FILES)
diff --git a/ui/pages/help/gen-index.py b/ui/pages/help/gen-index.py
new file mode 100755
index 0000000..4fa7cbe
--- /dev/null
+++ b/ui/pages/help/gen-index.py
@@ -0,0 +1,64 @@
+#!/usr/bin/python
+#
+# Project Kimchi
+#
+# Copyright IBM, Corp. 2014
+#
+# Authors:
+#  Aline Manera <alinefm at linux.vnet.ibm.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+
+import glob
+import libxml2
+
+
+HTML_HEAD = """
+<html>
+<head>
+  <title>Kimchi Help</title>
+</head>
+<body>
+<h1>Kimchi Help</h1>
+"""
+
+HTML_TAIL = """
+</body>
+</html>
+"""
+
+
+def main():
+    pages = {}
+    files = sorted(glob.glob('*.dita'))
+    for f in files:
+        with open(f) as fd:
+            xml = fd.read()
+            doc = libxml2.parseDoc(xml)
+            node = doc.xpathEval('/cshelp/title')[0]
+            name = node.children.content
+            pages[f.replace('.dita', '.html')] = name
+            doc.freeDoc()
+
+    with open('index.html', 'w') as fd:
+        fd.write(HTML_HEAD)
+        for page, name in pages.iteritems():
+            html = '  <a href="/help/%s">%s</a><br />\n'
+            fd.write(html % (page, name))
+        fd.write(HTML_TAIL)
+
+
+if __name__ == '__main__':
+    main()
-- 
1.7.10.4




More information about the Kimchi-devel mailing list