add script to generate new blog posts
All checks were successful
check / test (push) Successful in 4s
deploy / test (push) Successful in 3s

This commit is contained in:
Jörg Thalheim 2023-09-21 12:51:19 +02:00
parent 6e7419a2b5
commit 11858548a5
4 changed files with 49 additions and 1 deletions

View File

@ -19,9 +19,15 @@ $ zola serve
Send changes to https://git.clan.lol/clan/clan-homepage
## To update the website
```
$ nix run .#deploy
```
## Create a new post
```
$ nix run .#new-post "September Changelog"
```

41
flake-parts/new-post.nix Normal file
View File

@ -0,0 +1,41 @@
{
perSystem = {
lib,
pkgs,
self',
...
}: {
apps.new-post.program = builtins.toString (pkgs.writeShellScript "new-post.sh" ''
export PATH="${lib.makeBinPath [
pkgs.coreutils pkgs.gitMinimal
]}"
if [ -z "$1" ]; then
echo "Usage: new-post.sh <title>"
exit 1
fi
title=$(echo "$1" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')
root=$(git rev-parse --show-toplevel)
fname="$root/content/blog/$(date +%Y-%m-%d)-$title.md"
if [ -f "$fname" ]; then
echo "File already exists: $fname"
exit 1
fi
cat <<EOF > "$fname"
+++
title = "$1"
date = "$(date --iso-8601=seconds)"
draft = true
template = "blog/page.html"
[taxonomies]
authors = [] # TODO
[extra]
lead = "Some lead"
+++
Some text
EOF
echo "Created $fname"
git add "$fname"
'');
};
}

View File

@ -15,6 +15,7 @@
systems = [ "x86_64-linux" ];
imports = [
./flake-parts/deploy.nix
./flake-parts/new-post.nix
./flake-parts/devShells
];
perSystem = { pkgs, ... }: {