Switch blog.json from embedded content to content_url links
Changes blog.json generation to link to hosted markdown files instead of
embedding full content. Each post now includes a content_url field pointing
to {site_url}/{slug}/index.md. This significantly reduces blog.json file
size while maintaining full content access via standard HTTP requests.
Updated README.rst to document the new linking behavior & how blog.json works.
This commit is contained in:
parent
2bda81d294
commit
d8cf83e051
2 changed files with 13 additions and 24 deletions
|
|
@ -1,7 +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.
|
||||
Links to Markdown files (index.md) generated by rst2md.py instead of embedding content.
|
||||
"""
|
||||
|
||||
import json
|
||||
|
|
@ -109,20 +109,8 @@ def parse_atom_feed(atom_path):
|
|||
return feed_info, entries
|
||||
|
||||
|
||||
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."""
|
||||
"""Generate JSON Blog format with links to Markdown content."""
|
||||
feed_info, entries = parse_atom_feed(atom_path)
|
||||
|
||||
jsonblog = {
|
||||
|
|
@ -146,15 +134,12 @@ def generate_jsonblog(atom_path, output_dir, site_url):
|
|||
'createdAt': entry['createdAt'],
|
||||
}
|
||||
|
||||
# Try to load markdown content
|
||||
md_content = load_markdown_content(output_dir, entry['slug'])
|
||||
if md_content:
|
||||
post['content'] = md_content
|
||||
# Check if markdown file exists, then link to it
|
||||
md_path = output_dir / entry['slug'] / 'index.md'
|
||||
if md_path.exists():
|
||||
post['content_url'] = f"{site_url}/{entry['slug']}/index.md"
|
||||
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']
|
||||
|
|
@ -170,7 +155,7 @@ def generate_jsonblog(atom_path, output_dir, site_url):
|
|||
|
||||
jsonblog['posts'].append(post)
|
||||
|
||||
print(f"Generated {len(jsonblog['posts'])} posts ({markdown_found} with markdown content)")
|
||||
print(f"Generated {len(jsonblog['posts'])} posts ({markdown_found} with markdown links)")
|
||||
return jsonblog
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue