Simplify usage of custom justfile targets

This commit is contained in:
Pascal Le Merrer 2026-03-03 22:39:06 +01:00
parent 7ae5406548
commit 2b450e1b51
7 changed files with 53 additions and 31 deletions

View file

@ -30,17 +30,18 @@ def set_publication_date_for_seo(text: str, publication_date: datetime) -> str:
return text.replace("{DATE_UTC}", date_utc)
# Parse the command line arguments
parser = argparse.ArgumentParser()
parser.add_argument("-n", "--number", required=True, type=int, help="Newsletter number")
args = parser.parse_args()
# Find the number of the letter to create
destination_path = Path(f"./content/newsletter")
p = destination_path.glob("craft-letter-*.md")
files = [x for x in p if x.is_file()]
letter_number = len(files) + 1
# Load the newsletter template
template = Path("./template/newsletter.md")
content = template.read_text()
new_content = content.replace("{LETTER_NUMBER}", str(args.number))
new_content = content.replace("{LETTER_NUMBER}", str(letter_number))
today = datetime.today()
next_monday = get_next_weekday(today, MONDAY)
@ -52,9 +53,11 @@ new_content = set_publication_date_for_pelican(new_content, next_monday)
new_content = set_publication_date_for_seo(new_content, next_monday)
# Create the new file
destination = Path(f"./content/newsletter/craft-letter-{args.number}.md")
destination = destination_path / f"craft-letter-{letter_number}.md"
destination.write_text(new_content)
print(f"Created letter #{letter_number}: {destination}")
# Load the homepage template
template = Path("./template/index.md")
content = template.read_text()
@ -63,15 +66,15 @@ new_content = set_publication_date_for_pelican(content, next_monday)
new_content = set_publication_date_for_seo(new_content, next_monday)
link = (
f"[lettre n°{args.number}]({{filename}}/newsletter/craft-letter-{args.number}.md)"
)
link = f"[lettre n°{letter_number}]({{filename}}/newsletter/craft-letter-{letter_number}.md)"
new_content = new_content.replace("{LINK}", link)
for i in reversed(range(args.number)):
for i in reversed(range(letter_number)):
link = f"* [Lettre n°{i + 1}]({{filename}}/newsletter/craft-letter-{i + 1}.md)\n"
new_content += link
# Update the index page
destination = Path("./content/pages/index.md")
destination.write_text(new_content)
print(f"Updated index page: {destination}")