diff --git a/pg-py/pa.py b/pg-py/pa.py
index a8960b9..8b5987f 100644
--- a/pg-py/pa.py
+++ b/pg-py/pa.py
@@ -173,24 +173,27 @@ def render_template(template_content, context):
# Handle simple year grouping for archive template
if 'years' in context and '{% for year, posts in years %}' in content:
- start_pattern = '{% for year, posts in years %}'
- end_pattern = '{% endfor %}'
- start_idx = content.find(start_pattern)
- end_idx = content.find(end_pattern) + len(end_pattern)
-
- if start_idx != -1 and end_idx != -1:
- template_block = content[start_idx:end_idx]
- content = content.replace(template_block, '')
+
+ if 'YEAR_GROUPING_PROCESSED' not in content:
+ start_pattern = '{% for year, posts in years %}'
+ end_pattern = '{% endfor %}'
+ content = content.replace(start_pattern, '').replace(end_pattern, '')
+ content = content.replace('{{ year }}', '')
years_content = ''
for year, posts in context['years'].items():
years_content += f'<h2>{year}</h2>\n'
for post in posts:
date_str = apply_filter(post.get('date', ''), 'format', '%d %b %Y')
- years_content += f'<li>{date_str} - <a href="{post.get("url", "")}">{post.get("title", "")}</a></li>\n'
+ years_content += f'<li class="archive-item">\n<span class="archive-title"><a href="{post.get("url", "")}">{post.get("title", "")}</a></span>\n<span class="archive-date">{date_str}</span>\n</li>\n'
+
+ ul_start = content.find('<ul class="archive-list">') + len('<ul class="archive-list">')
+ ul_end = content.find('</ul>')
+ if ul_start != -1 and ul_end != -1:
+ content = content[:ul_start] + years_content + content[ul_end:]
- content = content.replace('</ul>', f'{years_content}</ul>')
-
+ content += '<!-- YEAR_GROUPING_PROCESSED -->' # Hacky AF!
+
content = process_filters(content, context)
return content