Skip to content

Commit 27427a1

Browse files
brunoborgesCopilot
andcommitted
Make snippet count dynamic via build-time {{snippetCount}} placeholder
index.html now uses {{snippetCount}} placeholders in 4 places (ld+json, hero badge, section badge, stats bar). generate.py replaces them with the actual count during build. No more manual updates when adding or removing slugs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 0348e46 commit 27427a1

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

generate.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,16 @@ def main():
235235

236236
print(f"Rebuilt data/snippets.json with {len(snippets_list)} entries")
237237

238+
# Patch index.html with the current snippet count
239+
count = len(all_snippets)
240+
with open("index.html") as f:
241+
index_content = f.read()
242+
index_content = index_content.replace("{{snippetCount}}", str(count))
243+
with open("index.html", "w") as f:
244+
f.write(index_content)
245+
246+
print(f"Patched index.html with snippet count: {count}")
247+
238248

239249
if __name__ == "__main__":
240250
main()

index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"description": "A collection of modern Java code snippets. Every old Java pattern next to its clean, modern replacement — side by side.",
6060
"mainEntity": {
6161
"@type": "ItemList",
62-
"numberOfItems": 85,
62+
"numberOfItems": {{snippetCount}},
6363
"itemListElement": [
6464
{"@type": "ListItem", "position": 1, "url": "https:\/\/javaevolved.github.io\/type-inference-with-var", "name": "Type inference with var"}
6565
,{"@type": "ListItem", "position": 2, "url": "https:\/\/javaevolved.github.io\/text-blocks-for-multiline-strings", "name": "Text blocks for multiline strings"}
@@ -168,7 +168,7 @@
168168
</nav>
169169

170170
<section class="hero">
171-
<div class="hero-badge">85 modern patterns · Java 8 → Java 25</div>
171+
<div class="hero-badge">{{snippetCount}} modern patterns · Java 8 → Java 25</div>
172172
<h1>Java has evolved.<br><span class="gradient">Your code can too.</span></h1>
173173
<p>Every old Java pattern next to its clean, modern replacement — side by side.</p>
174174
<a href="/language/records-for-data-classes.html" class="hero-compare">
@@ -214,7 +214,7 @@ <h1>Java has evolved.<br><span class="gradient">Your code can too.</span></h1>
214214
<section class="section" id="all-comparisons" style="padding-top:24px">
215215
<div class="section-header">
216216
<h2 class="section-title">All comparisons</h2>
217-
<span class="section-badge">85 snippets</span>
217+
<span class="section-badge">{{snippetCount}} snippets</span>
218218
</div>
219219
<div class="filter-pills" id="categoryFilter">
220220
<span class="filter-label">Filter:</span>
@@ -2961,7 +2961,7 @@ <h3>Default interface methods</h3>
29612961

29622962
<div class="stats-bar">
29632963
<div class="stat-card">
2964-
<div class="number orange">85</div>
2964+
<div class="number orange">{{snippetCount}}</div>
29652965
<div class="label">Modern Patterns</div>
29662966
</div>
29672967
<div class="stat-card">

0 commit comments

Comments
 (0)