![]() |
| 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"
{TopicsDirectory(@indices^.topic,"ALL")}
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):
keywords wherescripttutorials.indexsite.p03addkeywords
BuildTitleAlphaIndextutorialtutorials.indexsite.p06buildindexalphaClearPageFromIndex
tutorials.indexsite.p09tipsTitleAlphaDirectory
tutorials.indexsite.p07showdiralphaTopicsDirectory
tutorials.indexsite.p05showdir
objectNotFoundHandlertutorials.indexsite.p11authorsite index
building blockssummarytutorials.indexsite.p01buildingBlockskeywords
tutorials.indexsite.p03addkeywordsplanning
tutorials.indexsite.p02theplantools
tutorials.indexsite.p01buildingBlockstutorials.indexsite.index
tutorials.indexsite.p08summarytutorials.indexsite.p08summary
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:
AddOneItem()
And finally, add the following nested script just above the case visitPhase block:
on AddOneItem()
local
pageAdr = itemAdr^
pageTbl = html.getPageTableAddress()
pageUrl = html.getPath( pageTbl^.adrObject, pageAdr, pageTbl )
pageTitle
if ( typeOf( pageAdr^ ) == tableType )
pageTitle = html.getOneDirective( "title", html.data.standardMacros.renderObject( pageAdr^ ) )
else
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):
keywords wherescriptAdd Keywords
BuildTitleAlphaIndextutorialBuild the Alphabetical IndexClearPageFromIndex
Hints and TipsTitleAlphaDirectory
Display The Alphabetical DirectoryTopicsDirectory
Display The Keyword Directory
objectNotFoundHandlerAbout the Authorsite index
building blockssummaryBricks and Mortarkeywords
Add Keywordsplanning
Plan the Projecttools
Bricks and MortarIndexing a Website
SummarySummary
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.