-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_complete.sh
More file actions
391 lines (358 loc) · 13.2 KB
/
Copy pathbuild_complete.sh
File metadata and controls
391 lines (358 loc) · 13.2 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
#!/bin/bash
# Build complete book HTML from individual chapter/appendix HTML files
# Output: FundsXML_Book_Complete.html
# Resolve the directory this script lives in, so the build works from any
# checkout location (local clone, CI runner, etc.).
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
OUT="$DIR/FundsXML_Book_Complete.html"
# Extract body content (between <body> and </body>) from an HTML file,
# stripping per-chapter <script> blocks and the per-page theme-toggle button
# (the complete file has its own single copy at the end).
extract_body() {
# The feedback-widget script is stripped with a same-line substitution
# BEFORE the range-delete: sed's /start/,/end/d matches the end pattern
# only from the next line on, so a one-line <script>…</script> would
# otherwise swallow everything up to the next </script>-bearing line.
sed -n '/<body>/,/<\/body>/p' "$1" \
| sed '1s/.*<body>//' \
| sed '$s/<\/body>.*//' \
| sed -E 's|<script id="feedback-widget">.*</script>||g' \
| sed -E '/<script( [^>]*)?>/,/<\/script>/d' \
| sed -E 's|<button id="theme-btn"[^>]*>.*</button>||g' \
| sed -E 's|<nav class="chapter-nav"[^>]*>.*</nav>||g'
}
cat > "$OUT" << 'HEADER'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>FundsXML — The European Standard for Fund Data Exchange</title>
<link rel="icon" type="image/png" href="FundsXML-Logo.png">
<style>
HEADER
# Canonical CSS lives in polish_styles.py (single source of truth).
python3 "$DIR/polish_styles.py" --print-css complete >> "$OUT"
cat >> "$OUT" << 'HEADER_END'
</style>
</head>
<body>
HEADER_END
cat >> "$OUT" << 'COVER'
<!-- ============================================================ -->
<!-- COVER PAGE -->
<!-- ============================================================ -->
<div class="cover">
<img src="FundsXML-Logo.png" alt="FundsXML" class="cover-logo">
<div class="cover-subtitle">The European Standard for Fund Data Exchange</div>
<p style="font-size: 1.15em; color: #1a1a1a; margin-top: 1em;">A Practical Handbook for Fund Professionals</p>
<p style="font-size: 1em; color: #444; margin-top: 0.5em;">Based on FundsXML Schema Version 4.2.x</p>
<div class="cover-edition">2026</div>
</div>
COVER
# Table of Contents (from the TOC HTML)
echo '<!-- ============================================================ -->' >> "$OUT"
echo '<!-- TABLE OF CONTENTS -->' >> "$OUT"
echo '<!-- ============================================================ -->' >> "$OUT"
echo '<div class="chapter-break">' >> "$OUT"
extract_body "$DIR/FundsXML_Book_TableOfContents.html" >> "$OUT"
echo '</div>' >> "$OUT"
# Management Summary (front matter)
if [ -f "$DIR/ManagementSummary.html" ]; then
echo "" >> "$OUT"
echo '<!-- ============================================================ -->' >> "$OUT"
echo '<!-- MANAGEMENT SUMMARY -->' >> "$OUT"
echo '<!-- ============================================================ -->' >> "$OUT"
echo '<div class="chapter-break">' >> "$OUT"
extract_body "$DIR/ManagementSummary.html" >> "$OUT"
echo '</div>' >> "$OUT"
fi
# Part I — Foundations
for ch in 01 02 03; do
f="$DIR/Chapter${ch}.html"
if [ -f "$f" ]; then
echo "" >> "$OUT"
echo "<!-- ============================================================ -->" >> "$OUT"
echo "<!-- CHAPTER ${ch} -->" >> "$OUT"
echo "<!-- ============================================================ -->" >> "$OUT"
echo '<div class="chapter-break">' >> "$OUT"
extract_body "$f" >> "$OUT"
echo '</div>' >> "$OUT"
fi
done
# Part II — FundsXML in Detail
for ch in 04 05 06 07 08 09; do
f="$DIR/Chapter${ch}.html"
if [ -f "$f" ]; then
echo "" >> "$OUT"
echo "<!-- CHAPTER ${ch} -->" >> "$OUT"
echo '<div class="chapter-break">' >> "$OUT"
extract_body "$f" >> "$OUT"
echo '</div>' >> "$OUT"
fi
done
# Part III — Implementation and Practice
for ch in 10 11 12 13; do
f="$DIR/Chapter${ch}.html"
if [ -f "$f" ]; then
echo "" >> "$OUT"
echo "<!-- CHAPTER ${ch} -->" >> "$OUT"
echo '<div class="chapter-break">' >> "$OUT"
extract_body "$f" >> "$OUT"
echo '</div>' >> "$OUT"
fi
done
# Part IV — Outlook and Reference
for ch in 14; do
f="$DIR/Chapter${ch}.html"
if [ -f "$f" ]; then
echo "" >> "$OUT"
echo "<!-- CHAPTER ${ch} -->" >> "$OUT"
echo '<div class="chapter-break">' >> "$OUT"
extract_body "$f" >> "$OUT"
echo '</div>' >> "$OUT"
fi
done
# Appendices
for app in A B C D E; do
f="$DIR/Appendix${app}.html"
if [ -f "$f" ]; then
echo "" >> "$OUT"
echo "<!-- APPENDIX ${app} -->" >> "$OUT"
echo '<div class="chapter-break">' >> "$OUT"
extract_body "$f" >> "$OUT"
echo '</div>' >> "$OUT"
fi
done
# Index
f="$DIR/Index.html"
if [ -f "$f" ]; then
echo "" >> "$OUT"
echo "<!-- INDEX -->" >> "$OUT"
echo '<div class="chapter-break">' >> "$OUT"
extract_body "$f" >> "$OUT"
echo '</div>' >> "$OUT"
fi
# Unified navigation script for the complete book
cat >> "$OUT" << 'SCRIPT'
<script>
(function() {
var headings = document.querySelectorAll('h1, h2');
if (headings.length === 0) return;
var nav = document.createElement('nav');
nav.id = 'toc-nav';
var title = document.createElement('div');
title.className = 'toc-title';
title.textContent = 'Contents';
nav.appendChild(title);
var ul = document.createElement('ul');
var counter = 0;
headings.forEach(function(h) {
// Skip the cover h1
if (h.closest('.cover')) return;
var id = 'nav-' + counter++;
h.id = id;
var li = document.createElement('li');
if (h.tagName === 'H1') li.className = 'toc-h1';
var a = document.createElement('a');
a.href = '#' + id;
// Use only the first text node to keep it short
var text = h.childNodes[0] ? h.childNodes[0].textContent.trim() : h.textContent.trim();
// Truncate long titles
if (text.length > 50) text = text.substring(0, 47) + '...';
a.textContent = text;
li.appendChild(a);
ul.appendChild(li);
});
nav.appendChild(ul);
document.body.insertBefore(nav, document.body.firstChild);
var btn = document.createElement('button');
btn.id = 'toc-toggle';
btn.className = 'open';
btn.textContent = '\u2630';
btn.title = 'Toggle navigation';
btn.addEventListener('click', function() {
nav.classList.toggle('collapsed');
btn.classList.toggle('open');
});
document.body.insertBefore(btn, document.body.firstChild);
// Scroll tracking
var links = nav.querySelectorAll('a');
var navHeadings = [];
links.forEach(function(a) {
var target = document.getElementById(a.getAttribute('href').substring(1));
if (target) navHeadings.push(target);
});
function updateActive() {
var scrollPos = window.scrollY + 100;
var current = -1;
for (var i = 0; i < navHeadings.length; i++) {
if (navHeadings[i].offsetTop <= scrollPos) current = i;
}
links.forEach(function(a, i) {
a.classList.toggle('active', i === current);
});
// Scroll the active item into view in the nav
if (current >= 0 && links[current]) {
links[current].scrollIntoView({ block: 'nearest', behavior: 'smooth' });
}
}
window.addEventListener('scroll', updateActive, {passive: true});
updateActive();
})();
</script>
SCRIPT
# Heading-anchor injector + back-to-top button
cat >> "$OUT" << 'EXTRAS'
<script>
document.addEventListener("DOMContentLoaded", function() {
document.querySelectorAll("h1, h2, h3, h4").forEach(function(el) {
var subtitle = el.querySelector(".subtitle");
var text = (subtitle && el.firstChild && el.firstChild.nodeType === 3)
? el.firstChild.textContent.trim()
: el.textContent.trim();
var match = text.match(/^(\d+\.\d+(?:\.\d+)?)/);
var id;
if (match) {
id = "s" + match[1];
} else {
id = text.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").substring(0, 60);
}
if (!el.id) el.id = id;
var a = document.createElement("a");
a.className = "heading-anchor";
a.href = "#" + el.id;
a.textContent = "#";
a.title = "Link to this section";
if (subtitle) {
el.insertBefore(a, subtitle);
} else {
el.appendChild(a);
}
});
});
</script>
<button id="top-btn" onclick="window.scrollTo({top:0,behavior:'smooth'})">↑ Top</button>
<script>
(function(){
var btn=document.getElementById('top-btn');
window.addEventListener('scroll',function(){
btn.classList.toggle('visible', window.scrollY>400);
});
})();
</script>
EXTRAS
# Close HTML
echo '' >> "$OUT"
echo '</body>' >> "$OUT"
echo '</html>' >> "$OUT"
# Inject the theme-toggle (preload in <head>, button + script before </body>)
# and a single copy of the reader-feedback widget.
# Reuses the idempotent helpers from polish_styles.py.
python3 - <<PYEOF
import sys
sys.path.insert(0, "$DIR")
from polish_styles import inject_theme, inject_feedback
p = "$OUT"
html = open(p, encoding="utf-8").read()
open(p, "w", encoding="utf-8").write(inject_feedback(inject_theme(html)))
PYEOF
echo "Done. Output: $OUT"
wc -l "$OUT"
du -h "$OUT"
# ---------------------------------------------------------------------------
# Generate the GitHub Pages landing page (index.html).
# Reuses the Table-of-Contents CSS so the look matches the book, links every
# chapter/appendix for individual reading, plus the complete HTML and PDF.
# ---------------------------------------------------------------------------
IDX="$DIR/index.html"
# Emit a linked card for a file: <stem> <fallback-label> <page-range>
card() {
local file="$1" fallback="$2" pages="$3"
[ -f "$DIR/$file" ] || return 0
local title
title="$(grep -oE '<title>[^<]*</title>' "$DIR/$file" | head -1 | sed -E 's|</?title>||g')"
[ -n "$title" ] || title="$fallback"
local badge=""
[ -n "$pages" ] && badge=" <span class=\"pages\">pages ${pages}</span>"
echo " <a class=\"chapter\" href=\"${file}\">${title}${badge}</a>" >> "$IDX"
}
part() { echo " <h2 class=\"part-title\">$1</h2>" >> "$IDX"; }
cat > "$IDX" << 'IDX_HEAD'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>FundsXML — The European Standard for Fund Data Exchange</title>
<link rel="icon" type="image/png" href="FundsXML-Logo.png">
<style>
IDX_HEAD
python3 "$DIR/polish_styles.py" --print-css toc >> "$IDX"
cat >> "$IDX" << 'IDX_MID'
</style>
</head>
<body>
<div class="container">
<header class="book-header">
<img src="FundsXML-Logo.png" alt="FundsXML" style="max-width:240px;height:auto;margin-bottom:1em;">
<div class="subtitle">A Practical Handbook for Fund Professionals</div>
<h1>FundsXML – The European Standard for Fund Data Exchange</h1>
<div class="meta">Based on FundsXML Schema Version 4.2.x · 2026</div>
<div class="summary-box" style="text-align:center;">
<a class="download-link" href="FundsXML_Book_Complete.html">Read the complete book online →</a>
<a class="download-link" href="FundsXML_Book.pdf">Download PDF</a>
<a class="download-link issue-link" href="https://github.com/fundsxml/book/issues/new/choose">Report an issue</a>
</div>
</header>
IDX_MID
part "Front Matter"
card "ManagementSummary.html" "Management Summary" "5–6"
part "Part I — Foundations"
card "Chapter01.html" "Chapter 1" "7–31"
card "Chapter02.html" "Chapter 2" "32–61"
card "Chapter03.html" "Chapter 3" "62–81"
part "Part II — FundsXML in Detail"
card "Chapter04.html" "Chapter 4" "82–103"
card "Chapter05.html" "Chapter 5" "104–143"
card "Chapter06.html" "Chapter 6" "144–188"
card "Chapter07.html" "Chapter 7" "189–218"
card "Chapter08.html" "Chapter 8" "219–268"
card "Chapter09.html" "Chapter 9" "269–293"
part "Part III — Implementation and Practice"
card "Chapter10.html" "Chapter 10" "294–318"
card "Chapter11.html" "Chapter 11" "319–346"
card "Chapter12.html" "Chapter 12" "347–378"
card "Chapter13.html" "Chapter 13" "379–408"
part "Part IV — Outlook and Reference"
card "Chapter14.html" "Chapter 14" "409–426"
part "Appendices"
card "AppendixA.html" "Appendix A" "427–438"
card "AppendixB.html" "Appendix B" "439–446"
card "AppendixC.html" "Appendix C" "447–461"
card "AppendixD.html" "Appendix D" "462–481"
card "AppendixE.html" "Appendix E" "482–485"
card "Index.html" "Index" "506–515"
cat >> "$IDX" << 'IDX_FOOT'
</div>
</body>
</html>
IDX_FOOT
# Single theme toggle + feedback widget for the landing page too.
python3 - <<PYEOF
import sys
sys.path.insert(0, "$DIR")
from polish_styles import inject_theme, inject_feedback
p = "$IDX"
html = open(p, encoding="utf-8").read()
open(p, "w", encoding="utf-8").write(inject_feedback(inject_theme(html)))
PYEOF
echo "Generated landing page: $IDX"
# Build the PDF if node + playwright + build_pdf.js are available.
if command -v node >/dev/null 2>&1 && [ -f "$DIR/build_pdf.js" ]; then
echo "Generating PDF..."
( cd "$DIR" && node build_pdf.js )
else
echo "Skipping PDF build (node or build_pdf.js missing)."
fi