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

system.verbs.builtins.radio.upstream.callbacks.upstream.updateWeblogArchivePages

on updateWeblogArchivePages (filelist) {
	<<Changes
		<<1/8/02; 9:29:17 PM by JES
			<<Pass in false for the value of flCreateFolders, when calling radio.weblog.file.getArchiveFilePath to get the path for an archive file in the previous month. This prevents an empty folder from being created for months which don't exist.
		<<1/5/02; 4:17:02 PM by JES
			<<Created.
			<<If this is a weblog archive page, or a page in a category that has HTML rendering turned on, set whenLastUpload to date(0) for the source file for all archive pages which have links to this page in their calendars, that have not been rendered with a link to this page yet.
			<<This makes sure that archive page calendars are always up-to-date. At most, all the archive pages for the previous month will be rendered, when you make the first post in a new month.
			<<Most of the time, the only file that will be touched is the archive page for yesterday (or the most recent day that contains a post, if there were no posts yesterday). Even this will only happen once, when you make the first post in a new day.
	local (adrblog = radio.weblog.init ());
	local (pc = file.getPathChar ());
	local (f);
	on checkFile (f, minDate) {
		local (adrfile = @user.radio.settings.files.[f]);
		if defined (adrfile^) {
			if adrfile^.upstream.whenLastUploaded < minDate {
				adrfile^.upstream.whenLastUploaded = date (0)}}};
	on checkLinkingFiles (f) {
		local (d);
		if radio.weblog.file.getArchiveFileDate (f, @d) { //note: d is always midnight on the day in question
			local (day, month, year, hour, minute, second);
			date.get (d, @day, @month, @year, @hour, @minute, @second);
			local (catname);
			radio.weblog.file.getCatName (f, @catname, adrblog);
			if radio.weblog.isDateOnHomePage (d, adrblog, catname) {
				local (folder = file.folderFromPath (file.folderFromPath (file.folderFromPath (f))));
				bundle { //check pages in this month
					if day > 1 {
						for i = day - 1 downTo 1 {
							local (fileToCheck = radio.weblog.file.getArchiveFilePath (folder, date.set (i, month, year, 0, 0, 0)));
							checkFile (fileToCheck, d)}}};
				bundle { //check pages in the previous month
					local (firstOfThisMonth = date.set (1, month, year, 0, 0, 0));
					month--;
					if month < 1 {
						month = 12;
						year--};
					local (daysInMonth = date.daysInMonth (date.set (1, month, year, 0, 0, 0)));
					for i = daysInMonth downTo (1) {
						local (fileToCheck = radio.weblog.file.getArchiveFilePath (folder, date.set (i, month, year, 0, 0, 0), false));
						checkFile (fileToCheck, firstOfThisMonth)}}}}};
	for f in filelist {
		if radio.weblog.file.isArchivePage (f) {
			checkLinkingFiles (f)}}};
bundle { //test code
	local (filelist = {});
	filelist = filelist + radio.weblog.file.getArchiveFilePath (user.radio.prefs.wwwFolder, clock.now ());
	filelist = filelist + radio.weblog.file.getArchiveFilePath (radio.weblog.file.getCategoryFolder ("default"), clock.now ());
	updateWeblogArchivePages (filelist)}



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.