-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copying content from old SVN repository
- Loading branch information
Showing
16 changed files
with
1,888 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
var path = require('path'); | ||
var fs = require("fs"); | ||
|
||
exports.getCache = function(directory, encoding, expiration) | ||
{ | ||
var encoding = encoding || "binary"; | ||
var expiration = expiration || false; | ||
var storage = {} | ||
|
||
var updateFileExistence = function(file_name) | ||
{ | ||
if (!file_name) | ||
return; | ||
|
||
var full_path = path.join(process.cwd(), directory, file_name); | ||
|
||
path.exists(full_path, function(exists) | ||
{ | ||
if (exists) | ||
{ | ||
storage[file_name] = {}; | ||
storage[file_name].loading = false; | ||
|
||
if (expiration === false) | ||
loadFile(file_name); | ||
} | ||
else | ||
{ | ||
//console.log(full_path + " does not exist"); | ||
delete storage[file_name]; | ||
} | ||
}); | ||
} | ||
|
||
var resetExpirationCounter = function(file_name) | ||
{ | ||
if (storage[file_name]) | ||
{ | ||
if (storage[file_name].timeout_id) | ||
{ | ||
clearTimeout(storage[file_name].timeout_id); | ||
delete storage[file_name].timeout_id; | ||
} | ||
|
||
if (expiration > 0) | ||
{ | ||
//console.log("Expiring " + file_name + " in " + (expiration * 1000)); | ||
storage[file_name].timeout_id = setTimeout(function() | ||
{ | ||
//console.log(file_name + " expired"); | ||
if (storage[file_name] && storage[file_name].data) | ||
{ | ||
delete storage[file_name].data; | ||
delete storage[file_name].timeout_id; | ||
} | ||
}, expiration * 1000); | ||
} | ||
} | ||
} | ||
|
||
var loadFile = function(file_name, callback) | ||
{ | ||
if (!file_name) | ||
return; | ||
|
||
if (storage[file_name] && storage[file_name].loading) | ||
{ | ||
storage[file_name].callbacks.push(callback); | ||
return; | ||
} | ||
|
||
var full_path = path.join(process.cwd(), directory, file_name); | ||
storage[file_name] = {}; | ||
storage[file_name].loading = true; | ||
storage[file_name].callbacks = [callback]; | ||
|
||
//console.log("Attempting to read file " + file_name); | ||
|
||
fs.readFile(full_path, encoding, function(err, data) | ||
{ | ||
if (!err) | ||
{ | ||
if (expiration === false || expiration > 0) | ||
{ | ||
//console.log("Caching " + file_name); | ||
storage[file_name].data = data; | ||
if (expiration > 0) | ||
resetExpirationCounter(file_name); | ||
} | ||
} | ||
else | ||
{ | ||
data = false; | ||
//console.log("Unable to read " + full_path + " I guess"); | ||
} | ||
|
||
storage[file_name].loading = false; | ||
var callback; | ||
while (callback = storage[file_name].callbacks.shift()) | ||
{ | ||
//console.log("Calling a callback on load of " + file_name); | ||
callback(data); | ||
} | ||
}); | ||
|
||
} | ||
|
||
fs.readdir(path.join(process.cwd(), directory), function(err, files) | ||
{ | ||
if (!err) | ||
{ | ||
for (i in files) | ||
{ | ||
updateFileExistence(files[i]); | ||
} | ||
} | ||
}); | ||
|
||
fs.watch(directory, { persistant: false }, function(event, file_name) | ||
{ | ||
updateFileExistence(file_name); | ||
}); | ||
|
||
return { | ||
getFile: function(file_name, callback) | ||
{ | ||
if (!storage[file_name]) | ||
callback(false); | ||
else if (storage[file_name].data) | ||
{ | ||
callback(storage[file_name].data); | ||
resetExpirationCounter(file_name); | ||
} | ||
else | ||
loadFile(file_name, callback); | ||
}, | ||
getCurrentCache: function() | ||
{ | ||
return storage; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
exports.extensions = {file: './file.js', post: './post.js', html: './html.js'} | ||
|
||
exports.post = { file_suffix: ".md" } | ||
|
||
exports.html = { file_suffix: ".html", cache_expiration: false } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
exports.loaded_extensions = {}; | ||
|
||
exports.loadExtensions = function(extensions_to_load) | ||
{ | ||
for (var extension_name in extensions_to_load) | ||
{ | ||
exports.loaded_extensions[extension_name] = require(extensions_to_load[extension_name]); | ||
|
||
for (var extension in exports.loaded_extensions[extension_name]) | ||
{ | ||
if (extension.load) | ||
extension.load(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
var path = require('path'); | ||
|
||
exports.handleRequest = function(noddity_url, response, send404) | ||
{ | ||
if (noddity_url.path) | ||
{ | ||
var local_path = path.join(process.cwd(), "file", path.normalize(noddity_url.path)); | ||
|
||
path.exists(local_path, function(exists) | ||
{ | ||
if (exists) | ||
{ | ||
require("fs").readFile(local_path, "binary", function(err, file) | ||
{ | ||
if(err) | ||
{ | ||
response.writeHeader(500, {"Content-Type": "text/plain"}); | ||
response.write(err + "\n"); | ||
response.end(); | ||
} | ||
else | ||
{ | ||
response.writeHeader(200); | ||
response.write(file, "binary"); | ||
response.end(); | ||
} | ||
}); | ||
} | ||
else | ||
{ | ||
console.log(local_path + " does not exist, sending 404"); | ||
send404(response); | ||
} | ||
}); | ||
} | ||
else | ||
{ | ||
console.log("No noddity_url.path, sending 404"); | ||
send404(response); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
var cache = require('./cache.js').getCache('html', 'utf8', false); | ||
var config = require('./config.js'); | ||
|
||
// Tries to find a filename that matches: html_file specified in content metadata, extension name, slug name, index | ||
exports.provideBaseOutput = function(page, callback) | ||
{ | ||
var suffix = config.html.file_suffix; | ||
|
||
cache.getFile(page.metadata.html_file + suffix, function(output) | ||
{ | ||
if (output !== false) | ||
callback(output); | ||
else | ||
cache.getFile(page.url.extension + suffix, function(output) | ||
{ | ||
if (output !== false) | ||
callback(output); | ||
else | ||
cache.getFile(page.url.slug + suffix, function(output) | ||
{ | ||
if (output !== false) | ||
callback(output) | ||
else | ||
cache.getFile('index' + suffix, function(output) | ||
{ | ||
callback(output || "No HTML file found"); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
exports.provideReplaceable = function(page, parameter, callback) | ||
{ | ||
cache.getFile(parameter + config.html.file_suffix, function(output) | ||
{ | ||
callback(output || ""); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<img src="../file/awesome.png" height=100px/> | ||
<h1>Welcome to my awesome site! This is the header, and it goes everywhere!</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<html> | ||
<head> | ||
<title> | ||
{?post:metadata:title} | ||
</title> | ||
</head> | ||
<body> | ||
{?html:header} | ||
<div id="content"> | ||
{?content_html} | ||
</div> | ||
<div id="menu"> | ||
<div id="posts"> | ||
{?post:last5} | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<html> | ||
<head> | ||
<title> | ||
{?content:title} | ||
</title> | ||
</head> | ||
<body> | ||
{?html:header} | ||
<div id="content"> | ||
{?content} | ||
</div> | ||
</body> | ||
</html> |
Oops, something went wrong.