Merge pull request #1969 from gaelicWizard/plugin-jekyll

Plugin/jekyll: lint and stuff
pull/2006/head^2
Noah Gorny 2022-01-01 22:43:36 +02:00 committed by GitHub
commit f534505357
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 238 additions and 323 deletions

View File

@ -137,13 +137,6 @@ elif [ -s /Applications/Preview.app ]; then
PREVIEW="/Applications/Preview.app" PREVIEW="/Applications/Preview.app"
fi fi
# Load all the Jekyll stuff
if [ -e "$HOME/.jekyllconfig" ]; then
# shellcheck disable=SC1090
. "$HOME/.jekyllconfig"
fi
# BASH_IT_RELOAD_LEGACY is set. # BASH_IT_RELOAD_LEGACY is set.
if ! _command_exists reload && [[ -n "${BASH_IT_RELOAD_LEGACY:-}" ]]; then if ! _command_exists reload && [[ -n "${BASH_IT_RELOAD_LEGACY:-}" ]]; then
case $OSTYPE in case $OSTYPE in

View File

@ -97,6 +97,7 @@ plugins/available/history-search.plugin.bash
plugins/available/history-substring-search.plugin.bash plugins/available/history-substring-search.plugin.bash
plugins/available/history.plugin.bash plugins/available/history.plugin.bash
plugins/available/hub.plugin.bash plugins/available/hub.plugin.bash
plugins/available/jekyll.plugin.bash
plugins/available/jump.plugin.bash plugins/available/jump.plugin.bash
plugins/available/less-pretty-cat.plugin.bash plugins/available/less-pretty-cat.plugin.bash
plugins/available/node.plugin.bash plugins/available/node.plugin.bash

View File

@ -1,268 +1,185 @@
# shellcheck shell=bash
cite about-plugin cite about-plugin
about-plugin 'manage your jekyll site' about-plugin 'manage your jekyll site'
editpost() { function editpost() {
about 'edit a post' about 'edit a post'
param '1: site directory' param '1: site directory'
group 'jekyll' group 'jekyll'
unset SITE local SITE site POST DATE TITLE POSTS
if [ -z "$1" ] local -i COUNTER=1 POST_TO_EDIT ret
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."
return 1 return 1
fi fi
for site in ${SITES[@]} for site in "${SITES[@]:-}"; do
do if [[ "${site##*/}" == "$1" ]]; then
if [ "${site##*/}" = "$1" ] SITE="${site}"
then
SITE=$site
break break
fi fi
done done
if [ -z "$SITE" ] if [[ -z "${SITE:-}" ]]; then
then
echo "No such site." echo "No such site."
return 1 return 1
fi fi
builtin cd "$SITE/_posts" pushd "${SITE}/_posts" > /dev/null || return
COUNTER=1 for POST in *; do
NUMBER="$RANDOM" DATE="$(echo "${POST}" | grep -oE "[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}")"
TMPFILE="/tmp/editpost-$NUMBER" TITLE="$(grep -oE "title: (.+)" < "${POST}")"
TITLE="${TITLE/title: /}"
for POST in * echo "${COUNTER}) ${DATE} ${TITLE}"
do POSTS[COUNTER]="$POST"
DATE=`echo $POST | grep -oE "[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}"` COUNTER="$((COUNTER + 1))"
TITLE=`cat $POST | grep -oE "title: (.+)"` done > >(less)
TITLE=`echo $TITLE | sed 's/title: //'` read -rp "Number of post to edit: " POST_TO_EDIT
echo "$COUNTER) $DATE $TITLE" >> "$TMPFILE" "${JEKYLL_EDITOR:-${VISUAL:-${EDITOR:-${ALTERNATE_EDITOR:-nano}}}}" "${POSTS[POST_TO_EDIT]}"
POSTS[$COUNTER]=$POST ret="$?"
COUNTER=`expr $COUNTER + 1` popd > /dev/null || return "$ret"
done return "$ret"
less $TMPFILE
read -p "Number of post to edit: " POST_TO_EDIT
if [ -z "$JEKYLL_EDITOR" ]
then
nano "${POSTS[$POST_TO_EDIT]}"
else
"$JEKYLL_EDITOR" "${POSTS[$POST_TO_EDIT]}"
fi
} }
newpost() { function newpost() {
about 'create a new post' about 'create a new post'
param '1: site directory' param '1: site directory'
group 'jekyll' group 'jekyll'
unset SITE local SITE site FNAME_POST_TITLE FNAME YAML_DATE
if [ -z "$1" ] local JEKYLL_FORMATTING FNAME_DATE OPTIONS OPTION POST_TYPE POST_TITLE
then local -i loc=0 ret
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."
return 1 return 1
fi fi
if [ -z "$SITE" ] if [[ -z "${SITE}" ]]; then
then
echo "No such site." echo "No such site."
return 1 return 1
fi fi
loc=0 for site in "${SITES[@]}"; do
if [[ "${site##*/}" == "$1" ]]; then
for site in ${SITES[@]} SITE="$site"
do JEKYLL_FORMATTING="${MARKUPS[loc]}"
if [ "${site##*/}" = "$1" ]
then
SITE=$site
JEKYLL_FORMATTING=${MARKUPS[$loc]}
break break
fi fi
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"
# 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
select OPTION in "${OPTIONS[@]}"; do
if [ $JEKYLL_FORMATTING = "markdown" -o $JEKYLL_FORMATTING = "textile" ] POST_TYPE="${OPTION}"
then
select OPTION in $OPTIONS
do
if [[ $OPTION = "Text" ]]
then
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 -p "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=`echo $POST_TITLE | tr ' ' "-"`
# 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...
{
touch "$FNAME"
# Write a little stuff to the file for the YAML Front Matter # Write a little stuff to the file for the YAML Front Matter
echo "---"
echo "---" >> $FNAME # Now we have to get the date, again. But this time for in the header (YAML Front Matter) of the file
YAML_DATE="$(date "+%B %d %Y %X")"
# Now we have to get the date, again. But this time for in the header (YAML Front Matter) of
# the file
YAML_DATE=$(date "+%B %d %Y %X")
# Echo the YAML Formatted date to the post file # Echo the YAML Formatted date to the post file
echo "date: $YAML_DATE"
echo "date: $YAML_DATE" >> $FNAME
# Echo the original post title to the YAML Front Matter header # Echo the original post title to the YAML Front Matter header
echo "title: $POST_TITLE"
echo "title: $POST_TITLE" >> $FNAME
# And, now, echo the "post" layout to the YAML Front Matter header # And, now, echo the "post" layout to the YAML Front Matter header
echo "layout: post"
echo "layout: post" >> $FNAME
# Close the YAML Front Matter Header # Close the YAML Front Matter Header
echo "---"
echo "---" >> $FNAME echo
echo >> $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" ]] case $POST_TYPE in
then "Text")
if [[ $POST_TYPE = "Text" ]]
then
true true
fi ;;
"Quote")
if [[ $POST_TYPE = "Quote" ]] echo "> Quote"
then echo
echo "> Quote" >> $FNAME echo "&mdash; Author"
echo >> $FNAME ;;
echo "&mdash; Author" >> $FNAME "Image")
fi echo "![Alternate Text](/path/to/image/or/url)"
;;
if [[ $POST_TYPE = "Image" ]] "Audio")
then echo "<html><audio src=\"/path/to/audio/file\" controls=\"controls\"></audio></html>"
echo "![Alternate Text](/path/to/image/or/url)" >> $FNAME ;;
fi "Video")
echo "<html><video src=\"/path/to/video\" controls=\"controls\"></video></html>"
if [[ $POST_TYPE = "Audio" ]] ;;
then "Link")
echo "<html><audio src=\"/path/to/audio/file\" controls=\"controls\"></audio></html>" >> $FNAME echo "[link][1]"
fi echo
echo "> Quote"
if [[ $POST_TYPE = "Video" ]] echo
then echo "[1]: url"
echo "<html><video src=\"/path/to/video\" controls=\"controls\"></video></html>" >> $FNAME ;;
fi esac
elif [[ $JEKYLL_FORMATTING == "textile" ]]; then
if [[ $POST_TYPE = "Link" ]] case $POST_TYPE in
then "Text")
echo "[link][1]" >> $FNAME
echo >> $FNAME
echo "> Quote" >> $FNAME
echo >> $FNAME
echo "[1]: url" >> $FNAME
fi
fi
if [[ $JEKYLL_FORMATTING = "textile" ]]
then
if [[ $POST_TYPE = "Text" ]]
then
true true
fi ;;
"Quote")
if [[ $POST_TYPE = "Quote" ]] echo "bq. Quote"
then echo
echo "bq. Quote" >> $FNAME echo "&mdash; Author"
echo >> $FNAME ;;
echo "&mdash; Author" >> $FNAME "Image")
fi echo "!url(alt text)"
;;
if [[ $POST_TYPE = "Image" ]] "Audio")
then echo "<html><audio src=\"/path/to/audio/file\" controls=\"controls\"></audio></html>"
echo "!url(alt text)" >> $FNAME ;;
fi "Video")
echo "<html><video src=\"/path/to/video\" controls=\"controls\"></video></html>"
if [[ $POST_TYPE = "Audio" ]] ;;
then "Link")
echo "<html><audio src=\"/path/to/audio/file\" controls=\"controls\"></audio></html>" >> $FNAME echo "\"Site\":url"
fi echo
echo "bq. Quote"
if [[ $POST_TYPE = "Video" ]] ;;
then esac
echo "<html><video src=\"/path/to/video\" controls=\"controls\"></video></html>" >> $FNAME fi >> "${FNAME}"
fi
if [[ $POST_TYPE = "Link" ]]
then
echo "\"Site\":url" >> $FNAME
echo >> $FNAME
echo "bq. Quote" >> $FNAME
fi
fi
# Open the file in your favorite editor # Open the file in your favorite editor
"${JEKYLL_EDITOR:-${VISUAL:-${EDITOR:-${ALTERNATE_EDITOR:-nano}}}}" "${FNAME}"
"$JEKYLL_EDITOR" $FNAME ret="$?"
popd > /dev/null || return "$ret"
return "$ret"
} }
function testsite() { function testsite() {
@ -270,31 +187,31 @@ function testsite() {
param '1: site directory' param '1: site directory'
group 'jekyll' group 'jekyll'
unset SITE local SITE site
if [ -z "$1" ] local -i ret
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."
return 1 return 1
fi fi
for site in ${SITES[@]} for site in "${SITES[@]}"; do
do if [[ "${site##*/}" == "$1" ]]; then
if [ "${site##*/}" = "$1" ] SITE="$site"
then
SITE=$site
break break
fi fi
done done
if [ -z "$SITE" ] if [[ -z "${SITE}" ]]; then
then
echo "No such site." echo "No such site."
return 1 return 1
fi fi
builtin cd $SITE pushd "${SITE}" > /dev/null || return
jekyll --server --auto jekyll --server --auto
ret="$?"
popd > /dev/null || return "$ret"
return "$ret"
} }
function buildsite() { function buildsite() {
@ -302,32 +219,32 @@ function buildsite() {
param '1: site directory' param '1: site directory'
group 'jekyll' group 'jekyll'
unset SITE local SITE site
if [ -z "$1" ] local -i ret
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."
return 1 return 1
fi fi
for site in ${SITES[@]} for site in "${SITES[@]}"; do
do if [[ "${site##*/}" == "$1" ]]; then
if [ "${site##*/}" = "$1" ] SITE="$site"
then
SITE=$site
break break
fi fi
done done
if [ -z "$SITE" ] if [[ -z "${SITE}" ]]; then
then
echo "No such site." echo "No such site."
return 1 return 1
fi fi
builtin cd $SITE 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() {
@ -335,33 +252,37 @@ function deploysite() {
param '1: site directory' param '1: site directory'
group 'jekyll' group 'jekyll'
unset SITE local SITE site REMOTE
if [ -z "$1" ] local -i loc=0 ret
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."
return 1 return 1
fi fi
loc=0 for site in "${SITES[@]}"; do
if [[ "${site##*/}" == "$1" ]]; then
for site in ${SITES[@]} SITE="$site"
do # shellcheck disable=SC2153 # who knows
if [ "${site##*/}" = "$1" ] REMOTE="${REMOTES[loc]}"
then
SITE=$site
REMOTE=${REMOTES[$loc]}
break break
fi fi
loc=$(($loc+1)) loc=$((loc + 1))
done done
if [ -z "$SITE" ] if [[ -z "${SITE}" ]]; then
then
echo "No such site." echo "No such site."
return 1 return 1
fi fi
builtin cd $SITE pushd "${SITE}" > /dev/null || return
rsync -rz $REMOTE rsync -rz "${REMOTE?}"
ret="$?"
popd > /dev/null || return "$ret"
return "$ret"
} }
# Load the Jekyll config
if [[ -s "$HOME/.jekyllconfig" ]]; then
source "$HOME/.jekyllconfig"
fi