Improve tooling

This commit is contained in:
Pascal Le Merrer 2026-02-28 11:23:55 +01:00
parent 458352da97
commit 3165d050a1
3 changed files with 24 additions and 16 deletions

View file

@ -40,7 +40,8 @@ devserver-global:
pelican -lr content -o output -s "{{CONFFILE}}" {{PELICANOPTS}} -b 0.0.0.0 pelican -lr content -o output -s "{{CONFFILE}}" {{PELICANOPTS}} -b 0.0.0.0
# generate using production settings # generate using production settings
publish: publish number:
just format {{number}}
pelican content -o output -s "{{PUBLISHCONF}}" {{PELICANOPTS}} pelican content -o output -s "{{PUBLISHCONF}}" {{PELICANOPTS}}
rsync -e ssh -av --delete-after /Users/pascal/Documents/craft-letter/output/ craftletter@ssh-craftletter.alwaysdata.net:/home/craftletter/www rsync -e ssh -av --delete-after /Users/pascal/Documents/craft-letter/output/ craftletter@ssh-craftletter.alwaysdata.net:/home/craftletter/www
@ -53,8 +54,9 @@ new number:
PYTHONPATH=PWD venv/bin/python ./scripts/create_newsletter.py --number={{number}} PYTHONPATH=PWD venv/bin/python ./scripts/create_newsletter.py --number={{number}}
# generate HTML email # generate HTML email
mail file: mail number:
PYTHONPATH=PWD venv/bin/python ./scripts/prepare_email.py {{file}} just format {{number}}
PYTHONPATH=PWD venv/bin/python ./scripts/prepare_email.py --number={{number}}
# Format the content of a given newsletter # Format the content of a given newsletter
format number: format number:

View file

@ -3,9 +3,9 @@ from pathlib import Path
REPLACEMENTS = { REPLACEMENTS = {
" :": " :", " :": " :",
" ;": " :", " ;": " ;",
" !": " :", " !": " !:",
" ?": " :", " ?": " ?",
"'": "", "'": "",
} }
@ -15,9 +15,8 @@ args = parser.parse_args()
file = Path(f"./content/newsletter/craft-letter-{args.number}.md") file = Path(f"./content/newsletter/craft-letter-{args.number}.md")
with open(file) as f: content = file.read_text()
content = f.read() for value, replacement in REPLACEMENTS.items():
for value, replacement in REPLACEMENTS.items(): content = content.replace(value, replacement)
content = content.replace(value, replacement)
file.write_text(content) file.write_text(content)

View file

@ -1,6 +1,8 @@
#!python #!python
# Copies the given input file, removing the parts specific to the Web, # Copies the given input file, removing the parts specific to the Web,
# so it can be converted to an email # so it can be converted to an email
from datetime import date
from docutils.parsers.rst.directives.misc import Date
import subprocess import subprocess
import argparse import argparse
@ -11,13 +13,10 @@ MAIL_GENERATOR = "/opt/homebrew/bin/mdtosendy"
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("source") parser.add_argument("-n", "--number", required=True, type=int, help="Newsletter number")
args = parser.parse_args() args = parser.parse_args()
root = Path.cwd() source = Path(f"./content/newsletter/craft-letter-{args.number}.md")
print(f"Root: {root}")
source = Path(root / args.source)
if not source.is_file(): if not source.is_file():
print(f"ERROR: file not found {source}") print(f"ERROR: file not found {source}")
@ -34,4 +33,12 @@ destination = Path.cwd() / "mail" / source.name
print(f"Writing {destination}") print(f"Writing {destination}")
destination.write_text(output) destination.write_text(output)
subprocess.run([MAIL_GENERATOR, "--preview", str(destination)]) subprocess.run([MAIL_GENERATOR, str(destination)])
generated_mail = Path("mail") / f"craft-letter-{args.number}.html"
today = date.today()
mail_content = generated_mail.read_text()
mail_content = mail_content.replace("{{YEAR}}", str(today.year))
generated_mail.write_text(mail_content)
subprocess.run(["open", str(generated_mail)])