Monday, November 08, 2010 at 12:03 AM.
system.verbs.builtins.html.utilities.buildMCF
on buildMCF (folder, url, f, sitename, author=user.name, org=user.organization, email=user.mailaddress, filter=@defaultFilter) {
<<Wed, Dec 25, 1996 at 8:08:38 AM by DW
<<Derived from Jim Correia's MCFGenerator suite.
<<I'll list changes I make on the change notes page.
<<Thu, Dec 26, 1996 at 9:57:32 PM by JimC
<<removed remaning dependencies on MCFGenerator suite - uses the 4.2 html.getOneTagValue
<<incorporated Guha's suggestions about the generated MCF
<<added the email parameter
<<added the filter paramter ( gives users more control over what files are included in the mcf )
<<this is the default filter - only includes .html files in the resulting mcf
on defaultFilter(f) {
if file.isFolder(f) {
return true};
if ( f endsWith ".html" ) {
msg (file.fileFromPath (f));
return true};
return false};
<<this is the filter that is used if someone passes in nil - everything is included
on nilFilter(f) {
msg (file.fileFromPath (f));
return true};
<<this function does all the work
on generateFileStructureMCF (baseFolder,outputFile,siteURL,siteName,authorName="",orgName="",mailAddress="",fileFilter) {
local {
mcfText = ""};
if ( ! (siteURL endsWith "/" ) ) {
siteURL = siteURL + "/"};
<<utility methods
on add(s) {
mcfText = mcfText + s + cr};
on addAuthor() {
<<if (authorName!="")
<<add("author_individual_name: \"" + authorName + "\"")
if ((authorName!="")&&(mailAddress!="")) {
add("authorIndividual: #\"" + mailAddress + "\"")}};
on addOrganization() {
<<if (orgName!="")
<<add("author_organization_name: \"" + orgName + "\"")
if (orgName!="") {
add("authorOrganization: #\"" + orgName + "\"")}};
on addFileInfo(f) {
add("firstPublicationDate: \"" + date.shortString(file.created(f)) + "\"");
add("lastRevisionDate: \"" + date.shortString(file.modified(f)) + "\"");
add("size: \"" + file.size(f) + "\"")};
bundle { <<add the file header information
<<add("begin-headers:\rMCFVersion: 1.0\rname: \"" + siteName + "\"\rend-headers:")
add(";This MCF File was generated by Userland Frontier 4.2 Mac -" + clock.now());
<<add(";Script by Jim Correia <pmth02jc@umassd.edu> and Dave Winer <dwiner@well.com>.")
add("");
add("begin-headers:");
add("MCFVersion: 1.0");
add("name: \"" + siteName + "\"");
add("typeOf: #\"TableOfContents\"");
add("tocOf: \"" + siteURL + "\"");
add("end-headers:");
add("");
bundle { << add an author tag
if ((authorName!="")&&(mailAddress!="")) {
add("unit: \"" + mailAddress + "\"");
add("name: \"" + authorName + "\"");
add("typeOf: #\"person\"");
add("emailAddress: \"" + mailAddress + "\"");
add("")}};
bundle { << add an organization tag
if (orgName!="") {
add("unit: \"" + orgName + "\"");
add("name: \"" + orgName + "\"");
add("typeOf:#\"Organization\"");
add("")}}};
on ProcessFolder(theFolder,parentgenls="",topmostfolder=false) {
rollBeachBall();
local ( genls="" );
if ( topmostfolder==false ) {
genls = string(theFolder) - string(baseFolder);
<<genls = string.replaceAll(genls,":","/") - "/"
genls = string.replaceAll(genls,":","/");
<<genls = (siteURL - "http://") + (genls) + ".mco"
genls = (siteURL - "http://") + (genls);
add( "unit: \"" + genls + "\"");
add( "name: \"" + ( file.fileFromPath(theFolder) - ":") + "\"");
add( "typeOf: #\"SubjectCategory\"" );
addAuthor();
addOrganization();
if ( parentgenls!="" ) {
<<add( "genls: \"" + parentgenls + "\"")
add( "parent: #\"" + parentgenls + "\"")};
add("")};
local ( f );
fileloop( f in theFolder ) {
if ( fileFilter^(f) ) {
if ( file.isFolder(f) ) {
ProcessFolder(f,genls)}
else {
ProcessFile(f,genls)}}}};
on ProcessFile(theFile,thegenls) {
<<if ( ! (theFile endsWith ".html") )
<<return
<<moved into the default filters
rollBeachBall();
local ( s );
s = theFile - baseFolder;
s = string.replaceAll(s,":","/");
add( "unit: \"" + siteURL + s + "\"");
local ( theTitle = html.getOneTagValue( string(file.readWholeFile(f)), "title") );
if ( theTitle == "" ) {
theTitle = file.fileFromPath(f)};
add( "name: \"" + theTitle + "\"");
addAuthor();
addOrganization();
addFileInfo(f);
if ( thegenls!="" ) {
<<add( "genls: \"" + thegenls + "\"")
add( "parent: #\"" + thegenls + "\"")};
add("")};
ProcessFolder(baseFolder,"",true);
msg ("Writing file...");
file.writeWholeFile(outputFile, mcfText, 'TEXT', 'R*ch', clock.now());
msg ("");
return true};
if ( filter == nil ) {
filter = @nilFilter};
return (generateFileStructureMCF (folder, f, url, sitename, author, org, email, filter))}
<<bundle <<test code
<<local (folder = "internal:apps:webstar:frontier:")
<<local (url = "http://www.scripting.com/frontier/")
<<local (f = folder + "siteMap.mcf")
<<buildMCF (folder, url, f, "Frontier")
<<bundle <<Êmore test code
<<html.utilities.buildMCF ("Touch of Grey:WebSite:", "http://tango.mth.umassd.edu/correia/", "Touch of Grey:WebSite:root.mcf", "JimC")
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.