mirror of
https://github.com/tanrax/org-social-static-preview
synced 2026-01-07 05:43:35 +01:00
main
Source blocks (#+BEGIN_SRC / #+END_SRC) were not rendering correctly in preview cards. The content was being displayed as raw Org Mode syntax instead of formatted code blocks. This fix: - Detects source blocks using regex pattern matching - Extracts code content and language identifier - HTML-escapes code content to prevent XSS - Replaces blocks with placeholders before other formatting - Restores blocks as styled <pre><code> elements after line break conversion Fixes issue where comments and code in source blocks were invisible in share preview links.
Org Social Static Preview Generator
Tool for generating HTML previews from Org Social files. This tool creates social media-like preview cards for each post in your social.org file.
Installation
No external dependencies required beyond Python 3 standard library and Jinja2:
pip install jinja2
Usage
Docker
Using Docker Compose (recommended):
# Create preview directory first
mkdir -p preview
# Copy `social.org` file to the current directory
cp /path/to/your/social.org .
# Run with Docker Compose
UID=$(id -u) GID=$(id -g) docker compose up
Or build and run manually:
# Create preview directory first
mkdir -p preview
docker build -t org-social-preview .
docker run -v $(pwd)/social.org:/app/social.org:ro -v $(pwd)/preview:/app/preview org-social-preview
Note: Make sure to create the preview directory before running Docker to avoid permission issues.
Arguments
--social-file,-s: Path to your social.org file (default:social.org)--preview-dir,-p: Directory to save HTML previews (default:preview)--template-dir,-td: Directory containing the template file (default:.)--template-name,-tn: Template filename (default:template.html)
Local Python
Basic usage:
python org_social_preview_generator.py
With custom options:
python org_social_preview_generator.py --social-file my-social.org --preview-dir output --template-dir templates --template-name custom.html
File Structure
org-social-preview/
├── org_social_preview_generator.py # Main script
├── template.html # HTML template
├── social.org # Your Org Social file
└── preview/ # Generated HTML files
├── 2025-08-14T09-11-00plus0200.html
├── 2025-08-14T14-29-00plus0200.html
└── ...
Template Customization
The HTML template (template.html) uses Jinja2 templating. You can customize:
- Styling and layout
- Open Graph metadata
- Post display format
- Color scheme and fonts
Available template variables:
nick: User nicknameformatted_content: Processed post contentmood: Post mood emojitags: List of tagsformatted_time: Formatted timestampavatar_url: User avatar URLpost_url: Post permalink
Technical recommendation
If you are going to use a cron job to generate them repeatedly, check the header or metadata for when the last modification was made.
License
This project is open source. See the main Org Social repository for more information.
Description
Languages
Python
68.9%
HTML
26.6%
Dockerfile
2.7%
Shell
1.8%
