mkblogpost.sh 505 Bytes
Newer Older
PoroCYon's avatar
PoroCYon committed
1 2 3 4 5 6 7
#!/usr/bin/env bash

set -e

read -erp "Title: " TITLE
read -erp "Filename: " FILENAME

PoroCYon's avatar
PoroCYon committed
8 9
DIR="src/blog/post/"
FILE="${DIR}${FILENAME}.md"
PoroCYon's avatar
PoroCYon committed
10

PoroCYon's avatar
PoroCYon committed
11 12 13 14 15
mkdir -p "$DIR"

ADDENTRY=0

if ! [ -f "$FILE" ]; then
16 17 18 19
    cat > "$FILE" <<EOF
---
title: ${TITLE}
blog-comment-link: ${FILENAME}
PoroCYon's avatar
PoroCYon committed
20
blog-date: $(date '+%F')
21 22 23 24 25 26 27
...

# ${TITLE}



EOF
PoroCYon's avatar
PoroCYon committed
28 29 30 31 32 33 34
    ADDENTRY=1
fi

$EDITOR "$FILE"
git add "$FILE"

if [ "$ADDENTRY" = 1 ] && [ -f "$FILE" ]; then
PoroCYon's avatar
PoroCYon committed
35 36 37
    echo -e "${FILENAME}\t$(date '+%F')\t${TITLE}\t$(uuidgen)" >> src/blog/postdb.tsv
fi