aboutsummaryrefslogtreecommitdiffstats
path: root/aaoth_new_post.sh
diff options
context:
space:
mode:
authorla-ninpre <leobrekalini@gmail.com>2021-05-23 20:20:13 +0300
committerla-ninpre <leobrekalini@gmail.com>2021-05-23 20:20:13 +0300
commit19673654ab83e7a9735c64dad632899855620c9c (patch)
tree23b14f00c9f11e7638fd9c4afe08056f8bee03bd /aaoth_new_post.sh
parent7d046658ee53378e88404f40aac4a2c8e2d97bf1 (diff)
downloadaaoth.xyz-19673654ab83e7a9735c64dad632899855620c9c.tar.gz
aaoth.xyz-19673654ab83e7a9735c64dad632899855620c9c.zip
add info about my matrix server
:)
Diffstat (limited to 'aaoth_new_post.sh')
-rwxr-xr-xaaoth_new_post.sh102
1 files changed, 102 insertions, 0 deletions
diff --git a/aaoth_new_post.sh b/aaoth_new_post.sh
new file mode 100755
index 0000000..2a7c7c9
--- /dev/null
+++ b/aaoth_new_post.sh
@@ -0,0 +1,102 @@
+#!/bin/sh
+
+SITE_DIR="$HOME/Documents/aaoth.xyz"
+POSTS_DIR="$SITE_DIR/_posts"
+
+DATE_SHORT=$(date -I)
+DATE_LONG=$(date -Isec)
+
+usage() {
+ echo "usage:"
+ echo " $0 [OPTIONS]"
+ echo
+ echo "options:"
+ echo " -t, --title <title>"
+ echo " specify new post title"
+ echo " -g, --tags <tags>"
+ echo " specify new post tags"
+ echo " -h, --help"
+ echo " print usage information"
+}
+
+read_title() {
+ echo -n "new post title: "
+ read TITLE
+}
+
+read_tags() {
+ echo -n "new post tags: "
+ read TAGS
+}
+
+create_tag_page() {
+ cat <<- TAG > "$SITE_DIR/tags/$1.md"
+---
+layout: tagsort
+tag: $1
+title: "tags: $1"
+permalink: /tags/$1/
+---
+TAG
+}
+
+cd $SITE_DIR
+
+# if there are no arguments specified, run interactively
+if [ $# -gt 0 ]
+then
+ while [ -n "$1" ]
+ do
+ case "$1" in
+ --title|-t)
+ shift
+ TITLE=$1
+ ;;
+ --tags|-g)
+ shift
+ TAGS=$1
+ ;;
+ --help|-h)
+ usage
+ exit 2
+ ;;
+ *)
+ usage
+ exit 1
+ ;;
+ esac
+ shift
+ done
+fi
+
+[ -z "$TITLE" ] && read_title
+[ -z "$TITLE" ] && echo "title could not be empty" && exit 1
+
+[ -z "$TAGS" ] && read_tags
+[ -z "$TAGS" ] && echo "specify at least one tag" && exit 1
+
+TITLE_FILE=$(echo $TITLE | tr '[A-Z]' '[a-z]' | sed 's/ /-/g')
+
+POST_FILENAME="$POSTS_DIR/$DATE_SHORT-$TITLE_FILE.md"
+
+for _tag in $TAGS
+do
+ [ ! -f "./tags/$_tag.md" ] \
+ && echo "tag $_tag is not present, creating one" \
+ && create_tag_page $_tag
+done
+
+# template is currently hardcoded
+cat <<-EOF > "$POST_FILENAME"
+---
+title: $TITLE
+date: $DATE_LONG
+author: la-ninpre
+tags: $TAGS
+---
+
+<!--more-->
+
+EOF
+
+nvim -c "normal 6jo" -c "startinsert" $POST_FILENAME