feat: generate updates from status.md
This commit is contained in:
parent
14bcf499ed
commit
435b23a63c
2 changed files with 58 additions and 0 deletions
39
scripts/gen.py
Executable file
39
scripts/gen.py
Executable file
|
@ -0,0 +1,39 @@
|
|||
from datetime import datetime
|
||||
from dateutil.parser import parse as parse_date
|
||||
|
||||
|
||||
def write_file(title, contents):
|
||||
title = title.strip()
|
||||
filename = title.replace(' ', '-').lower()
|
||||
if "Current status" in title:
|
||||
date = datetime.now()
|
||||
else:
|
||||
date = parse_date(title)
|
||||
filename += '.md'
|
||||
with open(f"content/updates/{filename}", "w", encoding='utf-8') as f:
|
||||
print(f"[*] Writing update {filename}")
|
||||
f.write("+++\n")
|
||||
f.write(f"title = '{title}'\n")
|
||||
f.write(f"date = '{date}'\n")
|
||||
f.write("+++\n")
|
||||
f.write(update)
|
||||
|
||||
|
||||
with open("./status.md", "r", encoding='utf-8') as f:
|
||||
title = None
|
||||
update = ""
|
||||
for line in f.readlines():
|
||||
if line.startswith("###"):
|
||||
if title:
|
||||
write_file(title, update)
|
||||
|
||||
title = line.removeprefix("### ")
|
||||
update = ""
|
||||
else:
|
||||
if title:
|
||||
if line.startswith("---"):
|
||||
break
|
||||
else:
|
||||
update += line
|
||||
|
||||
write_file(title, update)
|
|
@ -31,4 +31,23 @@ init() {
|
|||
cat README.md | tail -n +5 >> $file
|
||||
}
|
||||
|
||||
prep_status() {
|
||||
mkdir content/updates
|
||||
|
||||
index="content/updates/_index.md"
|
||||
touch $index
|
||||
echo "+++" > $index
|
||||
echo 'render = true' >> $index
|
||||
echo 'title = "Updates"' >> $index
|
||||
echo 'sort_by = "date"' >> $index
|
||||
echo 'template = "updates/index.html"' >> $index
|
||||
echo 'page_template = "updates/post.html"' >> $index
|
||||
echo 'generate_feed = true' >> $index
|
||||
echo "+++" >> $index
|
||||
echo "" >> $index
|
||||
|
||||
python ./scripts/gen.py
|
||||
}
|
||||
|
||||
init
|
||||
prep_status
|
||||
|
|
Loading…
Reference in a new issue