build_graphical_index.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #!/usr/bin/env python3
  2. ############################################################################
  3. #
  4. # MODULE: build_graphical_index
  5. # AUTHOR(S): Vaclav Petras <wenzeslaus gmail com>
  6. # PURPOSE: Build graphical index
  7. # COPYRIGHT: (C) 2015-2022 by Vaclav Petras and the GRASS Development Team
  8. #
  9. # This program is free software under the GNU General Public
  10. # License (>=v2). Read the file COPYING that comes with GRASS
  11. # for details.
  12. #
  13. #############################################################################
  14. import os
  15. import sys
  16. from build_html import write_html_footer, grass_version, header1_tmpl
  17. output_name = "graphical_index.html"
  18. year = os.getenv("VERSION_DATE")
  19. # other similar strings are in a different file
  20. # TODO: all HTML manual building needs refactoring (perhaps grass.tools?)
  21. header_graphical_index_tmpl = """\
  22. <link rel="stylesheet" href="grassdocs.css" type="text/css">
  23. <style>
  24. .img-list {
  25. list-style-type: none;
  26. margin: 0;
  27. padding: 0;
  28. text-align: center;
  29. }
  30. .img-list li {
  31. display: inline-block;
  32. position: relative;
  33. width: 8em;
  34. margin: 0;
  35. padding: 0.5em;
  36. margin-bottom: 1em;
  37. }
  38. .img-list li:hover {
  39. background-color: #eee;
  40. }
  41. .img-list li img {
  42. float: left;
  43. max-width: 100%;
  44. background: white;
  45. }
  46. .img-list li span {
  47. text-align: center;
  48. }
  49. .img-list li a {
  50. color: initial;
  51. text-decoration: none;
  52. }
  53. .img-list li .name {
  54. margin: 0.1em;
  55. display: block;
  56. color: #409940;
  57. font-weight: bold;
  58. font-style: normal;
  59. font-size: 120%;
  60. }
  61. </style>
  62. </head>
  63. <body style="width: 99%">
  64. <div id="container">
  65. <a href="index.html"><img src="grass_logo.png" alt="GRASS logo"></a>
  66. <hr class="header">
  67. <h2>Graphical index of GRASS GIS modules</h2>
  68. """
  69. def std_img_name(name):
  70. return "gi_{0}.jpg".format(name)
  71. index_items = [
  72. ("raster_graphical.html", std_img_name("raster"), "Raster"),
  73. ("vector_graphical.html", std_img_name("vector"), "Vector"),
  74. ("database_graphical.html", std_img_name("database"), "Database"),
  75. ("general_graphical.html", std_img_name("general"), "General"),
  76. ("display_graphical.html", std_img_name("display"), "Display"),
  77. ("imagery_graphical.html", std_img_name("imagery"), "Imagery"),
  78. ("raster3d_graphical.html", std_img_name("raster3d"), "3D raster"),
  79. ("temporal_graphical.html", std_img_name("temporal"), "Temporal"),
  80. ("miscellaneous_graphical.html", std_img_name("miscellaneous"), "Miscellaneous"),
  81. ("postscript_graphical.html", std_img_name("cartography"), "Cartography"),
  82. ("wxGUI_graphical.html", std_img_name("gui"), "GUI"),
  83. ("wxGUI.nviz.html", std_img_name("3dview"), "3D view"),
  84. (
  85. "https://grass.osgeo.org/grass-devel/manuals/libpython/index.html",
  86. std_img_name("python"),
  87. "Python",
  88. ),
  89. ("https://grass.osgeo.org/programming8/", std_img_name("c"), "C library"),
  90. ("manual_gallery.html", std_img_name("gallery"), "Gallery"),
  91. (
  92. "https://grass.osgeo.org/grass8/manuals/addons/",
  93. std_img_name("addons"),
  94. "Addons",
  95. ),
  96. ]
  97. def main():
  98. html_dir = sys.argv[1]
  99. with open(os.path.join(html_dir, output_name), "w") as output:
  100. output.write(
  101. header1_tmpl.substitute(
  102. title="GRASS GIS %s Reference "
  103. "Manual: Graphical index" % grass_version
  104. )
  105. )
  106. output.write(header_graphical_index_tmpl)
  107. output.write('<ul class="img-list">\n')
  108. for html_file, image, label in index_items:
  109. output.write(
  110. "<li>"
  111. '<a href="{html}">'
  112. '<img src="{img}">'
  113. '<span class="name">{name}</span>'
  114. "</a>"
  115. "</li>\n".format(html=html_file, img=image, name=label)
  116. )
  117. output.write("</ul>")
  118. write_html_footer(output, "index.html", year)
  119. if __name__ == "__main__":
  120. main()