home *** CD-ROM | disk | FTP | other *** search
- !!Script
- // Copyright ⌐ 1997-1998 - Modelworks Software
-
- /**
- @Tool: indexHtml~creates an index of a directory of HTML files for
- all anchors with a name property. The results are sent to the Output panel.
- @Tip: To capture the output in a file create an Output file.
- @EndTip:
- @EndTool:
- @Summary: indexHtml~creates an index of a directory
- */
-
- var output = getOutput();
- var nameList = newList();
-
- function getTargetName(name)
- {
- var suffix = name.lastIndexOf("_");
- if (suffix != -1)
- {
- return name.substring(0, suffix);
- }
-
- return name;
- }
-
- // This function is where we analize an anchor tag.
- // If we find a NAME attribute, we add a record to the nameList
-
- function AnalyizeHtmlTag(editorPath, relativePath, fileName, lineIndex, bot)
- {
- var position = bot.getHeadPosition();
- while (position.valid)
- {
- // attribute.key and attribute.value are a Token objects
- var attribute = bot.getNext(position);
- if (attribute)
- {
- if (attribute.key.string.toLowerCase() == "name")
- {
- var value = relativePath + "#" + attribute.value.string;
-
- // Add the same information to the nameList
- var indexEntry = newAssociation();
- indexEntry.key = getTargetName(attribute.value.string);
- indexEntry.value = value;
-
- nameList.addTail(indexEntry);
-
- break;
- }
- }
- }
- }
-
- // The is the comparison function for sorting the list
- function compare(itemA, itemB)
- {
- if (itemA.value < itemB.value)
- return -1;
- if (itemA.value == itemB.value)
- return 0;
-
- return 1;
- }
-
- //
- // Start Script
- //
-
- var directoryPath = chooseDirectory("Choose directory to index");
-
- if (directoryPath)
- {
- var files = getDirectoryFiles(directoryPath, "*.html", true);
- output.clear();
- output.writeLine("Indexing files: ");
- if (files)
- {
- var count = files.getCount();
- var position = files.getHeadPosition();
- while (position.valid)
- {
- var file = files.getNext(position);
-
- output.writeLine("Processing file: " + file.path);
-
- var editor = openEditor(file.path);
- if (editor)
- {
- var findData = editor.findFirst("<a", 0, 0, true, false);
- if (findData)
- {
- while (findData.found)
- {
- var bot = editor.getHtmlTag(findData.range.startLineIndex, findData.range.startCharIndex);
- if (bot)
- {
- var relativePath = editor.getRelativePath(directoryPath);
- AnalyizeHtmlTag(editor.path, relativePath, editor.name,
- findData.range.startLineIndex, bot);
- }
- editor.findNext(findData);
- }
- }
- }
- }
- }
-
- var items = nameList.getCount();
- if (items > 0)
- {
- output.writeLine("Sorting Anchors");
- nameList.sort();
-
- var position = nameList.getHeadPosition();
- while(position.valid)
- {
- var association = nameList.getNext(position);
- var info = association.value;
- var infoIndex = info.indexOf(".");
- if (infoIndex > -1)
- {
- info = info.substring(0, infoIndex);
- }
- output.writeLine("<a href=\"" + association.value + "\">" +
- association.key + "</a> - " + info + "<br>");
- }
- }
- }
-
- output.writeLine("Report completed");
- output.writeLine("Total name anchors: " + nameList.getCount());
-
- !!/Script
-