Monday, November 08, 2010 at 12:05 AM.
system.verbs.builtins.radio.weblog.oldStuff.publishStaticPage
on publishStaticPage (adrblog=radio.weblog.init (), catname=nil, maxDays=nil, maxDate=nil, minDate=nil, flHomePage=true) { <<Changes <<6/28/01; 3:17:17 PM by DW <<Created. <<9/2/01; 11:56:41 PM by JES <<Name change: publishStaticHomePage -> publishStaticPage. <<Only publishes one page -- either the home page, or an archive page. <<Added parameters needed for publishing archive pages. <<Add the responder atts gathered by radio.webserver.gatherAttributes, to the page table, before calling html.buildObject. <<Patch URLs in <a href tags, so that they point to the correct URLs in the static site. <<9/3/01; 6:06:57 PM by JES <<Set pagetable.radioResponder.weblogDay to the value of maxDate. This tells radio.weblog.drawCalendar which day's calendar to render. <<Save the pageTableAddress, if possible, and restore it after rendering the page. This makes this script safe to call from within the website framework context. <<9/3/01; 11:48:22 PM by JES <<Lock a semaphore to make this code non-reentrant. This prevents collisions when rendering pages. <<9/16/01; 8:05:45 PM by JES <<Added code to support the static site stats bug ("staticSiteStatsImage"). It's added to the template, just before the closing body tag. <<10/8/01; 11:10:51 AM by JES <<Removed code which added the staticSiteStats glossary entry to the page when rendering. There is now a macro for this, which will be added to the default templates. <<10/9/01; 12:39:11 PM by JES <<Added support for category rendering. This required some changes to the way image URLs were patched, since the original code was only aware of home pages and archive pages. <<Image URL patching now happens after setting the HTML file path. <<10/9/01; 4:05:15 PM by JES <<Fixed possible infinite loop bug, if the user's category path preference is outside the upstream folder. <<10/17/01; 3:32:37 PM by PBS <<Set and delete page table address for radio.webserver.setTemplate. <<10/29/01; 9:46:16 PM by PBS <<Render the pagetext, then stick it in the pagetable rather than in the page itself in radio.data.website. The page will just be a string -- a macro that get the rendered page text from the page table. <<This way we don't have to run html.processMacros twice on pages. semaphore.lock (this, 3600); local (atts, pc = file.getpathchar ()); radio.webServer.gatherAttributes (user.radio.prefs.wwwfolder, @atts); local (pagetext, archivepagetext, mostrecentday); bundle { //set pagetext local (daytemplate = string (file.readwholefile (atts.dayTemplate))); local (itemtemplate = string (file.readwholefile (atts.itemTemplate))); pagetext = radio.weblog.render (adrblog, dayTemplate, itemTemplate, catname, false, false, maxDays, maxDate, minDate, @atts, true)}; local (htmltext, pagetable); bundle { //render the page into htmltext local (oldPta); try {oldPta = html.getPageTableAddress ()}; local (adrsite = @radio.data.website, adrpage = @radio.data.website.default); <<wp.newtextobject (pagetext, adrpage) //PBS 10/29/01: this is too slow -- make it a string instead table.assign (adrpage, "<%renderedWeblogText%>"); //PBS 10/29/01: this will be replaced from the pagetable when the page is rendered. new (tabletype, @pagetable); new (tabletype, @pagetable.radioResponder); pagetable.renderedWeblogText = pagetext; //PBS 10/29/01: this way the <%renderedWeblogText%> macro will have something to include. pagetable.radioResponder.atts = atts; //9/2/01 JES: needed for cascadingStyleSheet, javaScript, navigator pagetable.radioResponder.adrblog = adrblog; pagetable.radioResponder.flStaticRendering = true; pagetable.radioResponder.flSameMachine = false; pagetable.radioResponder.flImagePatching = true; html.setPageTableAddress (@pagetable); //PBS 10/17/01: radio.webserver.settemplate needs this radio.webserver.settemplate (@atts, true, adrsite); pagetable.title = adrblog^.prefs.title; pagetable.radioResponder.weblogDay = maxDate; //tell radio.weblog.drawCalendar what day we're rendering htmltext = html.buildObject (adrpage, @pagetable); if oldPta != nil { html.setPageTableAddress (oldPta)} else { //PBS 10/17/01: delete dangling pta (they can cause crashes) html.deletePageTableAddress ()}}; local (folder, indexfilename, extension=""); bundle { //set folder, indexfilename, extension local (partialpath = string.replaceall (adrblog^.prefs.homePageFilePath, "/", pc)); if (partialpath beginswith pc) and (user.radio.prefs.wwwfolder endswith pc) { partialpath = string.delete (partialpath, 1, 1)}; folder = file.folderFromPath (user.radio.prefs.wwwfolder + partialpath); indexfilename = file.fileFromPath (user.radio.prefs.wwwfolder + partialpath); if indexfilename contains "." { extension = "." + string.nthField (indexfilename, '.', string.countFields (indexfilename, '.'))}}; local (f); bundle { //set f if catname == nil { //no category if flHomePage { f = folder + indexfilename} else { //archive page local (day, month, year, hour, minute, second); date.get (maxDate, @day, @month, @year, @hour, @minute, @second); f = folder + string.padwithzeros (year, 2) + pc + string.padwithzeros (month, 2) + pc + string.padwithzeros (day, 2) + extension}} else { //render a category local (adrcat = @adrblog^.categories.[catname]); local (fname = adrcat^.filename + extension); f = radio.file.getAbsolutePath (adrblog^.prefs.htmlCategoryFolderPath) + fname}}; bundle { //write out the image files, patch image URLs if defined (pagetable.radioResponder.imagefiles) { local (imagefolder = folder + "images" + pc); local (imagefolderurl); bundle { //get imagefolderurl local (fileurl); imagefolderurl = string.replaceAll (string.delete (imagefolder, 1, sizeOf (user.radio.prefs.wwwfolder)), pc, "/"); fileurl = string.replaceAll (string.delete (f, 1, sizeOf (user.radio.prefs.wwwfolder)), pc, "/"); loop { //pop off matching folder names local (pathpart = string.nthField (imagefolderurl, "/", 1)); if pathpart == string.nthField (fileurl, "/", 1) { imagefolderurl = string.delete (imagefolderurl, 1, sizeOf (pathpart) + 1); fileurl = string.delete (fileurl, 1, sizeOf (pathpart) + 1)} else { break}}; local (reldepth = string.countFields (fileurl, '/') - 1); if reldepth > 0 { imagefolderurl = string.filledString ("../", reldepth) + imagefolderurl}}; local (adrimagefile); for adrimagefile in @pagetable.radioResponder.imagefiles { local (fsource = user.radio.prefs.wwwfolder + nameof (adrimagefile^)); local (fdest = imagefolder + file.filefrompath (fsource)); file.surefilepath (fdest); local (flcopy = true); if file.exists (fdest) { if file.modified (fsource) == file.modified (fdest) { flcopy = false}}; if flcopy { file.copy (fsource, fdest); file.setmodified (fdest, file.modified (fsource)); file.setcreated (fdest, file.created (fsource))}; bundle { //patch the HTML text local (searchfor = "=\"" + adrimagefile^ + "\""); //the url is the value <<local (folderurl) <<bundle //set folderurl <<bundle //this code has latency which can mess up image url patching <<local (adrfolderatts) <<radio.file.getfileattributes (imagefolder, @adrfolderatts) <<folderurl = adrfolderatts^.upstream.url <<if catname == nil //home or archive page <<if flHomePage <<folderurl = "images/" <<else //archive page <<folderurl = "../../images/" <<else //category page << <<local (replacewith = "=\"" + folderurl + file.filefrompath (fsource) + "\"") local (replacewith = "=\"" + imagefolderurl + file.filefrompath (fsource) + "\""); htmltext = string.replaceall (htmltext, searchfor, replacewith, false)}}}}; bundle { //patch link URLs local (staticUrl = "", dynamicUrl = "", uri); <<bundle //get staticUrl <<local (adrupstreamspec, adrfolderatts, adrservercapabilities, partialPath) <<radio.file.getfileattributes (file.folderFromPath (f), @adrfolderatts) <<radio.upstream.getUpstreamSpec (adrfolderatts, @adrupstreamspec) <<adrservercapabilities = radio.upstream.getServerCapabilities (adrupstreamspec) <<bundle //calculate relative path of the weblog, to the user's home folder <<local (upstreamfolder = file.folderFromPath (nameOf (adrupstreamspec^))) <<local (upstreamRelPath = string.mid (upstreamfolder, sizeOf (user.radio.prefs.wwwFolder) + 1, infinity)) <<partialPath = string.popLeading (adrblog^.prefs.homePageFilePath, '/') <<partialPath = string.mid (partialPath, sizeOf (upstreamRelPath) + 1, infinity) <<partialPath = string.popSuffix (partialPath, '/') + "/" <<staticUrl = adrservercapabilities^.yourUpstreamFolderUrl + partialPath bundle { //get dynamicUrl dynamicUrl = "http://" + tcp.dns.getMyDottedId (); if string (user.inetd.config.http.port) != "80" { dynamicUrl = dynamicUrl + ":" + user.inetd.config.http.port}; dynamicUrl = dynamicUrl + "/"}; bundle { //get uri if catname == nil { //home or archive page if flHomePage { uri = "/" + indexfilename} //indexfilename already has the extension else { //archive page local (day, month, year, hour, minute, second); date.get (mostrecentday, @day, @month, @year, @hour, @minute, @second); uri = "/" + string.padwithzeros (year, 2) + "/" + string.padwithzeros (month, 2) + "/" + string.padwithzeros (day, 2) + extension}} else { //category page local (catpath = radio.file.getAbsolutePath (adrblog^.prefs.htmlCategoryFolderPath)); local (upstreamSpecFileName = radio.data.filenames.upstreamFileName); local (nomad = string.popSuffix (catpath, pc) + pc); while not (file.exists (nomad + upstreamSpecFileName)) { nomad = string.delete (nomad, sizeOf (nomad), 1); nomad = string.popSuffix (nomad, pc) + pc; if nomad == user.radio.prefs.wwwFolder { break}; if string.countFields (nomad, pc) <= 1 { //reality check break}}; local (relpath = string.delete (catpath, 1, sizeOf (nomad)) + catname + extension); uri = "/" + string.replaceAll (relpath, pc, "/")}}; htmltext = radio.html.patchLinks (htmltext, staticUrl, dynamicUrl, uri)}; bundle { //write out the HTML file <<bundle //original code <<local (adrmirror) <<for adrmirror in @adrblog^.mirrors <<local (folder = adrmirror^.folder, indexfilename = adrmirror^.indexPageName + adrmirror^.htmlExtension) <<file.writewholefile (folder + indexfilename, htmltext) << <<local (day, month, year, hour, minute, second) <<date.get (mostrecentday, @day, @month, @year, @hour, @minute, @second) <<local (f = folder + string.padwithzeros (year, 2) + pc + string.padwithzeros (month, 2) + pc + string.padwithzeros (day, 2) + adrmirror^.htmlExtension) <<file.surefilepath (f) <<file.writewholefile (f, archivepagehtmltext) file.surefilepath (f); file.writewholefile (f, htmltext)}; semaphore.unlock (this); return (f)}; bundle { //test code <<radio.weblog.publishStaticPage () <<radio.weblog.publishStaticPage (flHomePage:false) radio.weblog.publishStaticPage (catname:"My Interests")}
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.