Add templates and generation script
This commit is contained in:
parent
c201bd380b
commit
802f4c3ece
3 changed files with 128 additions and 5 deletions
72
scripts/create_newsletter.py
Normal file
72
scripts/create_newsletter.py
Normal file
|
|
@ -0,0 +1,72 @@
|
||||||
|
import argparse
|
||||||
|
import locale
|
||||||
|
from pathlib import Path
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
|
MONDAY = 0 # 0 = Monday, 1=Tuesday, 2=Wednesday...
|
||||||
|
|
||||||
|
|
||||||
|
def get_next_weekday(d, weekday):
|
||||||
|
days_ahead = weekday - d.weekday()
|
||||||
|
if days_ahead <= 0: # Target day already happened this week
|
||||||
|
days_ahead += 7
|
||||||
|
return d + timedelta(days_ahead)
|
||||||
|
|
||||||
|
|
||||||
|
def set_publication_date_for_humans(text: str, publication_date: datetime) -> str:
|
||||||
|
locale.setlocale(locale.LC_TIME, "fr_FR")
|
||||||
|
date = publication_date.strftime("%d %B %Y")
|
||||||
|
return text.replace("{DATE}", date)
|
||||||
|
|
||||||
|
|
||||||
|
def set_publication_date_for_pelican(text: str, publication_date: datetime) -> str:
|
||||||
|
date_digits = publication_date.isoformat()[0:10]
|
||||||
|
return text.replace("{DATE_DIGITS}", date_digits)
|
||||||
|
|
||||||
|
|
||||||
|
def set_publication_date_for_seo(text: str, publication_date: datetime) -> str:
|
||||||
|
locale.setlocale(locale.LC_TIME, "en_US")
|
||||||
|
date_utc = publication_date.strftime("%a %b %d %Y")
|
||||||
|
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()
|
||||||
|
|
||||||
|
# Load the newsletter template
|
||||||
|
template = Path("../template/newsletter.md")
|
||||||
|
content = template.read_text()
|
||||||
|
|
||||||
|
|
||||||
|
new_content = content.replace("{LETTER_NUMBER}", str(args.number))
|
||||||
|
|
||||||
|
today = datetime.today()
|
||||||
|
next_monday = get_next_weekday(today, MONDAY)
|
||||||
|
|
||||||
|
new_content = set_publication_date_for_humans(new_content, next_monday)
|
||||||
|
|
||||||
|
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.write_text(new_content)
|
||||||
|
|
||||||
|
# Load the homepage template
|
||||||
|
template = Path("../template/index.md")
|
||||||
|
content = template.read_text()
|
||||||
|
|
||||||
|
new_content = set_publication_date_for_pelican(content, next_monday)
|
||||||
|
|
||||||
|
new_content = set_publication_date_for_seo(new_content, next_monday)
|
||||||
|
|
||||||
|
for i in reversed(range(args.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)
|
||||||
53
template/index.md
Normal file
53
template/index.md
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
Title: Accueil
|
||||||
|
Date: {DATE_DIGITS} 09:00
|
||||||
|
URL:
|
||||||
|
save_as: index.html
|
||||||
|
Category: Home
|
||||||
|
|
||||||
|
<script type="application/ld+json">
|
||||||
|
{
|
||||||
|
"@context": "https://schema.org",
|
||||||
|
"@type": "WebPage",
|
||||||
|
"name": "Accueil",
|
||||||
|
"description": "Lettre de veille technologique en développement logiciel",
|
||||||
|
"image": [
|
||||||
|
"https://www.craftletter.fr/images/craftletter.svg"
|
||||||
|
],
|
||||||
|
"datePublished": "{DATE_UTC} 09:00:00 GMT+0200 (Coordinated Universal Time)",
|
||||||
|
"author": {
|
||||||
|
"@type": "Person",
|
||||||
|
"name": "Pascal Le Merrer",
|
||||||
|
"url": "https://www.linkedin.com/in/pascal-le-merrer/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<img class="logo" alt="Logo Craft Letter" src="{static}/images/craftletter.svg">
|
||||||
|
|
||||||
|
La Craft Letter est une newsletter hebdomadaire dans laquelle je partage des articles
|
||||||
|
issues de ma veille technologique. Vous y trouverez des articles relatifs au développement logiciel d'une façon générale, qu'il soit front-end, back-end ou autre. Mais aussi des articles consacrés à l'architecture logicielle, la méthodologie, les outils, des projets open source, des conférences...
|
||||||
|
|
||||||
|
Pour savoir qui je suis, ou pourquoi j'écris cette lettre, je vous invite à vous lire l'édito du [premier numéro]({filename}/newsletter/craft-letter-1.md).
|
||||||
|
|
||||||
|
|
||||||
|
<script>
|
||||||
|
(function (s, e, n, d, er) {
|
||||||
|
s['Sender'] = er;
|
||||||
|
s[er] = s[er] || function () {
|
||||||
|
(s[er].q = s[er].q || []).push(arguments)
|
||||||
|
}, s[er].l = 1 * new Date();
|
||||||
|
var a = e.createElement(n),
|
||||||
|
m = e.getElementsByTagName(n)[0];
|
||||||
|
a.async = 1;
|
||||||
|
a.src = d;
|
||||||
|
m.parentNode.insertBefore(a, m)
|
||||||
|
})(window, document, 'script', 'https://cdn.sender.net/accounts_resources/universal.js', 'sender');
|
||||||
|
sender('7ce69975e53330')
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div style="text-align: center" class="sender-form-field" data-sender-form-id="av2kqL"></div>
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# Archives
|
||||||
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
Title: Lettre n°{LETTER_NUMBER} - {DATE}
|
Title: Lettre n°{LETTER_NUMBER} - {DATE}
|
||||||
Date: {DATETIME}
|
Date: {DATE_DIGITS} 09:00
|
||||||
Category: Newsletter
|
Category: Newsletter
|
||||||
|
|
||||||
<script type="application/ld+json">
|
<script type="application/ld+json">
|
||||||
|
|
@ -11,7 +11,7 @@ Category: Newsletter
|
||||||
"image": [
|
"image": [
|
||||||
"https://www.craftletter.fr/images/craftletter.svg"
|
"https://www.craftletter.fr/images/craftletter.svg"
|
||||||
],
|
],
|
||||||
"datePublished": "{DATETIME_UTC} (Coordinated Universal Time)",
|
"datePublished": "{DATE_UTC} 09:00:00 GMT+0200 (Coordinated Universal Time)",
|
||||||
"author": {
|
"author": {
|
||||||
"@type": "Person",
|
"@type": "Person",
|
||||||
"name": "Pascal Le Merrer",
|
"name": "Pascal Le Merrer",
|
||||||
|
|
@ -20,6 +20,4 @@ Category: Newsletter
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<img class="logo" alt="Logo Craft Letter" src="{static}/images/craftletter.svg">
|
<img class="logo" alt="Logo Craft Letter" src="{static}/images/craftletter.svg">
|
||||||
|
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue