blob: 8c2139f30f1ebaf04a2d48b7532641bed58a5721 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
#!/bin/sh
# quick and dirty script to add new posts to aaoth.xyz
SITE_DIR="$HOME/Documents/aaoth.xyz"
POSTS_DIR="$SITE_DIR/_posts"
DATE_SHORT=$(date -I)
DATE_LONG=$(date -Isec)
usage() {
echo "add a post to aaoth.xyz"
echo
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 "new post title: "
read -r TITLE
}
read_tags() {
echo "new post tags: "
read -r 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" || exit 1
# 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 '[:upper:]' '[:lower:]' | 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"
|