From 3fa633addc0401b6d1b0466bee74dc9c70fbfc4f Mon Sep 17 00:00:00 2001
From: Thierry Berger <contact@thierryberger.com>
Date: Mon, 16 Oct 2023 12:29:15 +0200
Subject: [PATCH] script to help preparing new newswletters

---
 newsletter-template.md        |  8 ++++----
 scripts/prepare_newsletter.sh | 24 ++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 4 deletions(-)
 create mode 100644 scripts/prepare_newsletter.sh

diff --git a/newsletter-template.md b/newsletter-template.md
index 831ecd123..491d9de16 100644
--- a/newsletter-template.md
+++ b/newsletter-template.md
@@ -1,7 +1,7 @@
 +++
-title = "This Month in Rust GameDev #{TODO} - {TODO} {TODO}"
+title = "This Month in Rust GameDev #{TODO_id} - {TODO_month} {TODO_day}"
 transparent = true
-date = TODO
+date = {TODO_date}
 draft = true
 +++
 
@@ -9,7 +9,7 @@ draft = true
 
 <!-- Check the post with markdownlint-->
 
-Welcome to the {TODO}th issue of the Rust GameDev Workgroup's
+Welcome to the {TODO_id}th issue of the Rust GameDev Workgroup's
 monthly newsletter.
 [Rust] is a systems language pursuing the trifecta:
 safety, concurrency, and speed.
@@ -35,8 +35,8 @@ Feel free to send PRs about your own projects!
 - [Learning Material Updates](#learning-material-updates)
 - [Tooling Updates](#tooling-updates)
 - [Library Updates](#library-updates)
-- [Other News](#other-news)
 - [Popular Workgroup Issues in Github](#popular-workgroup-issues-in-github)
+- [Other News](#other-news)
 - [Meeting Minutes](#meeting-minutes)
 - [Discussions](#discussions)
 - [Requests for Contribution](#requests-for-contribution)
diff --git a/scripts/prepare_newsletter.sh b/scripts/prepare_newsletter.sh
new file mode 100644
index 000000000..6653d1a9b
--- /dev/null
+++ b/scripts/prepare_newsletter.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+# This scripts parses existing news, and copies the newsletter template
+# alongside the others, with its incremented id number.
+# This script also replaces the TODOs related to the news id number.
+
+read -r -d '\n' -a news <<< `find content/news/ -type d -printf "%f\n"`
+
+last_news=`echo ${news[-1]} | sed -r s/0//`
+echo $last_news
+news_to_create_simple=$((last_news+1))
+news_to_create=`printf "%#03s" $news_to_create_simple`
+
+read -e -p "Do you want to create issue $news_to_create? (y/n): " choice
+
+[[ "$choice" != [Yy]* ]] && exit
+
+echo "accepted"
+
+new_file="content/news/$news_to_create/index.md"
+
+mkdir -p content/news/$news_to_create && cp -r newsletter-template.md $new_file
+
+sed -i 's/{TODO_id}/'$news_to_create_simple'/g' $new_file
\ No newline at end of file