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

scripting2Suite.server.buildHomePage

on buildHomePage (username) {
	<<Changes
		<<7/18/10; 8:43:28 PM by DW
			<<Call beforeBuildHomePage callbacks.
		<<7/8/10; 5:27:41 AM by DW
			<<Add a line-break between stories.
		<<6/25/10; 8:25:31 PM by DW
			<<Use our visitReverseChronologic routine to exclude stories that aren't in the chronology.
		<<6/14/10; 7:27:25 AM by DW
			<<The crumbtrail at the top of the page should point to the most recent day. It was using the date of the last save. There might not be an archive page for that day (there isn't now, as I write this).
		<<6/12/10; 8:04:46 AM by DW
			<<On the home page, the most recent day's stories are expanded, all other stories are collapsed.
		<<6/7/10; 9:24:01 PM by DW
			<<Created. 
	local (adrdata = scripting2suite.inituser (username), adrcal = @adrdata^.calendar);
	local (whenLastSave = date (0), htmltext, path = "default.html", mostRecentDay = date (0));
	bundle { //call callbacks, 7/18/10 by DW
		local (adrscript);
		for adrscript in @adrdata^.callbacks.beforeBuildHomePage {
			while typeof (adrscript^) == addresstype {
				adrscript = adrscript^};
			try {adrscript^ (adrdata)}}};
	bundle { //get htmltext
		local (indentlevel = 0, ct = 0);
		htmltext = "\r\r";
		on add (s) {
			htmltext = htmltext + string.filledstring ("\t", indentlevel) + s + "\r\n"};
		on decode (s) {
			return (xml.entitydecode (s, true))};
		on visit (adrstory) {
			local (flExpanded);
			if ct >= adrdata^.prefs.ctStoriesOnHomePage {
				return (false)};
			if mostRecentDay == date (0) { //6/12/10; by DW
				mostRecentDay = adrstory^.postDate};
			flExpanded = date.sameday (adrstory^.postDate, mostRecentDay);
			add (scripting2Suite.server.getStoryText (adrstory, flExpanded, adrdata^.prefs.flDisqusComments));
			add ("<br />"); //7/8/10 by DW
			if adrstory^.whenLastSave > whenLastSave {
				whenLastSave = adrstory^.whenLastSave};
			ct++;
			return (true)};
		scripting2Suite.server.visitReverseChronologic (adrcal, @visit);
		htmltext = scripting2Suite.server.glossarySubstitution (@adrdata^.prefs.glossary, htmltext);
		htmltext = scripting2Suite.server.glossarySubstitution (@scripting2Suite.data.systemGlossary, htmltext)};
	bundle { //run it through the template
		local (t);
		new (tabletype, @t);
		t.whenLastUpdate = whenLastSave;
		t.title = "Home Page";
		scripting2Suite.server.setupMacrosTable (username, @t); //add common elements
		t.crumbTrail = scripting2Suite.server.getCrumbTrail (t.baseurl, mostRecentDay); //6/14/10 by DW
		scripting2Suite.server.getCalendarText (username, whenLastSave, t.baseurl, @t.calendar, @t.nextPrevMonths);
		bundle { //set nextPrev
			t.nextPrev = ""}; //this is the home page boozer, 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;
		scratchpad.t = t;
		htmltext = string.multiplereplaceall (string (adrdata^.prefs.hometemplate), @t, false, "<%", "%>")};
	bundle { //upload it
		return (scripting2Suite.writeStaticFile (username, path, htmltext))}};
bundle { //test code
	webbrowser.openurl (buildHomePage ("davewiner"))}



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.