Monday, November 08, 2010 at 12:03 AM.
system.verbs.builtins.html.buildGlossary
on buildGlossary (adrGlossary = table.getCursorAddress (), flinteract = false, adrFilterScript = nil) {
<<10/9/98; 7:28:39 AM by DW
<<added filter callback script, to allow custom glossary builders for specific websites
<<I needed this to convert the Scripting News site to run dynamically.
<<if there's an error, we display a dialog...
<<asking if the user wants to edit the object, or continue building the glossary
<<if flinteract is true, show the addresses of tables we add thru msg.
<<Thu, Jan 14, 1999 at 4:25:18 PM by PBS
<<If an object has a . character in its name, don't convert the dot to a /.
<<This allows for pages whose names contain their file suffix.
<<The same fix was made to html.addPageToGlossary.
local (name = nameOf (adrGlossary^));
if (string.lower (name) != "glossary") and (string.lower (name) != "#glossary") {
scriptError ("Can't build the glossary because \"" + name + "\" is not named #glossary or glossary.")};
local (ctAdded = 0);
local (flquit = false); //if true, we unwind recusion
on visit (adrtable) {
local (i, ct = sizeof (adrtable^), adritem, type, title, stringstrip, path, pagetable);
for i = 1 to ct {
if flquit { //unwind recursion
return};
adritem = @adrtable^ [i];
if html.traversalSkip (adritem) {
continue};
type = typeOf (adritem^);
if type == tableType {
if not defined (adritem^.["#glossary"]) { //don't dive into tables that already have glossaries
visit (adritem)}}
else {
new (tabletype, @pagetable);
try {
case type { //we only preflight outlines and wptexts
wptextType {
html.runDirectives (string (adritem^), @pagetable)};
outlineType {
local (outlinecopy = adritem^);
html.runOutlineDirectives (@outlinecopy, @pagetable)}}
else {
continue}}
else {
local (s = "Error processing " + nameof (adritem^) + ": \"" + tryError + "\"");
if dialog.twoWay (s, "Continue", "Edit") { //user chose Continue
continue}
else { //user chose Edit
edit (adritem);
flquit = true;
return}};
html.buildPageTable (adritem, @pagetable); //for file extension
if adrFilterScript != nil { //10/9/98; 8:11:51 AM by DW
if not adrFilterScript^ (adritem, @pagetable) {
continue}};
if flinteract {
msg (adritem)};
stringstrip = (string (siteroot) - "root.") + ".";
local (name = nameOf (pageTable.adrObject^)); //PBS 1/14/99
path = string (adritem) - stringstrip;
path = string.replaceall (path, "[\"", "");
path = string.replaceall (path, "\"]", "");
path = string.mid (path, 1, sizeOf (path) - sizeOf (name)); //PBS 1/14/99
path = string.replaceall (path, ".", "/");
path = path + name; //PBS 1/14/99
local (adrsubtable = @adrGlossary^.[pagetable.title]);
new (tableType, adrsubtable);
adrsubtable^.linetext = pagetable.title;
adrsubtable^.path = path + html.getPref ("fileExtension", @pagetable);
if flinteract {
msg (adritem)};
ctAdded++}};
return (true)};
local (basetable = parentOf (adrGlossary^)); //the objects that get added to the glossary
local (siteroot);
bundle { //set the siteroot to the root of the site, relative to the ftpsite.
local (nomad = basetable);
loop {
if defined (nomad^.["#ftpsite"]) {
siteroot = nomad;
break};
try { //see if the #ftpsite is in a #prefs table
if defined (nomad^.["#prefs"].ftpsite) or defined (nomad^.prefs.["#ftpsite"]) {
siteroot = nomad;
break}};
nomad = parentOf (nomad^);
if (nomad == @root) or (nomad == "") {
siteroot = parentOf (adrGlossary^);
break}}};
if flinteract {
if not dialog.confirm ("Rebuild \"" + adrGlossary + "?") {
return}};
visit (basetable);
if flinteract {
dialog.notify (ctAdded + " glossary entries added.")};
return (true)}
This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.