Skip to content

Commit 220ff08

Browse files
committedSep 10, 2020
new post script, todo updated
1 parent 086744e commit 220ff08

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed
 

‎README.md

-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ This is a slow rebuild of neenjaw.com transitioned to jekyll (ruby-based)
77
## Todo
88

99
- style logo/header
10-
- post index
1110
- post navigation
1211
- colors

‎new_post.sh

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
function main {
6+
if [[ "${#}" -eq 1 ]]; then
7+
output_dir="./_posts"
8+
title="${1}"
9+
elif [[ "${#}" -eq 2 && -d "${1}" ]]; then
10+
output_dir=$(realpath "${1}")
11+
title="${2}"
12+
else
13+
die "USAGE: ./new_post.sh (<title>) | (<existing dir> <title>)"
14+
fi
15+
16+
current_date=$(date +"%Y-%m-%d")
17+
current_time=$(date +"%H:%M:%S")
18+
19+
new_post_content=(
20+
"---"
21+
"layout: post"
22+
"title: ${title}"
23+
"date: ${current_date} ${current_time} -0600"
24+
"categories: "
25+
"---"
26+
)
27+
28+
printf '%s\n' "${new_post_content[@]}" > "${output_dir}/${current_date}-${title}.markdown"
29+
}
30+
31+
function installed {
32+
cmd=$(command -v "${1}")
33+
34+
[[ -n "${cmd}" ]] && [[ -f "${cmd}" ]]
35+
return ${?}
36+
}
37+
38+
function die {
39+
>&2 echo "Fatal: ${@}"
40+
exit 1
41+
}
42+
43+
# Check for all required dependencies
44+
deps=(realpath)
45+
for dep in "${deps[@]}"; do
46+
installed "${dep}" || die "Missing '${dep}'"
47+
done
48+
49+
main "$@"; exit

0 commit comments

Comments
 (0)
Please sign in to comment.