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

scripting2Suite.oldstuff.buildStories

on buildStories (username, adrday) {
	<<Changes
		<<5/29/10; 8:55:02 PM by DW
			<<Build all the stories for the indictated user for the indicated day.
			<<Adapted from scriptingNewsSuite.renderOutline. 
		<<11/18/03; 8:36:11 PM by DW
			<<If there is no outline, and no opml, then instead of creating a new empty outline, just return the empty string.
			<<The rendering code wants a created attribute on every line. Very reasonable thing to want. So we would have to syntesize one for the empty headline in the outline. Why should we? The intention is to render the outline. We know how to render a non-existent outline, it's just the empty string.
		<<11/16/03; 4:36:23 PM by DW
			<<Total rewrite to not use the CMS to render. 
			<<I want more control over what gets generated. 
			<<And I don't want to go through the <rules> routine every day.
			<<And I don't want to make the users do it. Simplify.
		<<11/10/03; 7:03:43 PM by DW
			<<Undo the fixup by three hours. I changed the script on my desktop to stamp each entry with Pacific time, not Eastern time.
		<<10/30/03; 8:36:27 AM by DW
			<<If there is no opml, just create an empty outline.
		<<10/29/03; 10:35:23 AM by DW
			<<Subtract three hours from the created attributes on top-level headlines, so that the permalinks on Scripting News, which is rendered in California match up with the archive, which is is Massachusetts.
		<<10/29/03; 8:35:39 AM by DW
			<<Created.
	local (adrsystemdata = scripting2suite.init (), now = clock.now (), fldebug = true);
	local (adrdata = scripting2suite.initUser (username), baseurl);
	bundle { //set baseurl
		if not adrdata^.prefs.ftp.enabled {
			baseurl = adrsystemdata^.prefs.baseurl + username + "/"}
		else {
			baseurl = adrdata^.prefs.ftp.url}};
	local (arrowPermalinkImg = string (scripting2Suite.data.html.arrowPermalinkImg));
	local (sharpPermalinkImg = string (scripting2Suite.data.html.sharpPermalinkImg));
	local (htmltext = "", indentlevel = 0);
	on add (s) {
		htmltext = htmltext + string.filledstring ("\t", indentlevel) + s + "\r\n"};
	on hassubs (adrx) { //return true if the outline node has sub-outlines
		local (adr);
		for adr in adrx {
			if nameof (adr^) endswith "outline" { //contains at least one sub
				return (true)}};
		return (false)};
	on getfilename (title) { //turn a title into a filename
		local (fname = title, i, ch);
		for i = sizeof (fname) downto 1 {
			ch = fname [i];
			if (not string.isalpha (ch)) and (not string.isnumeric (ch)) and (ch != ' ') {
				fname = string.delete (fname, i, 1)}};
		fname = string.innerCaseName (fname);
		bundle { //limit length, 3/23/07 by DW
			local (maxlen = adrsystemdata^.prefs.maxFileNameLength - sizeof (".html"));
			if sizeof (fname) > maxlen {
				fname = string.mid (fname, 1, maxlen)}};
		return (fname)};
	if not defined (adrday^.xstruct) {
		xml.compile (adrday^.opml, @adrday^.xstruct)};
	local (adropml = xml.getaddress (@adrday^.xstruct, "opml"));
	local (adrbody = xml.getaddress (adropml, "body"), adrtoplevelhead);
	for adrtoplevelhead in adrbody {
		local (adratts = @adrtoplevelhead^.["/atts"]);
		if defined (adratts^) {
			local (linetext = xml.entitydecode (adratts^.text, true));
			if hassubs (adrtoplevelhead) {
				if not (linetext contains "<rules") {
					local (fname = getfilename (linetext), urlstory, postdate);
					bundle { //set postdate
						if defined (adratts^.created) {
							postdate = date (adratts^.created)}
						else {
							postdate = mainresponder.calendar.getaddressday (adrday)}};
					bundle { //set urlstory
						urlstory = baseurl + "stories/" + file.getdatepath ("/", postdate) + fname + ".html"};
					add ("<a name=\"" + fname + "\"></a><p><b>" + linetext + "</b> <a href=\"" + urlstory + "\">" + arrowPermalinkImg + "</a></p>");
					local (adr, storytext = "");
					bundle { //add #title, #postdate
						storytext = storytext + "#title \"" + linetext + "\"\r";
						storytext = storytext + "#postDate \"" + postdate + "\"\r"};
					for adr in adrtoplevelhead {
						if nameof (adr^) endswith "outline" {
							local (s = xml.entitydecode (adr^.["/atts"].text, true));
							storytext = storytext + s + "\r";
							add ("<p>" + s + "</p>")}};
					bundle { //save story in website structure, build it
						local (adrwebsiteday = mainresponder.calendar.getdayaddress (@adrdata^.website, postdate));
						local (adrstory = @adrwebsiteday^.[fname]);
						wp.newtextobject (storytext, adrstory);
						adrdata^.website.["#prefs"].whenLastUpdate = now;
						adrdata^.website.["#prefs"].username = username;
						thread.callscript (@scripting2Suite.buildStoryPage, {username, adrstory})}}}}};
			<<else
				<<try
					<<local (label = "When:" + string.replaceall (date.timestring (date (adratts^.created)), " ", ""))
					<<local (itemurl = permanentUrl + "#" + label)
					<<local (permalink = "<a href=\"" + itemurl + "\">" + sharpPermalinkImg + "</a>")
					<<add ("<p><a name=\"" + label + "\"></a>" + linetext + " " + permalink + "</p>")
				<<else
					<<add ("<p>" + linetext + " " + "</p>")
	adrday^.body = htmltext;
	return (htmltext)};
bundle { //test code
	adrday = @system.temp.scripting2.davewiner.calendar.["2010"].["05"].["28"];
	scripting2Suite.initArchiveDay (adrday);
	s = buildstories ("davewiner", adrday)}



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.