Skip to content

Commit e697737

Browse files
committed
fixed previous and next navigation sidebar links for multi series blog posts
1 parent e68608e commit e697737

11 files changed

Lines changed: 44 additions & 25 deletions

generate_portfolio_modified.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ def markdown_to_html_resume(text):
7777
reverse=True
7878
)
7979

80-
# 3. Now that every post has a slug, add previous/next post information
80+
# 3. Now that every post has a slug, add previous/next post information and series part resolution
81+
slug_to_post = {post['slug']: post for post in blog_posts}
82+
8183
for i, post in enumerate(blog_posts):
8284
post['next_post'] = None
8385
post['previous_post'] = None
@@ -86,6 +88,21 @@ def markdown_to_html_resume(text):
8688
if i > 0:
8789
post['previous_post'] = blog_posts[i - 1]
8890

91+
# Dynamically extract series part number from title, e.g. " (Part 2)" -> "2"
92+
part_match = re.search(r'\(Part (\d+)\)', post['title'])
93+
if part_match:
94+
post['part_num'] = part_match.group(1)
95+
96+
for post in blog_posts:
97+
if post.get('previous_part_slug'):
98+
prev_post = slug_to_post.get(post['previous_part_slug'])
99+
if prev_post and prev_post.get('part_num'):
100+
post['previous_part_num'] = prev_post['part_num']
101+
if post.get('next_part_slug'):
102+
next_post = slug_to_post.get(post['next_part_slug'])
103+
if next_post and next_post.get('part_num'):
104+
post['next_part_num'] = next_post['part_num']
105+
89106
# 4. Finally, process each post to create its HTML file
90107
for post in blog_posts:
91108
if "markdown_file" in post and post["markdown_file"]:

post_template.html

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,12 @@ <h1>{{ name }}'s Blog</h1>
9191
<section class="series-navigation-sidebar">
9292
<h4>This post is part of a series.</h4>
9393
{% if post.previous_part_slug %}
94-
<a href="posts/{{ post.previous_part_slug }}.html" class="series-link">← Read Part 1</a>
94+
<a href="posts/{{ post.previous_part_slug }}.html" class="series-link">← Read Part {{
95+
post.previous_part_num }}</a>
9596
{% endif %}
9697
{% if post.next_part_slug %}
97-
<a href="posts/{{ post.next_part_slug }}.html" class="series-link">Read Part 2 →</a>
98+
<a href="posts/{{ post.next_part_slug }}.html" class="series-link">Read Part {{ post.next_part_num
99+
}} →</a>
98100
{% endif %}
99101
</section>
100102
{% endif %}
@@ -137,12 +139,12 @@ <h2 class="section-heading">Technologies & Keywords</h2>
137139
<nav class="post-navigation">
138140
<!-- OLDER POST LINK LOGIC -->
139141
{% if post.previous_part_slug %}
140-
<!-- If this is Part 2, the "Older" link MUST be Part 1 -->
142+
<!-- Link back to the previous part dynamically -->
141143
<a href="posts/{{ post.previous_part_slug }}.html" class="nav-link prev-link">
142144
<span class="arrow"></span>
143145
<span class="nav-text">
144-
<span class="nav-label">Read Part 1</span>
145-
{{ post.title | replace(" (Part 2)", "") }}
146+
<span class="nav-label">Read Part {{ post.previous_part_num }}</span>
147+
{{ post.title.split(' (Part ')[0] }}
146148
</span>
147149
</a>
148150
{% elif post.next_post %}
@@ -161,11 +163,11 @@ <h2 class="section-heading">Technologies & Keywords</h2>
161163

162164
<!-- NEWER POST LINK LOGIC -->
163165
{% if post.next_part_slug %}
164-
<!-- If this is Part 1, the "Newer" link MUST be Part 2 -->
166+
<!-- Link forward to the next part dynamically -->
165167
<a href="posts/{{ post.next_part_slug }}.html" class="nav-link next-link">
166168
<span class="nav-text">
167-
<span class="nav-label">Read Part 2</span>
168-
{{ post.title | replace(" (Part 1)", "") }}
169+
<span class="nav-label">Read Part {{ post.next_part_num }}</span>
170+
{{ post.title.split(' (Part ')[0] }}
169171
</span>
170172
<span class="arrow"></span>
171173
</a>

posts/building-an-intelligent-video-analyst-crafting-the-agents-brain-part-2.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ <h2 class="section-heading">Technologies & Keywords</h2>
336336
<nav class="post-navigation">
337337
<!-- OLDER POST LINK LOGIC -->
338338

339-
<!-- If this is Part 2, the "Older" link MUST be Part 1 -->
339+
<!-- Link back to the previous part dynamically -->
340340
<a href="posts/building-an-intelligent-video-analyst-the-foundational-pipeline-part-1.html" class="nav-link prev-link">
341341
<span class="arrow"></span>
342342
<span class="nav-text">

posts/building-an-intelligent-video-analyst-the-foundational-pipeline-part-1.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ <h2 class="section-heading">Technologies & Keywords</h2>
367367

368368
<!-- NEWER POST LINK LOGIC -->
369369

370-
<!-- If this is Part 1, the "Newer" link MUST be Part 2 -->
370+
<!-- Link forward to the next part dynamically -->
371371
<a href="posts/building-an-intelligent-video-analyst-crafting-the-agents-brain-part-2.html" class="nav-link next-link">
372372
<span class="nav-text">
373373
<span class="nav-label">Read Part 2</span>

