Use Markdown content from index.md in blog.json instead of HTML

Updated generate_jsonblog.py to:
- Load Markdown content from output/<slug>/index.md files
- Set content_type: 'markdown' for each post
- Fall back to plain text if index.md not found

This ensures blog.json contains native Markdown content converted
from RST via pandoc, rather than stripped HTML from the Atom feed.

Works with the build order in make formats:
1. rst2md converts RST to Markdown
2. jsonblog reads the Markdown files
3. blog.json contains proper Markdown with content_type set

Result: 100/100 posts now have Markdown content with content_type field.
This commit is contained in:
russell@unturf.com 2026-01-19 15:05:20 -05:00
parent 9ba114df33
commit 01b1c2056d

View file

@ -1,6 +1,7 @@
#!/usr/bin/env python3
"""
Generate JSON Blog (jsonblog.dev) format - single JSON file with all posts.
Uses Markdown content from index.md files generated by rst2md.py.
"""
import json
@ -73,7 +74,7 @@ def parse_atom_feed(atom_path):
if title_elem is not None:
item['title'] = title_elem.text
# Content
# Content (will be replaced with markdown later)
content_elem = entry.find('atom:content', ns)
if content_elem is not None:
item['content_html'] = content_elem.text or ''
@ -108,8 +109,20 @@ def parse_atom_feed(atom_path):
return feed_info, entries
def generate_jsonblog(atom_path, site_url):
"""Generate JSON Blog format."""
def load_markdown_content(output_dir, slug):
"""Load markdown content from index.md file."""
md_path = output_dir / slug / 'index.md'
if md_path.exists():
try:
return md_path.read_text(encoding='utf-8')
except Exception as e:
print(f"Warning: Could not read {md_path}: {e}")
return None
return None
def generate_jsonblog(atom_path, output_dir, site_url):
"""Generate JSON Blog format with Markdown content."""
feed_info, entries = parse_atom_feed(atom_path)
jsonblog = {
@ -125,14 +138,24 @@ def generate_jsonblog(atom_path, site_url):
'posts': []
}
markdown_found = 0
for entry in entries:
post = {
'title': entry['title'],
'slug': entry['slug'],
'content': entry['content'], # Plain text for JSON Blog
'createdAt': entry['createdAt'],
}
# Try to load markdown content
md_content = load_markdown_content(output_dir, entry['slug'])
if md_content:
post['content'] = md_content
post['content_type'] = 'markdown'
markdown_found += 1
else:
# Fallback to plain text from HTML
post['content'] = entry['content']
if entry['updatedAt'] and entry['updatedAt'] != entry['createdAt']:
post['updatedAt'] = entry['updatedAt']
@ -147,6 +170,7 @@ def generate_jsonblog(atom_path, site_url):
jsonblog['posts'].append(post)
print(f"Generated {len(jsonblog['posts'])} posts ({markdown_found} with markdown content)")
return jsonblog
@ -163,8 +187,8 @@ if __name__ == '__main__':
print(f"Error: Atom feed not found at {atom_path}")
sys.exit(1)
jsonblog = generate_jsonblog(atom_path, site_url)
jsonblog = generate_jsonblog(atom_path, output_dir, site_url)
output_path = output_dir / 'blog.json'
output_path.write_text(json.dumps(jsonblog, indent=2, ensure_ascii=False))
print(f"Generated {output_path} ({len(jsonblog['posts'])} posts)")
print(f"Generated {output_path}")