|Frontier Tutorials / Indexing a Website / Display The Keyword Directory|
To get the information out of the index and onto a page, we need to create a macro.
The Indexer Suite contains several example macros, which are useful as demonstrations, but they aren't complete. Still, we can copy one of them as the starting point for our own macro.
So let's create the TopicsDirectory macro in the #tools table. We'll start with an example script from the Indexer Suite, then modify it to get the display we want.
Copy indexer.examples.IndexToHtml to your #tools table, and rename it "TopicsDirectory". Don't forget to change the name of the eponymous script, as well.
Create a page named "Topics" at the top level of your website, with the following content:
#title "Topics Index"
Render the "Topics" page. You should get a hierarchical display of ODB addresses; it will resemble the following (yours will, of course, have your own keywords and addresses in it, not mine):
The leaf-level items are the ODB addresses of the indexed pages. The items above them are the keywords specified for the leaf pages.
So now we're halfway there: we have the display structure. View the page source; you'll see that it uses <blockquote> to create the indented blocks. Other techniques are, of course, possible; we'll look at some of them later.
The Indexer Suite function that makes this happen is Indexer.VisitIndexExt.
VisitIndexExt walks the specified index table, and calls a user-provided callback function for each entry in the index table that corresponds to the specified keyword(s). The callback function is supposed to do whatever processing is needed, and should not produce a return value.
VisitIndexExt expects the callback function to accept the following parameters:
Open the TopicsDirectory script again. Notice that it has a case visitPhase block to handle the different visit phases:
Now we will modify the TopicsDirectory macro to replace the plain address string in each entry with a link to the page, using the page title as the link text.
Open up the TopicsDirectory macro. Double-click the first summit to collapse it, then double-click again to expand it one level.
Expand the line that begins "on VisitCBFuncExt".
Expand the line that reads "case visitPhase", then the line that reads "item".
Locate the line that reads:
Add( nameOf( itemAdr^ ) + "<br>\r" )
Replace it with:
And finally, add the following nested script just above the case visitPhase block:
pageAdr = itemAdr^
pageTbl = html.getPageTableAddress()
pageUrl = html.getPath( pageTbl^.adrObject, pageAdr, pageTbl )
if ( typeOf( pageAdr^ ) == tableType )
pageTitle = html.getOneDirective( "title", html.data.standardMacros.renderObject( pageAdr^ ) )
pageTitle = html.getOneDirective( "title", string( pageAdr^ ) )
Add( "<a href='" + pageUrl + "'>" + pageTitle + "</a><br>\r" )
Using a nested AddOneItem script to generate the information block for each entry makes it easy to modify the script to display the entry in a different way.
Notice that we've dereferenced itemAdr to get the actual image entry address. The indexer.visit verbs call the callback function with the address of the index entry, not the address of whatever is being indexed.
Render the "Topics" page again. You should get a hierarchical display of page titles linked to the pages; it will resemble the following (yours will, of course, have your own keywords and titles in it, not mine):
keywordswherescriptBuildTitleAlphaIndextutorialobjectNotFoundHandlerbuilding blocksIndexing a WebsitesummarySummary
Voila--a single-page keyword directory of the entire website. It wastes quite a bit of screen real-estate; we'll look at how to improve its display later.