From d4d20f09540ff738a3f6a3da511bdd16a6c18708 Mon Sep 17 00:00:00 2001 From: Dave Winer Date: Sat, 27 Jun 2015 10:15:47 -0400 Subject: [PATCH] v0.63 --- README.md | 8 ++++++++ pagepark.js | 35 ++++++++++++++++++++++------------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index e9ec3e5..1cac6fa 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,14 @@ There will always be more work to do here. ;-) #### Updates +##### v0.63 6/27/15 by DW + +If you add ?format=json to a request for an OPML file, you'll get a JSON representation of the outline. This is useful for single-page JavaScript apps that want to use the outlineBrowser toolkit to diplay the contents. An example of this is davewiner.com. + +I figured out how to write a JS page that's served by PagePark that returns the JSON representation of any OPML file. Here's a gist containing the code. And a call to that page. + +In both cases, the CORS header allows access from anywhere. + ##### v0.62 6/25/15 by DW Code cleanup and factoring in opml.js. diff --git a/pagepark.js b/pagepark.js index 827e934..21945f2 100644 --- a/pagepark.js +++ b/pagepark.js @@ -1,4 +1,4 @@ -var myVersion = "0.62d", myProductName = "PagePark"; +var myVersion = "0.63a", myProductName = "PagePark"; //The MIT License (MIT) @@ -310,21 +310,30 @@ function handleHttpRequest (httpRequest, httpResponse) { } break; case config.extOpmlFiles: //6/23/15 by DW - var flReturnHtml = (!hasAcceptHeader ("text/x-opml")) && (formatParam != "opml"); - if (pageparkPrefs.flProcessOpmlFiles && config.flProcessOpmlFiles && flReturnHtml) { //6/24/15 by DW - getOpmlTemplate (function (theTemplate) { - var opmltext = data.toString (), pagetable = new Object (); - opmlLib.readOpmlString (opmltext, function (theOutline) { - pagetable.bodytext = utils.jsonStringify (theOutline); - pagetable.title = utils.stringLastField (f, "/"); - var s = utils.multipleReplaceAll (theTemplate, pagetable, false, "[%", "%]"); - httpResponse.writeHead (200, {"Content-Type": "text/html"}); - httpResponse.end (s); - }); + var opmltext = data.toString (); + if (formatParam == "json") { + opmlLib.readOpmlString (opmltext, function (theOutline) { + httpResponse.writeHead (200, {"Content-Type": "application/json", "Access-Control-Allow-Origin": "*"}); + httpResponse.end (utils.jsonStringify (theOutline)); }); } else { - defaultReturn ("text/xml", data); + var flReturnHtml = (!hasAcceptHeader ("text/x-opml")) && (formatParam != "opml"); + if (pageparkPrefs.flProcessOpmlFiles && config.flProcessOpmlFiles && flReturnHtml) { //6/24/15 by DW + getOpmlTemplate (function (theTemplate) { + var pagetable = new Object (); + opmlLib.readOpmlString (opmltext, function (theOutline) { + pagetable.bodytext = utils.jsonStringify (theOutline); + pagetable.title = utils.stringLastField (f, "/"); + var s = utils.multipleReplaceAll (theTemplate, pagetable, false, "[%", "%]"); + httpResponse.writeHead (200, {"Content-Type": "text/html"}); + httpResponse.end (s); + }); + }); + } + else { + defaultReturn ("text/xml", data); + } } break; default: