build_graphical_index.py 3.9 KB

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