Page 1 of 1
adding code to each HTML page
Posted: Thu May 14, 2009 3:45 pm
by daj
Does anyone have an idea on how I can quickly add some HTML code to every page generated by iFamily?
I would like to know statistics about my website; things like the most popular pages, sources, time spent on the site, etc.
There are plenty of tools available to track this however they all require a small piece of HTML on each page.
iFamily doesn't appear to allow you to customize the default HTML page (does it?), so I wonder if anyone knows of a tool that would go through every page and add the same piece of code before I upload the pages. At the moment i have over 500 pages and I am sure that will grow, so doing it manually is not an option
thanks
Posted: Thu May 14, 2009 4:14 pm
by Warwick Wilson
Using a "find and replace in files" from a text editor, you will be able to search for.
</body>
(or </html>)
and replace it with
[your code]
</body>
in all files contained in the /HTMLFiles/ directory. This becomes trickier if you want an different identifier in each file.
Is this applicable to your case and does anyone know a batching text editor. (to avoid using grep, which may also work).
Posted: Thu May 14, 2009 4:21 pm
by daj
Warwick Wilson wrote:Using a "find and replace in files" from a text editor, you will be able to search for.
Yes, but there lies my problem -- I can't source a find and replace tool which works on multiple files. I am all googled out!
Warwick Wilson wrote:This becomes trickier if you want an different identifier in each file.
No, it's the same small piece of code.
I had a look behind the scenes in the package contents of iFamily to see if there was a template HTML file, but alas nothing
Thanks
Posted: Thu May 14, 2009 4:43 pm
by daj
I think I have cracked it.
grep only finds as far as I remember, but then sed popped into my head, after Warwick mentioned grep
So I think this should do the job
Code: Select all
for i in $(find . -type f); do sed 's|</body>|MYCODEHERE</body>|g' $i > $i-tmp; mv $i $i-backup; mv $i-tmp $i; done
The annoying thing about sed is that you need to output the result to a tempfile and then rename it back
If anyone has a smarter way, then it would be much appreciated
Posted: Thu May 14, 2009 5:20 pm
by Warwick Wilson
correct, grep cannot do a replace. This (sed) works:
Navigate to the HTMLFiles_01 directory in your shell terminal then type:
sed -i .bak 's/<\/body>/<bold>hello kitty<\/bold><\/body>/g' *
[remember to use the escape character whenever you have a slash.]
* refers to all files in the current directory
"-i .bak" changes it in place in the file, and creates a backup with a .bak extension.
in quote syntax = 's/findText/ReplaceText/g'
g refers to all occurences, not sure what the s is for.
... Surely someone has coded this into a text editor GUI somewhere.
Posted: Thu May 14, 2009 5:33 pm
by daj
I found a GUI -- yipee
Smultron is my new friend
It's open source too, so no cash had to change hands
I'm up and running and tracking activity
Posted: Sun Jun 07, 2009 3:21 pm
by Warwick Wilson
Oh.. this from the Enhancements request fora, JEdit may also be a good free solution here:
http://ifamilyforleopard.com/forums/viewtopic.php?t=403
Posted: Fri Jun 26, 2009 12:29 am
by hib
daj wrote:I found a GUI -- yipee
Smultron is my new friend
It's open source too, so no cash had to change hands
I'm up and running and tracking activity
Text Wrangler and its commercial bigger brother, BBEdit, are also great programs for doing search and replace within files and across file groups with or without using regular expressions.