The future is bright…

Every now and again I get really excited about something. My heart gave a little flutter just now when I read this article because, in a nutshell, that’s what I’ve been trying to do for the last couple of years. Proper web-based applications. Websites that Do Things.

So the fact that this stuff is now beginning to really hit the world in a big way is quite exciting. The cutting edge is quite a nice place to be.

I’m in love…

With an Apache extension. Don’t worry, it’s nothing to do with Native American Indians and the amazing results available through spam emails. It’s the wonderful mod_rewrite extension, available at all good website hosting companies. It really is wonderful, and you may be seeing a lot more of it very near here in the not too distant future.

However, as is my way, I may be trying to go beyond my abilities too soon. Which is fine, as long as it’s not for an important client, and as long as the site doesn’t crash (see the “Don’t rush it” entry below).

Actually, I was talking about that entry with the inamorata the other day, and she described me as “unconciously incompetant”. It must be love.

Don’t rush it…

Just don’t. Ever.

Good grief, that’s been a frightening few days. And all because I rushed something on Tuesday night that wasn’t that urgent after all. Now, who’s going to place bets that this (finally) teaches me a lesson. 200-1, I reckon.

But it does give me a good excuse to post my first proper code example. This one is classic ASP (VBScript), and is very useful when you need to hard-write a lot of files with only minor changes such as the title, keywords, description and a bit of page content between them. You can always see it in action as well, if you want. Oh, and one more thing, this (and any code peovided on this blog) is given without any guarantees or warranty whatsoever.

' all you need to do to that is create your html template and replace some
' of the elements in it with the codified equivalents. here's a list:
' page title = %%pagetitle%%
' meta keywords = %%pagekeywords%%
' meta description = %%pagedescription%%
' page content = %%pagecontent%%
' level (string of ../'s to the root, for image paths etc) = %%lev%%

' grab the template file
templatepath = "template.htm"
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath(templatepath), 1)
bodytext = f.readall
f.Close
Set f=Nothing
Set fs=Nothing

' this is the function that is called to create the final HTML code
function getBody(bodytext,pagetitle,pagekeywords,pagedescription,lev,pagecontent)
getbody = bodytext
getbody = "" & vbcrlf & getbody
getbody = replace(getbody,"%%pagetitle%%",pagetitle)
getbody = replace(getbody,"%%pagekeywords%%",pagekeywords)
getbody = replace(getbody,"%%pagedescription%%",pagedescription)
getbody = replace(getbody,"%%lev%%",lev)
getbody = replace(getbody,"%%pagecontent%%",pagecontent)
end function

' start your loop (from a database, for example)
' for each item create the HTML and save the file like this:
set fs=Server.CreateObject("Scripting.FileSystemObject")
set tfile=fs.CreateTextFile(server.mappath("path/to/your/file.html"))
tfile.Write getBody(bodytext,"Page title","keywords","description","../../../","This is the page content")
tfile.close
set tfile=nothing
set fs=nothing
' go to the next item
%>

How could I ever survive……

Without undelete tools? That’s the second time in as many days that I’ve deleted something important with … less care than I should have had. But, in my defence, I rarely make mistakes like that.

It’s all the other mistakes I make that are the real problem.

Perhaps this says something about humans in general. When we think we’re pretty good at something, that’s when we get lax. Start cutting corners, acting quickly without care or thought. And, obviously, that’s when the errors occur. Now with an inexperienced user this could be forgive, but for someone who is meant to be good at this stuff, oh dear. Now, deep breath and…

Undelete