Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bake

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bake - npm Package Compare versions

Comparing version 0.0.5 to 0.1.0

.npmignore

130

lib/bake.js

@@ -5,6 +5,6 @@ var fs = require("fs"),

dive = require("dive"),
marked = require("marked");
ejs = require("ejs");
// Main function
var bake = function(dir, hooks) {
var bake = function(confFile, hooks) {

@@ -19,79 +19,103 @@ // File counter

// Load the configuration file
var conf = cjson.load(dir + "/conf/bake.json");
var conf = cjson.load(confFile);
console.log("Successfully loaded configuration file.");
// Set values for `bakeDir` and `tplDir`
var bakeDir = conf.directories.bake || "pub",
tplDir = conf.directories.templates || "tpl";
// Set values for `fileExt`
var fileExt = conf.fileExtensions || { txt: "html" };
var fileExtPattern
= new RegExp("\.(" + Object.keys(fileExt).join("|") + ")$", "i");
// Status log
console.log("\nBeginning to bake " + dir + "\n");
console.log("Beginning to bake " + bakeDir + ".\n");
// Dive into the public directory
dive(dir + "/pub", function(err, file) {
dive(bakeDir, function(err, master) {
// Throw errors
if (err) throw err;
// Match the file's name against markdown file extensions
if (file.match(/\.(mkd|md|markdown)$/i)) {
// Matching variable
var match;
// Match the master-file's name against enabled file extensions
if (match = master.match(fileExtPattern)) {
// Get the file extension of the master file
var masterExt = match[1];
// Increase file counter
++todo;
// Read the file's contents
fs.readFile(file, "utf8", function(err, data) {
// Read the master-file's contents
fs.readFile(master, "utf8", function(err, data) {
// Throw errors
if (err) throw err;
// Get the properties of the file
var p = props(data);
// Get the properties
// `file` is the file specific property object
var file = props(data);
// `global` is the global property object
var global = conf.properties;
// Parse markdown
var content = marked(p.__content);
// Assert that `file.template` is set
if (file.template == undefined)
file.template = global.defaultTemplate || "default";
// Assert p.template is set
if (p.template == undefined)
p.template = conf.defaultTemplate;
// Assert p.author is set
if (p.author == undefined)
p.author = conf.defaultAuthor;
// Read the template file
fs.readFile(dir + "/tpl/" + p.template + ".tpl", "utf8",
function(err, tpl) {
fs.readFile(tplDir + "/" + file.template + ".tpl", "utf8",
function(err, result) {
// Throw errors
if (err) throw err;
// Insert the content
tpl = tpl.replace("{__content}", content);
// For all keys of `global`
for (var key in global)
// If a hook is defined, apply it
if (hooks[key] != undefined)
global[key] = hooks[key](global);
// For all keys of conf.properties in tpl
if (conf.properties != undefined)
for (var key in conf.properties)
// If a hook is defined, apply it
if (hooks[key] != undefined)
tpl = hooks[key](tpl, p, conf.properties);
// Otherwise simply replace the key
else
tpl = tpl.replace(new RegExp("{" + key + "}", "g"),
conf.properties[key]);
// For all keys of `file`
for (var key in file)
// If a hook is defined, apply it
if (hooks[key] != undefined)
file[key] = hooks[key](file);
// For all keys of p in tpl
for (var key in p)
// exept for p.__content
if (key != "__content")
// If a hook is defined, apply it
if (hooks[key] != undefined)
tpl = hooks[key](tpl, p, conf.properties);
// Otherwise simply replace the key
else
tpl = tpl.replace(new RegExp("{" + key + "}", "g"),
p[key]);
// (Pre-)Insert the content (so there may be ejs-tags in
// `file.__content` are parsed, too.
result = result.replace(/<%= +file.__content +%>/g,
file.__content);
// New filename
htmlFile = file.replace(/\.(mkd|md|markdown)$/i, "") + ".html";
// Result's filename
var resultFilename = master.replace(fileExtPattern,
"." + fileExt[masterExt]);
// Export `file` and `global` to locals object for use in the
// template.
var locals = {
file: file,
global: global
};
// Render ejs-template
result = ejs.render(result, { locals: locals });
// Write contents
fs.writeFile(htmlFile, tpl, function(err) {
fs.writeFile(resultFilename, result, function(err) {
// Throw errors
if (err) throw err;
// Log on success
console.log(htmlFile + " written");
if (!--todo)
console.log("Everything has been successfully baked!\n");
// Log status on success
console.log(" " + resultFilename + " written.\n");
// When file counter is zero
if (!--todo) {
if (hooks["__complete"] != undefined)
// Call the completion hook
hooks["__complete"]();
// State final message
console.log("Everything has been successfully baked!");
}
});

@@ -98,0 +122,0 @@ });

{
"name": "bake",
"description": "javascript website bakery for markdown files",
"tags": ["website", "blog", "markdown", "template", "git"],
"version": "0.0.5",
"description": "bakery for static files that supports embedded JS templates",
"tags": [ "ejs", "template" ],
"version": "0.1.0",
"author": "Paul Vorbach <paul@vorb.de> (http://vorb.de)",

@@ -22,4 +22,4 @@ "repository": {

"props": ">=0.0.3",
"marked": ">=0.0.1"
"ejs": ">=0.4.3"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc