Add support for multiple Jekyll sites

pull/64/head
Mark Szymanski 2011-06-24 17:49:19 -05:00
parent 56b83c76cb
commit 9ad7964c86
2 changed files with 300 additions and 155 deletions

View File

@ -56,6 +56,13 @@ PREVIEW="less"
[ -s /usr/bin/gloobus-preview ] && PREVIEW="gloobus-preview" [ -s /usr/bin/gloobus-preview ] && PREVIEW="gloobus-preview"
[ -s /Applications/Preview.app ] && PREVIEW="/Applications/Preview.app" [ -s /Applications/Preview.app ] && PREVIEW="/Applications/Preview.app"
# Load all the Jekyll stuff
if [ -e $HOME/.jekyllconfig ]
then
. $HOME/.jekyllconfig
fi
# #
# Custom Help # Custom Help

View File

@ -1,208 +1,346 @@
#!/bin/bash #!/bin/bash
editpost() { editpost() {
builtin cd "$JEKYLL_LOCAL_ROOT/_posts" unset SITE
if [ -z "$1" ]
then
echo "Error: no site specified."
echo "The site is the name of the directory your project is in."
return 1
fi
COUNTER=1 for site in ${SITES[@]}
NUMBER="$RANDOM" do
TMPFILE="/tmp/editpost-$NUMBER" if [ "$(basename $site)" = "$1" ]
then
SITE=$site
break
fi
done
for POST in * if [ -z "$SITE" ]
do then
DATE=`echo $POST | grep -oE "[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}"` echo "No such site."
TITLE=`cat $POST | grep -oE "title: (.+)"` return 1
TITLE=`echo $TITLE | sed 's/title: //'` fi
echo "$COUNTER) $DATE $TITLE" >> "$TMPFILE"
POSTS[$COUNTER]=$POST builtin cd "$SITE/_posts"
COUNTER=`expr $COUNTER + 1`
done COUNTER=1
less $TMPFILE NUMBER="$RANDOM"
read -p "Number of post to edit: " POST_TO_EDIT TMPFILE="/tmp/editpost-$NUMBER"
if [ -z "$EDITOR" ]
then for POST in *
nano "${POSTS[$POST_TO_EDIT]}" do
else DATE=`echo $POST | grep -oE "[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}"`
"$EDITOR" "${POSTS[$POST_TO_EDIT]}" TITLE=`cat $POST | grep -oE "title: (.+)"`
fi TITLE=`echo $TITLE | sed 's/title: //'`
echo "$COUNTER) $DATE $TITLE" >> "$TMPFILE"
POSTS[$COUNTER]=$POST
COUNTER=`expr $COUNTER + 1`
done
less $TMPFILE
read -p "Number of post to edit: " POST_TO_EDIT
if [ -z "$EDITOR" ]
then
nano "${POSTS[$POST_TO_EDIT]}"
else
"$EDITOR" "${POSTS[$POST_TO_EDIT]}"
fi
} }
newpost() { newpost() {
unset SITE
if [ -z "$1" ]
then
echo "Error: no site specified."
echo "The site is the name of the directory your project is in."
return 1
fi
# 'builtin cd' into the local jekyll root if [ -z "$SITE" ]
then
echo "No such site."
return 1
fi
builtin cd "$JEKYLL_LOCAL_ROOT/_posts" loc=0
# Get the date for the new post's filename for site in ${SITES[@]}
do
if [ "$(basename $site)" = "$1" ]
then
SITE=$site
JEKYLL_FORMATTING=${MARKUPS[$loc]}
break
fi
loc=$(($loc+1))
done
FNAME_DATE=$(date "+%Y-%m-%d") # 'builtin cd' into the local jekyll root
# If the user is using markdown formatting, let them choose what type of post they want. Sort of like Tumblr. builtin cd "$SITE/_posts"
OPTIONS="Text Quote Image Audio Video Link" # Get the date for the new post's filename
if [ $JEKYLL_FORMATTING = "markdown" -o $JEKYLL_FORMATTING = "textile" ] FNAME_DATE=$(date "+%Y-%m-%d")
then
select OPTION in $OPTIONS
do
if [[ $OPTION = "Text" ]]
then
POST_TYPE="Text"
break
fi
if [[ $OPTION = "Quote" ]] # If the user is using markdown or textile formatting, let them choose what type of post they want. Sort of like Tumblr.
then
POST_TYPE="Quote"
break
fi
if [[ $OPTION = "Image" ]] OPTIONS="Text Quote Image Audio Video Link"
then
POST_TYPE="Image"
break
fi
if [[ $OPTION = "Audio" ]] if [ $JEKYLL_FORMATTING = "markdown" -o $JEKYLL_FORMATTING = "textile" ]
then then
POST_TYPE="Audio" select OPTION in $OPTIONS
break do
fi if [[ $OPTION = "Text" ]]
then
POST_TYPE="Text"
break
fi
if [[ $OPTION = "Video" ]] if [[ $OPTION = "Quote" ]]
then then
POST_TYPE="Video" POST_TYPE="Quote"
break break
fi fi
if [[ $OPTION = "Link" ]] if [[ $OPTION = "Image" ]]
then then
POST_TYPE="Link" POST_TYPE="Image"
break break
fi fi
done
fi
# Get the title for the new post if [[ $OPTION = "Audio" ]]
then
POST_TYPE="Audio"
break
fi
read -p "Enter title of the new post: " POST_TITLE if [[ $OPTION = "Video" ]]
then
POST_TYPE="Video"
break
fi
# Convert the spaces in the title to hyphens for use in the filename if [[ $OPTION = "Link" ]]
then
POST_TYPE="Link"
break
fi
done
fi
FNAME_POST_TITLE=`echo $POST_TITLE | tr ' ' "-"` # Get the title for the new post
# Now, put it all together for the full filename read -p "Enter title of the new post: " POST_TITLE
FNAME="$FNAME_DATE-$FNAME_POST_TITLE.$JEKYLL_FORMATTING" # Convert the spaces in the title to hyphens for use in the filename
# And, finally, create the actual post file. But we're not done yet... FNAME_POST_TITLE=`echo $POST_TITLE | tr ' ' "-"`
touch "$FNAME" # Now, put it all together for the full filename
# Write a little stuff to the file for the YAML Front Matter FNAME="$FNAME_DATE-$FNAME_POST_TITLE.$JEKYLL_FORMATTING"
echo "---" >> $FNAME # And, finally, create the actual post file. But we're not done yet...
# Now we have to get the date, again. But this time for in the header (YAML Front Matter) of touch "$FNAME"
# the file
YAML_DATE=$(date "+%B %d %Y %X") # Write a little stuff to the file for the YAML Front Matter
# Echo the YAML Formatted date to the post file echo "---" >> $FNAME
echo "date: $YAML_DATE" >> $FNAME # Now we have to get the date, again. But this time for in the header (YAML Front Matter) of
# the file
# Echo the original post title to the YAML Front Matter header YAML_DATE=$(date "+%B %d %Y %X")
echo "title: $POST_TITLE" >> $FNAME # Echo the YAML Formatted date to the post file
# And, now, echo the "post" layout to the YAML Front Matter header echo "date: $YAML_DATE" >> $FNAME
echo "layout: post" >> $FNAME # Echo the original post title to the YAML Front Matter header
# Close the YAML Front Matter Header echo "title: $POST_TITLE" >> $FNAME
echo "---" >> $FNAME # And, now, echo the "post" layout to the YAML Front Matter header
echo >> $FNAME
# Generate template text based on the post type echo "layout: post" >> $FNAME
if [[ $JEKYLL_FORMATTING = "markdown" ]] # Close the YAML Front Matter Header
then
if [[ $POST_TYPE = "Text" ]]
then
true
fi
if [[ $POST_TYPE = "Quote" ]] echo "---" >> $FNAME
then echo >> $FNAME
echo "> Quote" >> $FNAME
echo >> $FNAME
echo "— Author" >> $FNAME
fi
if [[ $POST_TYPE = "Image" ]] # Generate template text based on the post type
then
echo "![Alternate Text](/path/to/image/or/url)" >> $FNAME
fi
if [[ $POST_TYPE = "Audio" ]] if [[ $JEKYLL_FORMATTING = "markdown" ]]
then then
echo "<html><audio src=\"/path/to/audio/file\" controls=\"controls\"></audio></html>" >> $FNAME if [[ $POST_TYPE = "Text" ]]
fi then
true
fi
if [[ $POST_TYPE = "Video" ]] if [[ $POST_TYPE = "Quote" ]]
then then
echo "<html><video src=\"/path/to/video\" controls=\"controls\"></video></html>" >> $FNAME echo "> Quote" >> $FNAME
fi echo >> $FNAME
echo "&mdash; Author" >> $FNAME
fi
if [[ $POST_TYPE = "Link" ]] if [[ $POST_TYPE = "Image" ]]
then then
echo "[link][1]" >> $FNAME echo "![Alternate Text](/path/to/image/or/url)" >> $FNAME
echo >> $FNAME fi
echo "> Quote" >> $FNAME
echo >> $FNAME
echo "[1]: url" >> $FNAME
fi
fi
if [[ $JEKYLL_FORMATTING = "textile" ]] if [[ $POST_TYPE = "Audio" ]]
then then
if [[ $POST_TYPE = "Text" ]] echo "<html><audio src=\"/path/to/audio/file\" controls=\"controls\"></audio></html>" >> $FNAME
then fi
true
fi
if [[ $POST_TYPE = "Quote" ]] if [[ $POST_TYPE = "Video" ]]
then then
echo "bq. Quote" >> $FNAME echo "<html><video src=\"/path/to/video\" controls=\"controls\"></video></html>" >> $FNAME
echo >> $FNAME fi
echo "&mdash; Author" >> $FNAME
fi
if [[ $POST_TYPE = "Image" ]] if [[ $POST_TYPE = "Link" ]]
then then
echo "!url(alt text)" >> $FNAME echo "[link][1]" >> $FNAME
fi echo >> $FNAME
echo "> Quote" >> $FNAME
echo >> $FNAME
echo "[1]: url" >> $FNAME
fi
fi
if [[ $POST_TYPE = "Audio" ]] if [[ $JEKYLL_FORMATTING = "textile" ]]
then then
echo "<html><audio src=\"/path/to/audio/file\" controls=\"controls\"></audio></html>" >> $FNAME if [[ $POST_TYPE = "Text" ]]
fi then
true
fi
if [[ $POST_TYPE = "Video" ]] if [[ $POST_TYPE = "Quote" ]]
then then
echo "<html><video src=\"/path/to/video\" controls=\"controls\"></video></html>" >> $FNAME echo "bq. Quote" >> $FNAME
fi echo >> $FNAME
echo "&mdash; Author" >> $FNAME
fi
if [[ $POST_TYPE = "Link" ]] if [[ $POST_TYPE = "Image" ]]
then then
echo "\"Site\":url" >> $FNAME echo "!url(alt text)" >> $FNAME
echo >> $FNAME fi
echo "bq. Quote" >> $FNAME
fi
fi
# Open the file in your favorite editor if [[ $POST_TYPE = "Audio" ]]
then
echo "<html><audio src=\"/path/to/audio/file\" controls=\"controls\"></audio></html>" >> $FNAME
fi
"$EDITOR" $FNAME if [[ $POST_TYPE = "Video" ]]
then
echo "<html><video src=\"/path/to/video\" controls=\"controls\"></video></html>" >> $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
"$EDITOR" $FNAME
}
function testsite() {
unset SITE
if [ -z "$1" ]
then
echo "Error: no site specified."
echo "The site is the name of the directory your project is in."
return 1
fi
for site in ${SITES[@]}
do
if [ "$(basename $site)" = "$1" ]
then
SITE=$site
break
fi
done
if [ -z "$SITE" ]
then
echo "No such site."
return 1
fi
builtin cd $SITE
jekyll --server --auto
}
function buildsite() {
unset SITE
if [ -z "$1" ]
then
echo "Error: no site specified."
echo "The site is the name of the directory your project is in."
return 1
fi
for site in ${SITES[@]}
do
if [ "$(basename $site)" = "$1" ]
then
SITE=$site
break
fi
done
if [ -z "$SITE" ]
then
echo "No such site."
return 1
fi
builtin cd $SITE
rm -rf _site
jekyll --no-server
}
function deploysite() {
unset SITE
if [ -z "$1" ]
then
echo "Error: no site specified."
echo "The site is the name of the directory your project is in."
return 1
fi
loc=0
for site in ${SITES[@]}
do
if [ "$(basename $site)" = "$1" ]
then
SITE=$site
REMOTE=${REMOTES[$loc]}
break
fi
loc=$(($loc+1))
done
if [ -z "$SITE" ]
then
echo "No such site."
return 1
fi
builtin cd $SITE
rsync -rz $REMOTE
} }