Permalink
Browse files

Copying content from old SVN repository

  • Loading branch information...
TehShrike committed May 6, 2012
1 parent afdb09a commit c91ee844b55f9cb2cfe809b9b3666536ba8cc9e7
Showing with 1,888 additions and 0 deletions.
  1. +1,332 −0 Markdown.Converter.js
  2. +142 −0 cache.js
  3. +5 −0 config.js
  4. +15 −0 extension.js
  5. +41 −0 file.js
  6. BIN file/Awesome.png
  7. BIN file/conan.jpg
  8. +39 −0 html.js
  9. +2 −0 html/header.html
  10. +18 −0 html/index.html
  11. +13 −0 html/no-menu.html
  12. +180 −0 index.js
  13. +65 −0 post.js
  14. +7 −0 post/first111.md
  15. +17 −0 post/index.md
  16. +12 −0 post/second.md
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
142 cache.js
@@ -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;
}
}
}
View
@@ -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 }
View
@@ -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();
}
}
}
View
41 file.js
@@ -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);
}
}
View
BIN +57.5 KB file/Awesome.png
Binary file not shown.
View
BIN +12 KB file/conan.jpg
Binary file not shown.
View
39 html.js
@@ -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 || "");
});
}
View
@@ -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>
View
@@ -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>
View
@@ -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.

0 comments on commit c91ee84

Please sign in to comment.