Add new-draft
script
This commit is contained in:
parent
0f99141e8e
commit
469049521d
2 changed files with 27 additions and 0 deletions
|
@ -22,6 +22,7 @@
|
||||||
tailwindcss
|
tailwindcss
|
||||||
|
|
||||||
(import ./drafts.nix { inherit pkgs; })
|
(import ./drafts.nix { inherit pkgs; })
|
||||||
|
(import ./new-draft.nix { inherit pkgs; })
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
26
new-draft.nix
Normal file
26
new-draft.nix
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
{ pkgs }:
|
||||||
|
|
||||||
|
pkgs.writeShellApplication {
|
||||||
|
name = "new-draft";
|
||||||
|
|
||||||
|
runtimeInputs = with pkgs; [ coreutils git ];
|
||||||
|
|
||||||
|
text = ''
|
||||||
|
title="$1"
|
||||||
|
|
||||||
|
exclude_words="for|at|and"
|
||||||
|
|
||||||
|
filtered_title=$(echo "$title" | sed -E "s/\b($exclude_words)\b//g")
|
||||||
|
|
||||||
|
slug=$(echo "$filtered_title" | tr '[:upper:]' '[:lower:]' | sed -e 's/[^a-z0-9]/-/g' -e 's/-\+/-/g' -e 's/^-//g' -e 's/-$//g')
|
||||||
|
|
||||||
|
file="source/_posts/$slug.md"
|
||||||
|
|
||||||
|
echo -e "---\ntitle: $title\ndate: ~\ndraft: true\n---" > "$file"
|
||||||
|
|
||||||
|
echo "File created: $file"
|
||||||
|
|
||||||
|
git add "$file"
|
||||||
|
git commit -s -m "Add draft: $title"
|
||||||
|
'';
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue