All that's left is to create the table-of-contents page, consisting of a list of links to the other HTML pages.
Let's plan a strategy for this. How do we want the page to look? We can use the same template we are already using; we'll supply our own "title" and "subtext."
The question is what the "bodytext" should consist of. It should be a series of paragraphs, one for each HTML file we created. Each paragraph should consist of the "title" and "subtitle" for the corresponding HTML file, nicely formatted, and with the "title" being a live link to the HTML file.
This means we're going to have to retain the "title," "subtitle," and "fname" of each HTML file as we process it. So we may as well just accumulate the "bodytext" HTML for the table-of-contents page as we go along. Let's keep it in a string variable, calling it "tocbodytext."
Here is how we might want the finished HTML in "tocbodytext" to look:
<p><b><a href="face_time.html">Face time with
the mini-poser hoo-haws</a></b>.
A very close colleague of mine has a way with
descriptive verbiage.</p>
<p><b><a href="geek_gaugin.html">Where geek meets Gaugin</a></b>.
Content, creativity and computer code
And so on. What's the formula for this? It's:
tocbodytext = tocbodytext + "<p><b><a href = \\"" + fname + "\">" + \
title + "</a></b>. " + cr + subtitle + "</p>" + cr
(Notice that we express doublequotes inside a string by "escaping" them, that is, by saying backslash-doublequote. The backslash won't be present in the actual string; it's just a way of letting Frontier know that we aren't terminating the string yet.) If we just add this to the "fileloop" material somewhere, we'll be building the correct HTML as we go along.
Then, at the end of the whole routine, after the last pass through the "fileloop," we need to process "templatetext," "title," "subtitle," and "tocbodytext" in just the same way as we've been doing for each file, and write the result out as a textfile, which, since it's the table-of-contents page, we may as well call "default.html."
We just need to decide on appropriate "title" and "subtitle" for this last page; let's have the "title" be "Gil Amelio's Opinions," and the subtitle be "Apple CEO Gil Amelio writes about issues of the day."
There is just one further point. Studying the files in "Source Files," we find that some of them have a space at the end of paragraph that we're using as our "title." This will generate an extra space before the period that we're inserting after our use of "title" in "tocbodytext."
Let's handle this in a completely general way; way back in our "popline" handler, we'll remove leading and trailing spaces from the result before we hand it out. There are Frontier verbs to help us with this, string.popLeading and string.popTrailing.
Here, then, is our whole routine as modified to generate a table-of-contents page at the end. And one final touch: let's bring up the About Window so we can see our progress.
local (folder)
if not file.getFolderDialog ("Where is the AmelioWeb folder?", @folder) {return}
window.about ()
local (templatetext = string (file.readWholeFile (folder + "template.html")))
templatetext = string.replaceAll (templatetext, cr + lf, cr)
local (infolder = folder + "Source Files" + file.getPathChar ())
local (outfolder = folder + "Website" + file.getPathChar ())
file.sureFolder (outfolder)
file.emptyFolder (outfolder)
local (infile, filetext, title, subtitle, tocbodytext = "")
on popline()
local (s)
s = string.NthField (filetext, cr, 1)
filetext = string.delete (filetext, 1, sizeOf (s) + 1)
s = string.popLeading (s, ' ')
s = string.popTrailing (s, ' ')
return (s)
fileloop (infile in infolder)
local (fname = file.filefrompath (infile))
msg (fname)
if file.isFolder (infile)
file.copy (infile, outfolder + fname)
else
filetext = string (file.readWholeFile (infile))
filetext = string.replaceAll (filetext, cr + lf, cr)
fname = string.replace (fname, ".txt", ".html")
outfile = outfolder + fname
title = popline (); popline (); popline (); popline ()
subtitle = popline (); popline ()
local (s = templatetext)
s = string.replaceAll (s, "<<title>>", title)
s = string.replaceAll (s, "<<subtitle>>", subtitle)
s = string.replaceAll (s, "<<bodytext>>", filetext)
local (adrTable = @websites.["#data"])
html.data.adrPageTable = adrTable
adrTable^.activeURLs = true
adrTable^.clayCompatibility = false
adrTable^.autoParagraphs = true
s = html.processMacros (s)
file.writeWholeFile (outfile, s, 'TEXT', 'MSIE', clock.now ())
webbrowser.openDocument (outfile)
tocbodytext = tocbodytext + "<p><b><a href = \\"" + fname + "\">" + \
title + "</a></b>. " + cr + subtitle + "</p>" + cr
title = "Gil Amelio's Opinions"
subtitle ="Apple CEO Gil Amelio writes about issues of the day."
local (s = templatetext)
s = string.replaceAll (s, "<<title>>", title)
s = string.replaceAll (s, "<<subtitle>>", subtitle)
s = string.replaceAll (s, "<<bodytext>>", tocbodytext)
local (adrTable = @websites.["#data"])
html.data.adrPageTable = adrTable
adrTable^.activeURLs = true
adrTable^.clayCompatibility = false
adrTable^.autoParagraphs = true
s = html.processMacros (s)
file.writeWholeFile (outfolder + "default.html", s, 'TEXT', 'MSIE', clock.now ())
webbrowser.openDocument (outfolder + "default.html")
Run this. The results are excellent!