Archive

Posts Tagged ‘macintosh’

iWeb Correction Script – A shellscript for OSX

August 7th, 2010 No comments

I wrote this for use by a client who uses iWeb. It does a number of things, the most important being that it sets the site to use the domain root (or whatever folder you dump it into) instead of being in a Website_Files folder that gets redirected to.

It also renames the Welcome/Home/whatever the frontpage is called.html to index.html, lowercases all page file names, and appropriately makes changes in feed.xml and all html files to reflect the changes.

Finally, it adds meta keywords and descriptions (which you need to edit into the script for your site).

This is my first time dealing with OSX in this respect, so if you want to improve it go ahead…let me know if you would, please. I don’t own a mac, but I made this on a mac so that the client could use it…It works, even if it’s not entirely elegant. (I’m a linux guy – if it was GNU bash it would be a lot nicer code!).

To use, publish your iWeb site into a folder, copy corrector.sh into said folder, and DO NOT EXECUTE THE SCRIPT FROM FINDER. Open a terminal, cd into the location of the iweb files/folders and corrector, and run sh corrector.sh from the command line. From there it does all the work, then you just upload everything to your host.

#/bin/sh

echo "iWeb corrector - put the site in the domain root!"
echo "Fully free and opensource software by ilikenwf, (C) 2010"
echo "http://www.ilikenwf.com"
echo "FOR USE ON THE OSX O/S ONLY!"
echo "-------------------------------------------------------"
echo " "
echo "Please type the name of the site folder (case sensitive): "

read sitefolder

echo " "
echo "Please enter the name of your front/main page, like Welcome or Home (case sensitive): "

read index

rm ./index.html
rm ./assets*

mv ./"$sitefolder"/* ./
rm -rf ./"$sitefolder"

rm ./index.html

mv ./"$index".html ./index.html

for i in *.html
    do
        mv $i `echo $i | tr [:upper:] [:lower:]`;
        sed -i "" -e s/"$i"/`echo $i | tr [:upper:] [:lower:]`/g *.html
        sed -i "" -e s/"$i"/`echo $i | tr [:upper:] [:lower:]`/g feed.xml
    done

sed -i "" -e s/"$index"\.html/index\.html/g *.html
sed -i "" -e s/"$index"\.html/index\.html/g feed.xml

# Metatags - edit the text in between the "" for description
# and keywords, respectively.
# Using perl here because OSX's sed command
# Doesn't play nice when inserting newlines
# When you do this, make sure to escape special characters like commas
# eg "keyword1\, keyword2\,"
perl -pi -w -e 's/UTF\-8\"\ \/\>/UTF\-8\"\ \/\> \n \<meta name\=\"description\" content\=\"DESCRIPTION HERE\, MAKE SURE TO ESCAPE APPROPRIATE CHARS\" \/\> \n \</meta><meta name\=\"keywords\" content\=\"KEYWORDS\, HERE\, ESCAPE\, ALL\, COMMAS\,\" \/\>/g;' *.html

Categories: Useful Scripts Tags: , , , , , , ,