build_graphical_index.py 3.9 KB

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