commit: 7183f91296cf25741bb31b77f88eb57698782878
Author: Michael Orlitzky <mjo <AT> gentoo <DOT> org>
AuthorDate: Sat Dec 7 00:56:19 2019 +0000
Commit: Göktürk Yüksek <gokturk <AT> gentoo <DOT> org>
CommitDate: Thu Dec 19 20:53:18 2019 +0000
URL: https://gitweb.gentoo.org/proj/devmanual.git/commit/?id=7183f912
Make text.xml files a dependency for documents.js, update search_index.py
Updates to any text.xml should trigger a rebuild of documents.js. The
Makefile is updated to reflect that. And the updated search_index.py
that takes a list of files as arguments.
(This commit message is written by the committer, not the author.)
Signed-off-by: Göktürk Yüksek <gokturk <AT> gentoo.org>
Makefile | 7 +++++--
search_index.py | 30 +++++++++++++-----------------
2 files changed, 18 insertions(+), 19 deletions(-)
diff --git a/Makefile b/Makefile
index ac024b6..90990a8 100644
--- a/Makefile
+++ b/Makefile
@@ -19,8 +19,11 @@ prereq:
{ echo "dev-libs/libxml2 is required" >&2;\
exit 1; }
-index:
- @./search_index.py text.xml > documents.js
+# Since search_index.py rebuilds the index from scratch instead of
+# updating it, we pass it the names of ALL prerequisites ($^) and not
+# just the names of the ones that are new ($?).
+documents.js: $(XMLS)
+ ./search_index.py $^ > documents.js
%.png : %.svg
convert $< $@
diff --git a/search_index.py b/search_index.py
index 3226775..9af2753 100755
--- a/search_index.py
+++ b/search_index.py
@@ -2,27 +2,23 @@
# Copyright 2019 Gentoo Authors
# Distributed under the terms of the GNU GPL version 2 or later
import json
-import os
+import os.path
import sys
import xml.etree.ElementTree as ET
-xmlFile = sys.argv[1]
+files = sys.argv[1:]
documents = []
url_root = 'https://devmanual.gentoo.org/'
-print('var documents = ', end = '')
-for path, dirs, files in os.walk('.'):
- if xmlFile in files:
- tree = ET.parse(path + '/' + xmlFile)
- root = tree.getroot()
- for chapter in root.findall('chapter'):
- try:
- documents.append({"name": chapter.find('title').text,
- "text": chapter.find('body').find('p').text,
- "url": url_root + path[+2:] })
- except:
- pass
- if '.git' in dirs:
- dirs.remove('.git') # don't visit git directories
+for f in files:
+ tree = ET.parse(f)
+ root = tree.getroot()
+ for chapter in root.findall('chapter'):
+ try:
+ documents.append({"name": chapter.find('title').text,
+ "text": chapter.find('body').find('p').text,
+ "url": url_root + os.path.dirname(f) + '/'})
+ except AttributeError:
+ pass
-print(json.dumps(documents))
+print('var documents = ' + json.dumps(documents) + ';')