1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
#!/usr/bin/env python3
# generates topics.html and topic_*.html
# (c) 2012-2025 by the GRASS Development Team, Markus Neteler, Luca Delucchi
import os
import sys
import glob
from build_html import *
path = sys.argv[1]
year = os.getenv("VERSION_DATE")
min_num_modules_for_topic = 3
keywords = {}
htmlfiles = glob.glob1(path, "*.html")
for fname in htmlfiles:
fil = open(os.path.join(path, fname))
# TODO maybe move to Python re (regex)
lines = fil.readlines()
try:
index_keys = lines.index("<h2>KEYWORDS</h2>\n") + 1
index_desc = lines.index("<h2>NAME</h2>\n") + 1
except:
continue
try:
key = lines[index_keys].split(",")[1].strip().replace(" ", "_")
key = key.split(">")[1].split("<")[0]
except:
continue
try:
desc = lines[index_desc].split("-", 1)[1].strip()
except:
desc.strip()
if key not in keywords.keys():
keywords[key] = {}
keywords[key][fname] = desc
elif fname not in keywords[key]:
keywords[key][fname] = desc
topicsfile = open(os.path.join(path, "topics.html"), "w")
topicsfile.write(
header1_tmpl.substitute(
title="GRASS GIS " "%s Reference Manual: Topics index" % grass_version
)
)
topicsfile.write(headertopics_tmpl)
for key, values in sorted(keywords.items(), key=lambda s: s[0].lower()):
keyfile = open(os.path.join(path, "topic_%s.html" % key), "w")
keyfile.write(
header1_tmpl.substitute(
title="GRASS GIS "
"%s Reference Manual: Topic %s" % (grass_version, key.replace("_", " "))
)
)
keyfile.write(headerkey_tmpl.substitute(keyword=key.replace("_", " ")))
num_modules = 0
for mod, desc in sorted(values.items()):
num_modules += 1
keyfile.write(
desc1_tmpl.substitute(cmd=mod, desc=desc, basename=mod.replace(".html", ""))
)
if num_modules >= min_num_modules_for_topic:
topicsfile.writelines(
[moduletopics_tmpl.substitute(key=key, name=key.replace("_", " "))]
)
keyfile.write("</table>\n")
# link to the keywords index
# TODO: the labels in keywords index are with spaces and capitals
# this should be probably changed to lowercase with underscores
keyfile.write(
"<p><em>See also the corresponding keyword"
' <a href="keywords.html#{key}">{key}</a>'
" for additional references.</em>".format(key=key.replace("_", " "))
)
write_html_footer(keyfile, "index.html", year)
topicsfile.write("</ul>\n")
write_html_footer(topicsfile, "index.html", year)
topicsfile.close()
|