Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function parseHead(str) {
var header;
header = str.split('\n');
header.shift();
header.pop();
header = header.map(function(line) {
if(line.indexOf('date:') > -1) {
return ' date: "'+ line.replace('date: ','') +'"';
}
return ' '+ line;
});
header = header.join('\n');
header = [''].concat('\n'+header).join('---') +'\n';
header = yaml.eval(header);
header = mergeHead(header);
header = JSON.stringify(header, null, 4);
return header;
}
, shortName = res.replace(self.inDir, '');
fileNames.push(shortName);
var template = outPath.replace(self.outDir, '').split('/')[1].split('.')[0]
, group = (shortName.split('/').length == 3) ? 'root' : template
, markdown = fs.readFileSync(res, 'utf8')
, yml = markdown.match(/^-{3}((.|\n)*)-{3}/g)
, defaults = {
title: '',
template: template,
'render-file': true
}
if (yml) {
var props = yaml.eval(yml[0]);
markdown = markdown.replace(/^-{3}((.|\n)*)-{3}/g, '');
defaults = _.defaults(props, defaults);
}
var result = {
inPath: res,
inFile: shortName,
outPath: outPath,
href: href,
prepared: Codex.parseMarkdown(markdown)
};
result = _.merge(defaults, result);
if (result['render-file']) {
self.files.push(result);
exports.extractFrontMatter = function(data) {
var regex = /^(\s*---([\s\S]+)---\s*)/gi
, match = regex.exec(data)
;
if (match && match.length > 0) {
var yamlString = match[2].replace(/^\s+|\s+$/g,'')
, template = data.replace(match[0],'')
, yamlAttributes
;
return {
content: template,
attributes: yaml.eval(yamlString)
};
} else {
return {
content: data,
attributes: {}
}
}
};
parsers.yaml = function(data, callback) {
if (data) {
try {
callback(null, yaml.eval(data));
} catch (err) {
err.message = 'Failed to parse YAML body: ' + err.message;
callback(err, null);
}
} else {
callback(null, null);
}
};
fs.readFile("config.yml", "binary", function(err, file) {
if (err) {
util.puts(err);
};
//util.puts(file.toString());
var output = yaml.eval(file.toString());
TWITTER_CONSUMER_KEY = output["TWITTER_CONSUMER_KEY"];
TWITTER_CONSUMER_SECRET = output["TWITTER_CONSUMER_SECRET"];
});
parsers.yaml = function(data, callback) {
return callback(data && yaml.eval(data));
};
function _handleConfig(file) {
var config
switch(path.extname(file)) {
case 'yml':
config = yaml.eval(fs.readFileSync(file))
break
case 'yaml':
config = yaml.eval(fs.readFileSync(file))
break
case 'json':
config = require(file)
break
}
if (!config.plugins) {
return false
}
var list = []
for (var plugin in config.plugins) {
list.push(plugin)
}
return _requirePlugins(list)
function _handleConfig(file) {
var config
switch(path.extname(file)) {
case 'yml':
config = yaml.eval(fs.readFileSync(file))
break
case 'yaml':
config = yaml.eval(fs.readFileSync(file))
break
case 'json':
config = require(file)
break
}
if (!config.plugins) {
return false
}
var list = []
for (var plugin in config.plugins) {
transform(content, path) {
if (typeof content !== 'string') {
content = content.toString('utf8');
}
const matches = content.match(FRONT_MATTER_REG);
if (!matches) return content;
const meta = yaml.eval('---\n'+matches[1].replace(/^/gm,' ')+'\n') || {};
content = content.replace(FRONT_MATTER_REG, '');
if (!meta.title) {
let [,title] = content.match(TITLE_REG) || [];
if (title) {
content = content.replace(TITLE_REG, '');
meta.title = title;
}
}
content = '---\n' + JSON.stringify(meta) + '\n---\n' + content;
return content;
}
}, {
parsers.yaml = function(data, callback) {
return callback(data && yaml.eval(data));
};