plugin/jekyll: try to shorten the flow
Alsö, use `pushd`/`popd` instead of `builtin cd`. Alsö, SC2153pull/1969/head
parent
e38eeefc5f
commit
3fe9c8d6bc
|
|
@ -8,7 +8,7 @@ function editpost() {
|
||||||
group 'jekyll'
|
group 'jekyll'
|
||||||
|
|
||||||
local SITE site POST DATE TITLE POSTS
|
local SITE site POST DATE TITLE POSTS
|
||||||
local -i COUNTER=1 POST_TO_EDIT
|
local -i COUNTER=1 POST_TO_EDIT ret
|
||||||
if [[ -z "${1:-}" ]]; then
|
if [[ -z "${1:-}" ]]; then
|
||||||
echo "Error: no site specified."
|
echo "Error: no site specified."
|
||||||
echo "The site is the name of the directory your project is in."
|
echo "The site is the name of the directory your project is in."
|
||||||
|
|
@ -27,7 +27,7 @@ function editpost() {
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
builtin cd "${SITE}/_posts" || return
|
pushd "${SITE}/_posts" > /dev/null || return
|
||||||
|
|
||||||
for POST in *; do
|
for POST in *; do
|
||||||
DATE="$(echo "${POST}" | grep -oE "[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}")"
|
DATE="$(echo "${POST}" | grep -oE "[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}")"
|
||||||
|
|
@ -36,9 +36,12 @@ function editpost() {
|
||||||
echo "${COUNTER}) ${DATE} ${TITLE}"
|
echo "${COUNTER}) ${DATE} ${TITLE}"
|
||||||
POSTS[COUNTER]="$POST"
|
POSTS[COUNTER]="$POST"
|
||||||
COUNTER="$((COUNTER + 1))"
|
COUNTER="$((COUNTER + 1))"
|
||||||
done | less
|
done > >(less)
|
||||||
read -rp "Number of post to edit: " POST_TO_EDIT
|
read -rp "Number of post to edit: " POST_TO_EDIT
|
||||||
"${JEKYLL_EDITOR:-${VISUAL:-${EDITOR:-${ALTERNATE_EDITOR:-nano}}}}" "${POSTS[POST_TO_EDIT]}"
|
"${JEKYLL_EDITOR:-${VISUAL:-${EDITOR:-${ALTERNATE_EDITOR:-nano}}}}" "${POSTS[POST_TO_EDIT]}"
|
||||||
|
ret="$?"
|
||||||
|
popd > /dev/null || return "$ret"
|
||||||
|
return "$ret"
|
||||||
}
|
}
|
||||||
|
|
||||||
function newpost() {
|
function newpost() {
|
||||||
|
|
@ -48,7 +51,7 @@ function newpost() {
|
||||||
|
|
||||||
local SITE site FNAME_POST_TITLE FNAME YAML_DATE
|
local SITE site FNAME_POST_TITLE FNAME YAML_DATE
|
||||||
local JEKYLL_FORMATTING FNAME_DATE OPTIONS OPTION POST_TYPE POST_TITLE
|
local JEKYLL_FORMATTING FNAME_DATE OPTIONS OPTION POST_TYPE POST_TITLE
|
||||||
local -i loc=0
|
local -i loc=0 ret
|
||||||
if [[ -z "${1:-}" ]]; then
|
if [[ -z "${1:-}" ]]; then
|
||||||
echo "Error: no site specified."
|
echo "Error: no site specified."
|
||||||
echo "The site is the name of the directory your project is in."
|
echo "The site is the name of the directory your project is in."
|
||||||
|
|
@ -69,62 +72,29 @@ function newpost() {
|
||||||
loc=$((loc + 1))
|
loc=$((loc + 1))
|
||||||
done
|
done
|
||||||
|
|
||||||
# 'builtin cd' into the local jekyll root
|
# Change directory into the local jekyll root
|
||||||
|
pushd "${SITE}/_posts" > /dev/null || return
|
||||||
builtin cd "${SITE}/_posts" || return
|
|
||||||
|
|
||||||
# Get the date for the new post's filename
|
# Get the date for the new post's filename
|
||||||
|
|
||||||
FNAME_DATE="$(date "+%Y-%m-%d")"
|
FNAME_DATE="$(date "+%Y-%m-%d")"
|
||||||
|
|
||||||
# If the user is using markdown or textile formatting, let them choose what type of post they want. Sort of like Tumblr.
|
# If the user is using markdown or textile formatting, let them choose what type of post they want. Sort of like Tumblr.
|
||||||
|
|
||||||
OPTIONS=('Text' 'Quote' 'Image' 'Audio' 'Video' 'Link')
|
OPTIONS=('Text' 'Quote' 'Image' 'Audio' 'Video' 'Link')
|
||||||
|
|
||||||
if [[ $JEKYLL_FORMATTING == "markdown" || $JEKYLL_FORMATTING == "textile" ]]; then
|
if [[ $JEKYLL_FORMATTING == "markdown" || $JEKYLL_FORMATTING == "textile" ]]; then
|
||||||
select OPTION in "${OPTIONS[@]}"; do
|
select OPTION in "${OPTIONS[@]}"; do
|
||||||
if [[ $OPTION == "Text" ]]; then
|
POST_TYPE="${OPTION}"
|
||||||
POST_TYPE="Text"
|
break
|
||||||
break
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $OPTION == "Quote" ]]; then
|
|
||||||
POST_TYPE="Quote"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $OPTION == "Image" ]]; then
|
|
||||||
POST_TYPE="Image"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $OPTION == "Audio" ]]; then
|
|
||||||
POST_TYPE="Audio"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $OPTION == "Video" ]]; then
|
|
||||||
POST_TYPE="Video"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $OPTION == "Link" ]]; then
|
|
||||||
POST_TYPE="Link"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get the title for the new post
|
# Get the title for the new post
|
||||||
|
|
||||||
read -rp "Enter title of the new post: " POST_TITLE
|
read -rp "Enter title of the new post: " POST_TITLE
|
||||||
|
|
||||||
# Convert the spaces in the title to hyphens for use in the filename
|
# Convert the spaces in the title to hyphens for use in the filename
|
||||||
|
|
||||||
FNAME_POST_TITLE="${POST_TITLE/ /-}"
|
FNAME_POST_TITLE="${POST_TITLE/ /-}"
|
||||||
|
|
||||||
# Now, put it all together for the full filename
|
# Now, put it all together for the full filename
|
||||||
|
|
||||||
FNAME="$FNAME_DATE-$FNAME_POST_TITLE.$JEKYLL_FORMATTING"
|
FNAME="$FNAME_DATE-$FNAME_POST_TITLE.$JEKYLL_FORMATTING"
|
||||||
|
|
||||||
# And, finally, create the actual post file. But we're not done yet...
|
# And, finally, create the actual post file. But we're not done yet...
|
||||||
|
|
@ -151,72 +121,65 @@ function newpost() {
|
||||||
} > "${FNAME}"
|
} > "${FNAME}"
|
||||||
|
|
||||||
# Generate template text based on the post type
|
# Generate template text based on the post type
|
||||||
|
|
||||||
if [[ $JEKYLL_FORMATTING == "markdown" ]]; then
|
if [[ $JEKYLL_FORMATTING == "markdown" ]]; then
|
||||||
if [[ $POST_TYPE == "Text" ]]; then
|
case $POST_TYPE in
|
||||||
true
|
"Text")
|
||||||
fi
|
true
|
||||||
|
;;
|
||||||
if [[ $POST_TYPE == "Quote" ]]; then
|
"Quote")
|
||||||
echo "> Quote"
|
echo "> Quote"
|
||||||
echo
|
echo
|
||||||
echo "— Author"
|
echo "— Author"
|
||||||
fi
|
;;
|
||||||
|
"Image")
|
||||||
if [[ $POST_TYPE == "Image" ]]; then
|
echo ""
|
||||||
echo ""
|
;;
|
||||||
fi
|
"Audio")
|
||||||
|
echo "<html><audio src=\"/path/to/audio/file\" controls=\"controls\"></audio></html>"
|
||||||
if [[ $POST_TYPE == "Audio" ]]; then
|
;;
|
||||||
echo "<html><audio src=\"/path/to/audio/file\" controls=\"controls\"></audio></html>"
|
"Video")
|
||||||
fi
|
echo "<html><video src=\"/path/to/video\" controls=\"controls\"></video></html>"
|
||||||
|
;;
|
||||||
if [[ $POST_TYPE == "Video" ]]; then
|
"Link")
|
||||||
echo "<html><video src=\"/path/to/video\" controls=\"controls\"></video></html>"
|
echo "[link][1]"
|
||||||
fi
|
echo
|
||||||
|
echo "> Quote"
|
||||||
if [[ $POST_TYPE == "Link" ]]; then
|
echo
|
||||||
echo "[link][1]"
|
echo "[1]: url"
|
||||||
echo
|
;;
|
||||||
echo "> Quote"
|
esac
|
||||||
echo
|
elif [[ $JEKYLL_FORMATTING == "textile" ]]; then
|
||||||
echo "[1]: url"
|
case $POST_TYPE in
|
||||||
fi
|
"Text")
|
||||||
fi >> "${FNAME}"
|
true
|
||||||
|
;;
|
||||||
if [[ $JEKYLL_FORMATTING == "textile" ]]; then
|
"Quote")
|
||||||
if [[ $POST_TYPE == "Text" ]]; then
|
echo "bq. Quote"
|
||||||
true
|
echo
|
||||||
fi
|
echo "— Author"
|
||||||
|
;;
|
||||||
if [[ $POST_TYPE == "Quote" ]]; then
|
"Image")
|
||||||
echo "bq. Quote"
|
echo "!url(alt text)"
|
||||||
echo
|
;;
|
||||||
echo "— Author"
|
"Audio")
|
||||||
fi
|
echo "<html><audio src=\"/path/to/audio/file\" controls=\"controls\"></audio></html>"
|
||||||
|
;;
|
||||||
if [[ $POST_TYPE == "Image" ]]; then
|
"Video")
|
||||||
echo "!url(alt text)"
|
echo "<html><video src=\"/path/to/video\" controls=\"controls\"></video></html>"
|
||||||
fi
|
;;
|
||||||
|
"Link")
|
||||||
if [[ $POST_TYPE == "Audio" ]]; then
|
echo "\"Site\":url"
|
||||||
echo "<html><audio src=\"/path/to/audio/file\" controls=\"controls\"></audio></html>"
|
echo
|
||||||
fi
|
echo "bq. Quote"
|
||||||
|
;;
|
||||||
if [[ $POST_TYPE == "Video" ]]; then
|
esac
|
||||||
echo "<html><video src=\"/path/to/video\" controls=\"controls\"></video></html>"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $POST_TYPE == "Link" ]]; then
|
|
||||||
echo "\"Site\":url"
|
|
||||||
echo
|
|
||||||
echo "bq. Quote"
|
|
||||||
fi
|
|
||||||
fi >> "${FNAME}"
|
fi >> "${FNAME}"
|
||||||
|
|
||||||
# Open the file in your favorite editor
|
# Open the file in your favorite editor
|
||||||
|
|
||||||
"${JEKYLL_EDITOR:-${VISUAL:-${EDITOR:-${ALTERNATE_EDITOR:-nano}}}}" "${FNAME}"
|
"${JEKYLL_EDITOR:-${VISUAL:-${EDITOR:-${ALTERNATE_EDITOR:-nano}}}}" "${FNAME}"
|
||||||
|
ret="$?"
|
||||||
|
popd > /dev/null || return "$ret"
|
||||||
|
return "$ret"
|
||||||
}
|
}
|
||||||
|
|
||||||
function testsite() {
|
function testsite() {
|
||||||
|
|
@ -225,6 +188,7 @@ function testsite() {
|
||||||
group 'jekyll'
|
group 'jekyll'
|
||||||
|
|
||||||
local SITE site
|
local SITE site
|
||||||
|
local -i ret
|
||||||
if [[ -z "${1:-}" ]]; then
|
if [[ -z "${1:-}" ]]; then
|
||||||
echo "Error: no site specified."
|
echo "Error: no site specified."
|
||||||
echo "The site is the name of the directory your project is in."
|
echo "The site is the name of the directory your project is in."
|
||||||
|
|
@ -243,8 +207,11 @@ function testsite() {
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
builtin cd "${SITE}" || return
|
pushd "${SITE}" > /dev/null || return
|
||||||
jekyll --server --auto
|
jekyll --server --auto
|
||||||
|
ret="$?"
|
||||||
|
popd > /dev/null || return "$ret"
|
||||||
|
return "$ret"
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildsite() {
|
function buildsite() {
|
||||||
|
|
@ -253,6 +220,7 @@ function buildsite() {
|
||||||
group 'jekyll'
|
group 'jekyll'
|
||||||
|
|
||||||
local SITE site
|
local SITE site
|
||||||
|
local -i ret
|
||||||
if [[ -z "${1:-}" ]]; then
|
if [[ -z "${1:-}" ]]; then
|
||||||
echo "Error: no site specified."
|
echo "Error: no site specified."
|
||||||
echo "The site is the name of the directory your project is in."
|
echo "The site is the name of the directory your project is in."
|
||||||
|
|
@ -271,9 +239,12 @@ function buildsite() {
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
builtin cd "${SITE}" || return
|
pushd "${SITE}" > /dev/null || return
|
||||||
rm -rf _site
|
rm -rf _site
|
||||||
jekyll --no-server
|
jekyll --no-server
|
||||||
|
ret="$?"
|
||||||
|
popd > /dev/null || return "$ret"
|
||||||
|
return "$ret"
|
||||||
}
|
}
|
||||||
|
|
||||||
function deploysite() {
|
function deploysite() {
|
||||||
|
|
@ -282,7 +253,7 @@ function deploysite() {
|
||||||
group 'jekyll'
|
group 'jekyll'
|
||||||
|
|
||||||
local SITE site REMOTE
|
local SITE site REMOTE
|
||||||
local -i loc=0
|
local -i loc=0 ret
|
||||||
if [[ -z "${1:-}" ]]; then
|
if [[ -z "${1:-}" ]]; then
|
||||||
echo "Error: no site specified."
|
echo "Error: no site specified."
|
||||||
echo "The site is the name of the directory your project is in."
|
echo "The site is the name of the directory your project is in."
|
||||||
|
|
@ -292,6 +263,7 @@ function deploysite() {
|
||||||
for site in "${SITES[@]}"; do
|
for site in "${SITES[@]}"; do
|
||||||
if [[ "${site##*/}" == "$1" ]]; then
|
if [[ "${site##*/}" == "$1" ]]; then
|
||||||
SITE="$site"
|
SITE="$site"
|
||||||
|
# shellcheck disable=SC2153 # who knows
|
||||||
REMOTE="${REMOTES[loc]}"
|
REMOTE="${REMOTES[loc]}"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
|
@ -303,8 +275,11 @@ function deploysite() {
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
builtin cd "${SITE}" || return
|
pushd "${SITE}" > /dev/null || return
|
||||||
rsync -rz "${REMOTE?}"
|
rsync -rz "${REMOTE?}"
|
||||||
|
ret="$?"
|
||||||
|
popd > /dev/null || return "$ret"
|
||||||
|
return "$ret"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Load the Jekyll config
|
# Load the Jekyll config
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue