adding code to each HTML page

General discussion on the Generation of HTML Web Pages
Post Reply
daj
Posts: 23
Joined: Sat May 09, 2009 5:23 pm
Location: Glasgow, UK

adding code to each HTML page

Post by daj » Thu May 14, 2009 3:45 pm

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&#39t 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

User avatar
Warwick Wilson
Site Admin
Posts: 495
Joined: Sat Nov 15, 2008 12:36 am
Contact:

Post by Warwick Wilson » Thu May 14, 2009 4:14 pm

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).

daj
Posts: 23
Joined: Sat May 09, 2009 5:23 pm
Location: Glasgow, UK

Post by daj » Thu May 14, 2009 4:21 pm

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&#39t 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&#39s 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

daj
Posts: 23
Joined: Sat May 09, 2009 5:23 pm
Location: Glasgow, UK

Post by daj » Thu May 14, 2009 4:43 pm

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 &#39s|</body>|MYCODEHERE</body>|g&#39 $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

User avatar
Warwick Wilson
Site Admin
Posts: 495
Joined: Sat Nov 15, 2008 12:36 am
Contact:

Post by Warwick Wilson » Thu May 14, 2009 5:20 pm

correct, grep cannot do a replace. This (sed) works:

Navigate to the HTMLFiles_01 directory in your shell terminal then type:

sed -i .bak &#39s/<\/body>/<bold>hello kitty<\/bold><\/body>/g&#39 *

[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 = &#39s/findText/ReplaceText/g&#39
g refers to all occurences, not sure what the s is for.

... Surely someone has coded this into a text editor GUI somewhere.
Last edited by Warwick Wilson on Thu May 14, 2009 8:01 pm, edited 3 times in total.

daj
Posts: 23
Joined: Sat May 09, 2009 5:23 pm
Location: Glasgow, UK

Post by daj » Thu May 14, 2009 5:33 pm

I found a GUI -- yipee

Smultron is my new friend

It&#39s open source too, so no cash had to change hands ;-)

I&#39m up and running and tracking activity

User avatar
Warwick Wilson
Site Admin
Posts: 495
Joined: Sat Nov 15, 2008 12:36 am
Contact:

Post by Warwick Wilson » Sun Jun 07, 2009 3:21 pm

Oh.. this from the Enhancements request fora, JEdit may also be a good free solution here:

http://ifamilyforleopard.com/forums/viewtopic.php?t=403

hib
Posts: 31
Joined: Sun Oct 19, 2008 1:14 pm

Post by hib » Fri Jun 26, 2009 12:29 am

daj wrote:I found a GUI -- yipee

Smultron is my new friend

It&#39s open source too, so no cash had to change hands ;-)

I&#39m 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.
Al

Post Reply