@ -1,4 +1,4 @@
var myVersion = "0.7 2 a", myProductName = "PagePark" ;
var myVersion = "0.7 3 a", myProductName = "PagePark" ;
/ * T h e M I T L i c e n s e ( M I T )
/ * T h e M I T L i c e n s e ( M I T )
Copyright ( c ) 2014 - 2015 Dave Winer
Copyright ( c ) 2014 - 2015 Dave Winer
@ -32,7 +32,7 @@ var marked = require ("marked");
var dns = require ( "dns" ) ;
var dns = require ( "dns" ) ;
var mime = require ( "mime" ) ; //1/8/15 by DW
var mime = require ( "mime" ) ; //1/8/15 by DW
var utils = require ( "daveutils" ) ; //6/7/17 by DW
var utils = require ( "daveutils" ) ; //6/7/17 by DW
var opml Lib = require ( "daveopml" ) ; //6/7 /17 by DW
var opml ToJs = require ( "opmltojs" ) ; //6/16 /17 by DW
var folderPathFromEnv = process . env . pageparkFolderPath ; //1/3/15 by DW
var folderPathFromEnv = process . env . pageparkFolderPath ; //1/3/15 by DW
@ -43,7 +43,11 @@ var pageparkPrefs = {
flProcessMarkdownFiles : true , extMarkdownFiles : "md" , //5/5/15 by DW
flProcessMarkdownFiles : true , extMarkdownFiles : "md" , //5/5/15 by DW
flProcessOpmlFiles : true , extOpmlFiles : "opml" , //6/23/15 by DW
flProcessOpmlFiles : true , extOpmlFiles : "opml" , //6/23/15 by DW
error404File : "prefs/error.html" , //7/16/15 by DW
error404File : "prefs/error.html" , //7/16/15 by DW
legalPathChars : "" //7/19/15 by DW
legalPathChars : "" , //7/19/15 by DW,
flCacheTemplatesLocally : true , //6/17/17 by DW -- preserve the original behavior
urlDefaultMarkdownTemplate : "http://fargo.io/code/pagepark/defaultmarkdowntemplate.txt" , //6/17/17 by DW
urlDefaultOpmlTemplate : "http://fargo.io/code/pagepark/templates/opml/template.txt" , //6/17/17 by DW
urlDefaultErrorPage : "http://fargo.io/code/pagepark/prefs/error.html" //6/17/17 by DW
} ;
} ;
var fnamePrefs = "prefs/prefs.json" ;
var fnamePrefs = "prefs/prefs.json" ;
@ -60,13 +64,10 @@ var domainsPath = "domains/";
var configFname = "/config.json" ;
var configFname = "/config.json" ;
var mdTemplatePath = "prefs/mdTemplate.txt" ;
var mdTemplatePath = "prefs/mdTemplate.txt" ;
var urlDefaultMarkdownTemplate = "http://fargo.io/code/pagepark/defaultmarkdowntemplate.txt" ;
var opmlTemplatePath = "prefs/opmlTemplate.txt" ;
var opmlTemplatePath = "prefs/opmlTemplate.txt" ;
var urlDefaultOpmlTemplate = "http://fargo.io/code/pagepark/templates/opml/template.txt" ;
var urlDefaultErrorPage = "http://fargo.io/code/pagepark/prefs/error.html" ; //7/16/15 by DW
function httpExt2MIME ( ext ) { //12/24/14 by DW
function httpExt2MIME ( ext ) { //12/24/14 by DW
@ -94,29 +95,38 @@ function getFullFilePath (relpath) { //1/3/15 by DW
return ( folderpath + relpath ) ;
return ( folderpath + relpath ) ;
}
}
function getTemplate ( myTemplatePath , urlDefaultTemplate , callback ) {
function getTemplate ( myTemplatePath , urlDefaultTemplate , callback ) {
var f = getFullFilePath ( myTemplatePath ) ;
if ( pageparkPrefs . flCacheTemplatesLocally ) {
fs . readFile ( f , function ( err , data ) {
var f = getFullFilePath ( myTemplatePath ) ;
if ( err ) {
fs . readFile ( f , function ( err , data ) {
httpReadUrl ( urlDefaultTemplate , function ( s ) {
if ( err ) {
fs . writeFile ( myTemplatePath , s , function ( err ) {
httpReadUrl ( urlDefaultTemplate , function ( s ) {
if ( callback != undefined ) {
fs . writeFile ( myTemplatePath , s , function ( err ) {
callback ( s ) ;
if ( callback != undefined ) {
}
callback ( s ) ;
}
} ) ;
} ) ;
} ) ;
} ) ;
}
}
else {
else {
if ( callback != undefined ) {
callback ( data . toString ( ) ) ;
}
}
} ) ;
}
else {
httpReadUrl ( urlDefaultTemplate , function ( s ) {
if ( callback != undefined ) {
if ( callback != undefined ) {
callback ( data . toString ( ) ) ;
callback ( s ) ;
}
}
}
} ) ;
} ) ;
}
}
}
function getMarkdownTemplate ( callback ) {
function getMarkdownTemplate ( callback ) {
getTemplate ( mdTemplatePath , urlDefaultMarkdownTemplate, callback ) ;
getTemplate ( mdTemplatePath , pageparkPrefs. urlDefaultMarkdownTemplate, callback ) ;
}
}
function getOpmlTemplate ( callback ) { //6/23/15 by DW
function getOpmlTemplate ( callback ) { //6/23/15 by DW
getTemplate ( opmlTemplatePath , urlDefaultOpmlTemplate, callback ) ;
getTemplate ( opmlTemplatePath , pageparkPrefs. urlDefaultOpmlTemplate, callback ) ;
}
}
function checkPathForIllegalChars ( path ) {
function checkPathForIllegalChars ( path ) {
function isIllegal ( ch ) {
function isIllegal ( ch ) {
@ -218,7 +228,7 @@ function handleHttpRequest (httpRequest, httpResponse) {
} ) ;
} ) ;
}
}
function return404 ( ) {
function return404 ( ) {
getTemplate ( pageparkPrefs . error404File , urlDefaultErrorPage, function ( htmtext ) {
getTemplate ( pageparkPrefs . error404File , pageparkPrefs. urlDefaultErrorPage, function ( htmtext ) {
httpResponse . writeHead ( 404 , { "Content-Type" : "text/html" } ) ;
httpResponse . writeHead ( 404 , { "Content-Type" : "text/html" } ) ;
httpResponse . end ( htmtext ) ;
httpResponse . end ( htmtext ) ;
} ) ;
} ) ;
@ -301,12 +311,13 @@ function handleHttpRequest (httpRequest, httpResponse) {
if ( pageparkPrefs . flProcessOpmlFiles && config . flProcessOpmlFiles && flReturnHtml ) { //6/24/15 by DW
if ( pageparkPrefs . flProcessOpmlFiles && config . flProcessOpmlFiles && flReturnHtml ) { //6/24/15 by DW
getOpmlTemplate ( function ( theTemplate ) {
getOpmlTemplate ( function ( theTemplate ) {
var opmltext = data . toString ( ) , pagetable = new Object ( ) ;
var opmltext = data . toString ( ) , pagetable = new Object ( ) ;
opmlLib . readOpmlString ( opmltext , function ( theOutline ) {
opmlToJs . parse ( opmltext , function ( theOutline ) {
pagetable . bodytext = utils . jsonStringify ( theOutline ) ;
var pagetable = {
pagetable . title = utils . stringLastField ( f , "/" ) ;
bodytext : utils . jsonStringify ( theOutline ) ,
var s = utils . multipleReplaceAll ( theTemplate , pagetable , false , "[%" , "%]" ) ;
title : theOutline . opml . head . title
httpResponse . writeHead ( 200 , { "Content-Type" : "text/html" } ) ;
} ;
httpResponse . end ( s ) ;
var htmltext = utils . multipleReplaceAll ( theTemplate , pagetable , false , "[%" , "%]" ) ;
httpReturn ( htmltext , "text/html" ) ;
} ) ;
} ) ;
} ) ;
} ) ;
}
}