🎨 make the markdown file configuration explicit
This commit is contained in:
22
README.md
22
README.md
@@ -220,6 +220,7 @@ Comics are stored in the `COMICS` list in `comics_data.py`. Each comic entry:
|
||||
'alt_text': 'Alt text for comic', # Accessibility text (required)
|
||||
'title': 'Comic Title', # Title (optional, shows #X if absent)
|
||||
'author_note': 'Optional note', # Author note (optional, plain text)
|
||||
'author_note_md': '2025-01-01.md', # Optional markdown file for author note
|
||||
'full_width': True, # Optional: override FULL_WIDTH_DEFAULT
|
||||
'plain': True # Optional: override PLAIN_DEFAULT
|
||||
}
|
||||
@@ -235,7 +236,7 @@ python scripts/add_comic.py
|
||||
# Add comic entry AND create markdown file for author notes
|
||||
python scripts/add_comic.py -m
|
||||
```
|
||||
This will automatically add a new entry with defaults. The `-m` flag creates a markdown file in `content/author_notes/{date}.md` with a template. Then edit `comics_data.py` to customize.
|
||||
This will automatically add a new entry with defaults. The `-m` flag creates a markdown file in `content/author_notes/{date}.md` with a template and adds the `author_note_md` field to the comic entry. Then edit `comics_data.py` to customize.
|
||||
|
||||
**Option 2: Manual**
|
||||
1. Save your comic image in `static/images/comics/` (e.g., `comic-001.png`)
|
||||
@@ -253,11 +254,26 @@ This creates/updates `static/feed.rss`
|
||||
### Markdown Support
|
||||
|
||||
**Author Notes:**
|
||||
Create markdown files in `content/author_notes/{date}.md` (e.g., `2025-01-01.md`) for rich-formatted author notes. Markdown author notes take precedence over the `author_note` field in `comics_data.py` and render as HTML.
|
||||
Add the `author_note_md` field to your comic entry in `comics_data.py` to use markdown-formatted author notes. The field can be:
|
||||
- Just a filename (e.g., `"2025-01-01.md"`) - looked up in `content/author_notes/`
|
||||
- A path relative to `content/` (e.g., `"special/intro.md"`)
|
||||
|
||||
Markdown author notes take precedence over the plain text `author_note` field and render as HTML.
|
||||
|
||||
Example:
|
||||
```python
|
||||
# In comics_data.py
|
||||
{
|
||||
'number': 1,
|
||||
'filename': 'comic-001.png',
|
||||
'date': '2025-01-01',
|
||||
'alt_text': 'First comic',
|
||||
'author_note_md': '2025-01-01.md' # References content/author_notes/2025-01-01.md
|
||||
}
|
||||
```
|
||||
|
||||
```bash
|
||||
# Create author note for a specific comic
|
||||
# Create the markdown file
|
||||
echo "# My First Comic\n\nThis is **bold** text!" > content/author_notes/2025-01-01.md
|
||||
```
|
||||
|
||||
|
||||
33
app.py
33
app.py
@@ -72,9 +72,20 @@ def format_comic_date(date_str):
|
||||
return date_str
|
||||
|
||||
|
||||
def get_author_note(date_str):
|
||||
"""Load author note from markdown file if it exists, using date as filename"""
|
||||
note_path = os.path.join(os.path.dirname(__file__), 'content', 'author_notes', f'{date_str}.md')
|
||||
def get_author_note_from_file(filename):
|
||||
"""Load author note from markdown file if it exists
|
||||
|
||||
Args:
|
||||
filename: Either just a filename (looked up in content/author_notes/)
|
||||
or a path relative to content/
|
||||
"""
|
||||
# If filename contains a path separator, treat as relative to content/
|
||||
if '/' in filename or '\\' in filename:
|
||||
note_path = os.path.join(os.path.dirname(__file__), 'content', filename)
|
||||
else:
|
||||
# Just a filename, look in author_notes directory
|
||||
note_path = os.path.join(os.path.dirname(__file__), 'content', 'author_notes', filename)
|
||||
|
||||
try:
|
||||
with open(note_path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
@@ -92,13 +103,17 @@ def enrich_comic(comic):
|
||||
enriched['plain'] = is_plain(comic)
|
||||
enriched['formatted_date'] = format_comic_date(comic['date'])
|
||||
|
||||
# Check for markdown author note, fall back to data field if not found
|
||||
markdown_note = get_author_note(comic['date'])
|
||||
if markdown_note:
|
||||
enriched['author_note'] = markdown_note
|
||||
enriched['author_note_is_html'] = True
|
||||
# Check for explicitly specified markdown author note file
|
||||
if 'author_note_md' in comic and comic['author_note_md']:
|
||||
markdown_note = get_author_note_from_file(comic['author_note_md'])
|
||||
if markdown_note:
|
||||
enriched['author_note'] = markdown_note
|
||||
enriched['author_note_is_html'] = True
|
||||
else:
|
||||
# File specified but not found, use plain text from comic data if it exists
|
||||
enriched['author_note_is_html'] = False
|
||||
else:
|
||||
# No markdown file, use plain text from comic data if it exists
|
||||
# No markdown file specified, use plain text from comic data if it exists
|
||||
enriched['author_note_is_html'] = False
|
||||
|
||||
return enriched
|
||||
|
||||
@@ -82,6 +82,7 @@ COMICS = [
|
||||
'date': '2025-01-01',
|
||||
'alt_text': 'The very first comic',
|
||||
'author_note': 'This is where your comic journey begins!',
|
||||
'author_note_md': '2025-01-01.md', # Optional: use markdown from content/author_notes/2025-01-01.md (overrides author_note)
|
||||
'full_width': True, # Optional: override FULL_WIDTH_DEFAULT for this comic
|
||||
'plain': True, # Optional: override PLAIN_DEFAULT for this comic
|
||||
'section': 'Chapter 1: The Beginning', # Optional: start a new section on archive page
|
||||
|
||||
@@ -53,7 +53,7 @@ def main():
|
||||
"""Add a new comic entry with defaults"""
|
||||
parser = argparse.ArgumentParser(description='Add a new comic entry to comics_data.py')
|
||||
parser.add_argument('-m', '--markdown', action='store_true',
|
||||
help='Generate a markdown file for author notes')
|
||||
help='Generate a markdown file for author notes and add author_note_md field to comic entry')
|
||||
args = parser.parse_args()
|
||||
|
||||
# Get next number
|
||||
@@ -77,7 +77,16 @@ def main():
|
||||
content = f.read()
|
||||
|
||||
# Format new entry
|
||||
entry_str = f""" {{
|
||||
if args.markdown:
|
||||
entry_str = f""" {{
|
||||
'number': {comic['number']},
|
||||
'filename': {repr(comic['filename'])},
|
||||
'date': {repr(comic['date'])},
|
||||
'alt_text': {repr(comic['alt_text'])},
|
||||
'author_note_md': {repr(comic['date'] + '.md')}
|
||||
}}"""
|
||||
else:
|
||||
entry_str = f""" {{
|
||||
'number': {comic['number']},
|
||||
'filename': {repr(comic['filename'])},
|
||||
'date': {repr(comic['date'])},
|
||||
|
||||
Reference in New Issue
Block a user