posts/from-messy-data-to-production-mlops-my-network-security-journey-part-1.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ <h2 class="section-heading">Technologies & Keywords</h2>
357357

358358
<!-- NEWER POST LINK LOGIC -->
359359

360-
<!-- If this is Part 1, the "Newer" link MUST be Part 2 -->
360+
<!-- Link forward to the next part dynamically -->
361361
<a href="posts/from-messy-data-to-production-mlops-my-network-security-journey-part-2.html" class="nav-link next-link">
362362
<span class="nav-text">
363363
<span class="nav-label">Read Part 2</span>

posts/from-messy-data-to-production-mlops-my-network-security-journey-part-2.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ <h2 class="section-heading">Technologies & Keywords</h2>
335335
<nav class="post-navigation">
336336
<!-- OLDER POST LINK LOGIC -->
337337

338-
<!-- If this is Part 2, the "Older" link MUST be Part 1 -->
338+
<!-- Link back to the previous part dynamically -->
339339
<a href="posts/from-messy-data-to-production-mlops-my-network-security-journey-part-1.html" class="nav-link prev-link">
340340
<span class="arrow"></span>
341341
<span class="nav-text">

posts/from-notebook-to-ui-the-local-development-journey-part-1.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ <h2 class="section-heading">Technologies & Keywords</h2>
319319

320320
<!-- NEWER POST LINK LOGIC -->
321321

322-
<!-- If this is Part 1, the "Newer" link MUST be Part 2 -->
322+
<!-- Link forward to the next part dynamically -->
323323
<a href="posts/from-notebook-to-ui-the-web-deployment-journey-part-2.html" class="nav-link next-link">
324324
<span class="nav-text">
325325
<span class="nav-label">Read Part 2</span>

posts/from-notebook-to-ui-the-web-deployment-journey-part-2.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ <h2 class="section-heading">Technologies & Keywords</h2>
267267
<nav class="post-navigation">
268268
<!-- OLDER POST LINK LOGIC -->
269269

270-
<!-- If this is Part 2, the "Older" link MUST be Part 1 -->
270+
<!-- Link back to the previous part dynamically -->
271271
<a href="posts/from-notebook-to-ui-the-local-development-journey-part-1.html" class="nav-link prev-link">
272272
<span class="arrow"></span>
273273
<span class="nav-text">

posts/text-summarizer-journey-serving-the-model-part-3.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ <h2>Key Takeaways: Lessons from This Project</h2>
215215
<section class="series-navigation-sidebar">
216216
<h4>This post is part of a series.</h4>
217217

218-
<a href="posts/text-summarizer-journey-the-ml-engine-room-part-2.html" class="series-link">← Read Part 1</a>
218+
<a href="posts/text-summarizer-journey-the-ml-engine-room-part-2.html" class="series-link">← Read Part 2</a>
219219

220220

221221
</section>
@@ -345,12 +345,12 @@ <h2 class="section-heading">Technologies & Keywords</h2>
345345
<nav class="post-navigation">
346346
<!-- OLDER POST LINK LOGIC -->
347347

348-
<!-- If this is Part 2, the "Older" link MUST be Part 1 -->
348+
<!-- Link back to the previous part dynamically -->
349349
<a href="posts/text-summarizer-journey-the-ml-engine-room-part-2.html" class="nav-link prev-link">
350350
<span class="arrow"></span>
351351
<span class="nav-text">
352-
<span class="nav-label">Read Part 1</span>
353-
Text Summarizer Journey: Serving the Model (Part 3)
352+
<span class="nav-label">Read Part 2</span>
353+
Text Summarizer Journey: Serving the Model
354354
</span>
355355
</a>
356356

posts/text-summarizer-journey-the-ml-engine-room-part-2.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ <h4>This post is part of a series.</h4>
205205
<a href="posts/text-summarizer-journey-the-mlops-blueprint-part-1.html" class="series-link">← Read Part 1</a>
206206

207207

208-
<a href="posts/text-summarizer-journey-serving-the-model-part-3.html" class="series-link">Read Part 2</a>
208+
<a href="posts/text-summarizer-journey-serving-the-model-part-3.html" class="series-link">Read Part 3</a>
209209

210210
</section>
211211

@@ -342,7 +342,7 @@ <h2 class="section-heading">Technologies & Keywords</h2>
342342
<nav class="post-navigation">
343343
<!-- OLDER POST LINK LOGIC -->
344344

345-
<!-- If this is Part 2, the "Older" link MUST be Part 1 -->
345+
<!-- Link back to the previous part dynamically -->
346346
<a href="posts/text-summarizer-journey-the-mlops-blueprint-part-1.html" class="nav-link prev-link">
347347
<span class="arrow"></span>
348348
<span class="nav-text">
@@ -354,11 +354,11 @@ <h2 class="section-heading">Technologies & Keywords</h2>
354354

355355
<!-- NEWER POST LINK LOGIC -->
356356

357-
<!-- If this is Part 1, the "Newer" link MUST be Part 2 -->
357+
<!-- Link forward to the next part dynamically -->
358358
<a href="posts/text-summarizer-journey-serving-the-model-part-3.html" class="nav-link next-link">
359359
<span class="nav-text">
360-
<span class="nav-label">Read Part 2</span>
361-
Text Summarizer Journey: The ML Engine Room (Part 2)
360+
<span class="nav-label">Read Part 3</span>
361+
Text Summarizer Journey: The ML Engine Room
362362
</span>
363363
<span class="arrow"></span>
364364
</a>

0 commit comments

Comments
 (0)