-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcreate_new_entry.sh
executable file
·55 lines (49 loc) · 1.78 KB
/
create_new_entry.sh
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
#!/bin/sh
# this script creates a new news entry
# it's a little smarter than it used to be to account for per-platform, per-branch updates
# You can still run it with just ./create_new_entry.sh but it will fill in some
# of the necessary fields for you and. You can also now pass it environment variables TITLE,
# HREF, and AUTHOR to set the title, href, and author of the entry.
#
# Example usage:
# TITLE="Title Here" AUTHOR=idk EDITOR=mousepad I2P_OS=win I2P_BRANCH=beta ./create_new_entry.sh
ENTRIES=data/$I2P_OS/$I2P_BRANCH/entries.html
UUIDGEN="`which uuidgen || which uuid`"
if [ -z "$DATE" ]; then
DATE=$(date +%Y-%m-%dT%H:00:00Z)
YEAR=$(date +%Y)
MONTH=$(date +%m)
DAY=$(date +%d)
else
DATE2=$(echo "$DATE" | sed 's/T.*//')
YEAR=$(echo "$DATE2" | cut -d - -f 1)
MONTH=$(echo "$DATE2" | cut -d - -f 2)
DAY=$(echo "$DATE2" | cut -d - -f 3)
fi
if [ -z "$HREF" ]; then
if [ ! -z "$CHANGEME_URL_HERE" ]; then
CHANGEME_URL_HERE=CHANGEME_URL_HERE
else
CHANGEME_URL_HERE=$(echo "$TITLE" | tr "[:upper:]" "[:lower:]" | sed 's| |_|g')
fi
HREF="http://i2p-projekt.i2p/en/blog/post/$YEAR/$MONTH/$DAY/$CHANGEME_URL_HERE"
fi
TITLE=${TITLE:-TITLE_HERE}
AUTHOR=${AUTHOR:-AUTHOR_HERE}
if [ -z "$SUMMARY_HERE" ]; then
SUMMARY_HERE="SUMMARY_HERE"
fi
if [ -z "$CONTENT_HERE" ]; then
CONTENT_HERE="<p>\n\n</p>"
fi
sed -i "3i <article\n id=\"urn:uuid:`$UUIDGEN`\"\n title=\"$TITLE\"\n href=\"$HREF\"\n author=\"$AUTHOR\"\n published=\"$DATE\"\n updated=\"$DATE\">\n<details>\n<summary>$SUMMARY_HERE</summary>\n</details>\n$CONTENT_HERE\n</article>\n\n\n" $ENTRIES
if [ ! -z "$EDITOR" ]; then
case "$EDITOR" in
"nano" | "vim")
$EDITOR +13 $ENTRIES
;;
*)
$EDITOR $ENTRIES
;;
esac
fi