Created
October 31, 2011 22:44
-
-
Save mkaito/1329280 to your computer and use it in GitHub Desktop.
Jekyllator blog post snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function slugify() { | |
[[ -z "$1" ]] && return 65; | |
s=`echo $1 | sed -e 's/\s\{1,\}/ /g' | sed 's/^[ \t]*//;s/[ \t]*$//g' | sed 's/ /-/g' | tr '[A-Z]' '[a-z]'`; | |
debug "1: $s"; | |
typeset -A accents; # key value key value... | |
accents=( 'á' 'a' 'à' 'a' 'â' 'a' 'ä' 'a' 'ã' 'a' | |
'é' 'e' 'è' 'e' 'ê' 'e' 'ë' 'e' | |
'í' 'i' 'ì' 'i' 'î' 'i' 'ï' 'i' | |
'ó' 'o' 'ò' 'o' 'ô' 'o' 'ö' 'o' 'õ' 'o' | |
'ú' 'u' 'ù' 'u' 'û' 'u' 'ü' 'u' | |
'ç' 'c' 'ñ' 'n') | |
for k in ${(k)accents}; do; | |
debug "Replacing $k with ${accents[$k]}"; | |
s=`echo $s | sed -e "s/${k}/${accents[$k]}/g"`; | |
done; | |
s=`echo $1 | sed -e 's/[^A-Za-z0-9]/-/g' | tr -s '-'` | |
debug "2: $s"; | |
echo "$s"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function confirm() | |
{ | |
echo -n "$@ [y/N] " | |
read answer | |
for response in y Y yes YES Yes Sure sure SURE OK ok Ok kk; do | |
[[ "_$answer" == "_$response" ]] && return 0 | |
done | |
return 1 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if egrep 'published' $ppath > /dev/null; then | |
mv $ppath "${POSTS_PATH}/${pubstr}" | |
sed -i 's/published:\sfalse/published: true/' "${POSTS_PATH}/${pubstr}" | |
else | |
gawk 'NR>1 && $ppath=="---" {printf"published: true\n"}{print}' $ppath > "${POSTS_PATH}/${pubstr}" | |
rm $ppath | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment