|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 |
|
3 | 3 | import os |
| 4 | +import html |
| 5 | + |
| 6 | +modules_map = { |
| 7 | + "base": "guts goptions glogging gbase textProgressBar utilities", |
| 8 | + "plugins": "gfactory gdynamicDigitization gsd", |
| 9 | + "hits": "gtouchable ghit", |
| 10 | + "gui": "gboard gqtbuttonswidget g4display g4dialog gsplash gtree dbselect gui", |
| 11 | + "detector": "gsystem g4system gdetector gtranslationTable", |
| 12 | + "i/o": "gdata gstreamer eventDispenser", |
| 13 | + "geant4": "gparticle gphysics gfields actions", |
| 14 | +} |
4 | 15 |
|
5 | 16 | # Path to the directory containing subdirectories with Doxygen documentation |
6 | 17 | pages_directory = "pages" |
|
16 | 27 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
17 | 28 | <title>Doxygen Documentation Links</title> |
18 | 29 | <style> |
| 30 | + :root { |
| 31 | + --fg: #24292f; |
| 32 | + --muted: #57606a; |
| 33 | + --border: #d0d7de; |
| 34 | + --link: #0969da; |
| 35 | + --bg: #ffffff; |
| 36 | + } |
| 37 | +
|
19 | 38 | body { |
20 | | - font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; |
21 | 39 | margin: 0; |
22 | | - padding: 0; |
23 | | - background-color: #f4f4f9; |
24 | | - color: #333; |
25 | | - display: flex; |
26 | | - justify-content: center; |
27 | | - align-items: center; |
28 | | - min-height: 100vh; |
| 40 | + background: var(--bg); |
| 41 | + color: var(--fg); |
| 42 | + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"; |
29 | 43 | } |
30 | 44 |
|
| 45 | + /* GitHub-ish readable content width */ |
31 | 46 | .container { |
32 | | - text-align: center; |
33 | | - padding: 120px; |
34 | | - background-color: #ffffff; |
35 | | - box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); |
36 | | - border-radius: 10px; |
37 | | - width: 90%; |
38 | | - max-width: 600px; |
39 | | - } |
40 | | -
|
41 | | - h1 { |
42 | | - color: #4a90e2; |
43 | | - margin-bottom: 10px; |
| 47 | + max-width: 980px; |
| 48 | + margin: 0 auto; |
| 49 | + padding: 32px 24px 24px 24px; |
44 | 50 | } |
45 | 51 |
|
| 52 | + /* Intro line like a README paragraph */ |
46 | 53 | p { |
47 | | - color: #555; |
48 | | - font-size: 1.1em; |
49 | | - margin-bottom: 20px; |
| 54 | + margin: 0 0 16px 0; |
| 55 | + color: var(--muted); |
| 56 | + font-size: 16px; |
| 57 | + line-height: 1.5; |
50 | 58 | } |
51 | 59 |
|
| 60 | + /* Outer list holds sections (footer expects one outer <ul>) */ |
52 | 61 | .link-list { |
53 | | - display: flex; |
54 | | - flex-wrap: wrap; |
55 | | - justify-content: center; |
| 62 | + list-style: none; |
56 | 63 | padding: 0; |
57 | | - margin: 0; |
| 64 | + margin: 16px 0 0 0; |
| 65 | + } |
| 66 | +
|
| 67 | + /* Each section as a list item */ |
| 68 | + .section { |
| 69 | + margin: 0 0 20px 0; |
| 70 | + } |
| 71 | +
|
| 72 | + /* “Same font as ## but smaller” */ |
| 73 | + .section-title { |
| 74 | + font-weight: 600; |
| 75 | + font-size: 18px; /* smaller than typical H2 */ |
| 76 | + line-height: 1.25; |
| 77 | + margin: 24px 0 10px 0; |
| 78 | + padding-bottom: 6px; |
| 79 | + border-bottom: 1px solid var(--border); |
| 80 | + } |
| 81 | +
|
| 82 | + /* Links under each section */ |
| 83 | + .section-links { |
58 | 84 | list-style: none; |
| 85 | + padding: 0; |
| 86 | + margin: 10px 0 0 0; |
| 87 | +
|
| 88 | + /* compact grid-ish layout without “button” styling */ |
| 89 | + column-count: {{NUM_COLUMNS}}; |
| 90 | + column-gap: 18px; |
59 | 91 | } |
60 | 92 |
|
61 | | - .link-list li { |
62 | | - margin: 10px; |
63 | | - flex: 0 1 calc(100% / {{NUM_COLUMNS}} - 20px); |
64 | | - display: flex; |
65 | | - justify-content: center; |
| 93 | + .section-links li { |
| 94 | + break-inside: avoid; |
| 95 | + margin: 6px 0; |
66 | 96 | } |
67 | 97 |
|
68 | | - .link-list a { |
| 98 | + a { |
| 99 | + color: var(--link); |
69 | 100 | text-decoration: none; |
70 | | - color: #ffffff; |
71 | | - background-color: #333392; |
72 | | - padding: 10px 20px; |
73 | | - border-radius: 5px; |
74 | | - transition: background-color 0.1s; |
75 | | - display: inline-block; |
76 | | - width: 100%; |
77 | | - max-width: 300px; |
78 | | - text-align: center; |
79 | 101 | } |
80 | 102 |
|
81 | | - .link-list a:hover { |
82 | | - background-color: #4a70e2; |
| 103 | + a:hover { |
| 104 | + text-decoration: underline; |
83 | 105 | } |
84 | 106 |
|
| 107 | + /* Keep footer styles as originally referenced */ |
85 | 108 | .footer { |
86 | 109 | margin-top: 20px; |
87 | 110 | font-size: 0.9em; |
|
95 | 118 | <ul class="link-list"> |
96 | 119 | """ |
97 | 120 |
|
98 | | -# HTML template for the footer |
| 121 | +# HTML template for the footer (KEEP AS IS) |
99 | 122 | html_footer = """ |
100 | 123 | </ul> |
101 | 124 | <div class="footer"> |
|
110 | 133 | """ |
111 | 134 |
|
112 | 135 |
|
113 | | -def generate_html(directory: str, columns: int) -> str: |
114 | | - """Generate the index.html content listing subdirectories alphabetically.""" |
115 | | - links = "" |
| 136 | +def _existing_doc_dirs(directory: str) -> dict[str, str]: |
| 137 | + """ |
| 138 | + Return {subdir_name: relative_index_file} for subdirectories that contain index.html. |
| 139 | + """ |
| 140 | + out: dict[str, str] = {} |
| 141 | + for name in sorted(os.listdir(directory), key=str.casefold): |
| 142 | + subdir_path = os.path.join(directory, name) |
| 143 | + if not os.path.isdir(subdir_path): |
| 144 | + continue |
| 145 | + index_file = os.path.join(subdir_path, "index.html") |
| 146 | + if not os.path.exists(index_file): |
| 147 | + continue |
| 148 | + out[name] = os.path.relpath(index_file, directory) |
| 149 | + return out |
116 | 150 |
|
| 151 | + |
| 152 | +def generate_html(directory: str, columns: int) -> str: |
| 153 | + """Generate the index.html content listing subdirectories organized by modules_map.""" |
117 | 154 | # Clamp columns to at least 1 (avoids division by zero / bad CSS) |
118 | 155 | columns = max(1, int(columns)) |
119 | 156 |
|
120 | | - # Alphabetical order (case-insensitive) |
121 | | - subdirs = sorted(os.listdir(directory), key=str.casefold) |
| 157 | + existing = _existing_doc_dirs(directory) |
| 158 | + used: set[str] = set() |
122 | 159 |
|
123 | | - for subdir in subdirs: |
124 | | - subdir_path = os.path.join(directory, subdir) |
125 | | - if not os.path.isdir(subdir_path): |
126 | | - continue |
| 160 | + sections_html: list[str] = [] |
127 | 161 |
|
128 | | - index_file = os.path.join(subdir_path, "index.html") |
129 | | - if not os.path.exists(index_file): |
| 162 | + # Build sections in insertion order of modules_map |
| 163 | + for section_name, modules_str in modules_map.items(): |
| 164 | + modules = [m for m in modules_str.split() if m.strip()] |
| 165 | + # Only include modules that actually exist and have index.html |
| 166 | + present = [m for m in modules if m in existing] |
| 167 | + if not present: |
130 | 168 | continue |
131 | 169 |
|
132 | | - # Link relative to the pages directory |
133 | | - relative_index_file = os.path.relpath(index_file, directory) |
134 | | - links += f' <li><a href="{relative_index_file}" target="_blank">{subdir}</a></li>\n' |
| 170 | + used.update(present) |
| 171 | + |
| 172 | + section_title = html.escape(section_name) |
| 173 | + section_block = [ |
| 174 | + ' <li class="section">\n', |
| 175 | + f' <div class="section-title">{section_title}</div>\n', |
| 176 | + ' <ul class="section-links">\n', |
| 177 | + ] |
| 178 | + |
| 179 | + for m in present: |
| 180 | + href = html.escape(existing[m], quote=True) |
| 181 | + label = html.escape(m) |
| 182 | + # Text must visibly include square brackets: [ link ] |
| 183 | + section_block.append(f' <li><a href="{href}" target="_blank">[ {label} ]</a></li>\n') |
| 184 | + |
| 185 | + section_block.append(" </ul>\n") |
| 186 | + section_block.append(" </li>\n") |
| 187 | + section_block.append(" <br/>\n") |
| 188 | + sections_html.append("".join(section_block)) |
| 189 | + |
| 190 | + # Optional: any leftover documented dirs not in modules_map |
| 191 | + leftovers = sorted([k for k in existing.keys() if k not in used], key=str.casefold) |
| 192 | + if leftovers: |
| 193 | + section_block = [ |
| 194 | + ' <li class="section">\n', |
| 195 | + ' <div class="section-title">other</div>\n', |
| 196 | + ' <ul class="section-links">\n', |
| 197 | + ] |
| 198 | + for m in leftovers: |
| 199 | + href = html.escape(existing[m], quote=True) |
| 200 | + label = html.escape(m) |
| 201 | + section_block.append(f' <li><a href="{href}" target="_blank">[ {label} ]</a></li>\n') |
| 202 | + section_block.append(" </ul>\n") |
| 203 | + section_block.append(" </li>\n") |
| 204 | + section_block.append(" <br/>\n") |
| 205 | + sections_html.append("".join(section_block)) |
135 | 206 |
|
136 | 207 | header = html_header.replace("{{NUM_COLUMNS}}", str(columns)) |
137 | | - return header + links + html_footer |
| 208 | + return header + "".join(sections_html) + html_footer |
138 | 209 |
|
139 | 210 |
|
140 | 211 | def write_html_file(directory: str, columns: int) -> None: |
|
0 commit comments