refactor: make better use of global variables
This commit is contained in:
parent
54ab6805b5
commit
c44c87e735
@ -5,13 +5,17 @@
|
|||||||
# hugo variables (local machine)
|
# hugo variables (local machine)
|
||||||
scriptname=$(basename "$0")
|
scriptname=$(basename "$0")
|
||||||
blog_dir="$HOME/src/blog" # or the path to your blog
|
blog_dir="$HOME/src/blog" # or the path to your blog
|
||||||
local_url="http://localhost:1313/posts/"
|
local_url="http://localhost:1313/"
|
||||||
post_filename=""
|
post_filename=""
|
||||||
postname=""
|
postname=""
|
||||||
|
full_post_dir=""
|
||||||
|
full_post_url=""
|
||||||
|
|
||||||
# deployment variables
|
# deployment variables
|
||||||
|
# TODO set deployment variables
|
||||||
|
|
||||||
set_names() {
|
set_vars() {
|
||||||
|
# handle extraneous .md file extension
|
||||||
local arg="$1"
|
local arg="$1"
|
||||||
if [[ ! "$arg" =~ .md$ ]]; then
|
if [[ ! "$arg" =~ .md$ ]]; then
|
||||||
postname="$arg"
|
postname="$arg"
|
||||||
@ -19,18 +23,23 @@ set_names() {
|
|||||||
postname="${arg%???}"
|
postname="${arg%???}"
|
||||||
fi
|
fi
|
||||||
post_filename="$postname.md"
|
post_filename="$postname.md"
|
||||||
|
|
||||||
|
# hugo post location for server
|
||||||
|
full_post_dir="$blog_dir/content/posts/$post_filename"
|
||||||
|
|
||||||
|
# url for browser
|
||||||
|
full_post_url="$local_url/posts/$postname"
|
||||||
}
|
}
|
||||||
|
|
||||||
serve_and_open() {
|
serve_and_open() {
|
||||||
killall hugo > /dev/null 2>&1
|
killall hugo > /dev/null 2>&1
|
||||||
hugo serve -s "$blog_dir" -D > /dev/null 2>&1 &
|
hugo serve -s "$blog_dir" -D > /dev/null 2>&1 &
|
||||||
xdg-open "http://localhost:1313/posts/$postname"
|
xdg-open "$full_post_url"
|
||||||
echo "Don't forget to \"killall hugo\" when finished"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
edit_post() {
|
edit_post() {
|
||||||
serve_and_open
|
serve_and_open
|
||||||
$EDITOR "$blog_dir/content/posts/$post_filename" && kill %1
|
$EDITOR "$full_post_dir" && kill %1
|
||||||
}
|
}
|
||||||
|
|
||||||
new_post() {
|
new_post() {
|
||||||
@ -67,18 +76,19 @@ while (($#)); do
|
|||||||
case "$1" in
|
case "$1" in
|
||||||
new-post|newpost|np|new|n)
|
new-post|newpost|np|new|n)
|
||||||
shift
|
shift
|
||||||
set_names "$1"
|
set_vars "$1"
|
||||||
new_post "$1"
|
new_post "$1"
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
edit-post|edit|ep|e)
|
edit-post|edit|ep|e)
|
||||||
shift
|
shift
|
||||||
set_names "$1"
|
set_vars "$1"
|
||||||
edit_post "$1"
|
edit_post "$1"
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
list-post|list|lp|l|ls)
|
list-post|list|lp|l|ls)
|
||||||
ls -ltr "$blog_dir/content/posts"
|
# hugo list all | cut -d, -f1 | tail -n +2
|
||||||
|
hugo list all | cut -f1,4 -d, | tail -n +2 | tr ',' ' ' | column -t
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
list-drafts|listdraft|ld)
|
list-drafts|listdraft|ld)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user