Monday, November 08, 2010 at 12:00 AM.

scripting2Suite.server.buildTableOfContents

on buildTableOfContents (username) {
	<<Changes
		<<6/9/10; 5:40:24 AM by DW
			<<Make it reverse-chronologic for years, but chronologic within each year. Before it was strictly chronologic.
		<<6/3/10; 2:51:41 PM by DW
			<<Created. 
	local (adrdata = scripting2suite.inituser (username), htmltext = "\r\r", now = clock.now (), path = "toc.html");
	bundle { //update stats, 6/27/10 by DW
		adrdata^.stats.ctTocBuilds++;
		adrdata^.stats.whenLastTocBuild = now};
	bundle { //get htmltext
		local (startdate = adrdata^.prefs.archiveStartDate, startyear = date.year (startdate), floneyear = false);
		local (enddate = mainresponder.calendar.getLastDay (@adrdata^.calendar), endyear = date.year (enddate));
		local (indentlevel = 0, adryear, adrmonth, adrday, adrstory);
		on add (s) {
			htmltext = htmltext + string.filledstring ("\t", indentlevel) + s + "\r\n"};
		on addyear (year, startmonth, endmonth) {
			local (m, url);
			add ("<li class=\"tocYear\"><a name=\"y" + year + "\"></a>" + year + "</li><ul>"); indentlevel++;
			for m = startmonth to endmonth {
				url = year + "/" + string.padwithzeros (m, 2) + ".html";
				add ("<li class=\"tocMonth\"><a href=\"" + url + "\">" + date.monthtostring (m) + "</a></li>"); indentlevel++};
			add ("</ul>"); indentlevel--};
		on getmonth (d) {
			local (day, month, year, hour, minute, second);
			date.get (d, @day, @month, @year, @hour, @minute, @second);
			return (month)};
		add ("<ul>"); indentlevel++;
		bundle { //do the last year
			if startyear != endyear { //more than one year
				addyear (endyear, 1, getmonth (enddate))}};
		bundle { //do the middle years
			local (year);
			for year = endyear-1 downto startyear+1 {
				addyear (year, 1, 12)}};
		bundle { //do the first year
			if startyear == endyear { //special case
				addyear (startyear, getmonth (startdate), getmonth (enddate));
				floneyear = true}
			else {
				addyear (startyear, getmonth (startdate), 12)}};
		add ("</ul>"); indentlevel--};
		<<bundle //old code
			<<for adryear in @adrdata^.calendar
				<<add ("<li>" + nameof (adryear^) + "</li><ul>"); indentlevel++
				<<for adrmonth in adryear
					<<add ("<li>" + date.monthtostring (number (nameof (adrmonth^))) + "</li><ol>"); indentlevel++
					<<for adrday in adrmonth
						<<for adrstory in adrday
							<<add ("<li><a href=\"" + adrstory^.url + "\">" + adrstory^.title + "</a></li>")
					<<add ("</ol>"); indentlevel--
				<<add ("</ul>"); indentlevel--
			<<add ("</ul>"); indentlevel--
			<<webbrowser.displaytext (htmltext)
	bundle { //run it through the template
		local (t);
		new (tabletype, @t);
		t.whenLastUpdate = now;
		t.title = "Table of Contents";
		scripting2Suite.server.setupMacrosTable (username, @t); //add common elements
		scripting2Suite.server.getCalendarText (username, now, t.baseurl, @t.calendar, @t.nextPrevMonths);
		bundle { //set nextPrev
			t.nextPrev = ""}; //this is the toc betsy, it has no peer
		bundle { //do simple replacements on the blogroll, 6/7/10 by DW
			local (tsmall);
			new (tabletype, @tsmall);
			tsmall.calendar = t.calendar;
			tsmall.nextPrevMonths = t.nextPrevMonths;
			t.blogroll = string.multiplereplaceall (t.blogroll, @tsmall, false, "<%", "%>")};
		t.bodytext = htmltext;
		htmltext = string.multiplereplaceall (string (adrdata^.prefs.hometemplate), @t, false, "<%", "%>")};
	bundle { //upload it, return url
		return (scripting2Suite.writeStaticFile (username, path, htmltext))}};
bundle { //test code
	webbrowser.openurl (buildTableOfContents ("arikia"))}



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.