Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
utils.readFilesFromDirSync(POSTS_PATH, (filename, content) => {
count++
let post = yamlFront.loadFront(content)
post.html = md.render(post['__content'])
delete post['__content']
// console.log(post)
if (post['draft']) {
return
}
try {
let excerpt = EXCERPT_REGEX.exec(post.html)
if (excerpt) {
post.excerpt = excerpt[1]
} else {
post.excerpt = post.html
post.full = true
}
postIndex.push(Object.assign({}, post))
delete post.excerpt
if (isBinaryFileSync(name)) {
return fs.readFileSync(name) // return buffer
}
const template = fs.readFileSync(name, 'utf-8')
// custom template inheritance via yaml front matter.
// ---
// extend: 'source-file'
// replace: !!js/regexp /some-regex/
// OR
// replace:
// - !!js/regexp /foo/
// - !!js/regexp /bar/
// ---
const yaml = require('yaml-front-matter')
const parsed = yaml.loadFront(template)
const content = parsed.__content
let finalTemplate = content.trim() + `\n`
if (parsed.when) {
finalTemplate = (
`<%_ if (${parsed.when}) { _%>` +
finalTemplate +
`<%_ } _%>`
)
// use ejs.render to test the conditional expression
// if evaluated to falsy value, return early to avoid extra cost for extend expression
const result = ejs.render(finalTemplate, data, ejsOptions)
if (!result) {
return ''
}
const processFile = function(filename, width, content) {
const _basename = path.basename(filename, path.extname(filename));
const contents = fs.readFileSync(filename, {encoding: 'utf-8'});
const _metadata = yaml.loadFront(contents);
// If width is truthy (is defined and and is not 0).
if (width) {
// Max of WIDTH chars snapped to word boundaries, trim whitespace
const truncateOptions = {
length: width,
separator: /\s/,
omission: ' …',
};
_metadata.preview = truncate(_metadata['__content'].trim(),
truncateOptions);
}
// If the option is provided keep the entire content in field 'content'
if (typeof(content) != 'undefined') {
_metadata['content'] = _metadata['__content'];
if (isBinaryFileSync(name)) {
return fs.readFileSync(name) // return buffer
}
const template = fs.readFileSync(name, 'utf-8')
// custom template inheritance via yaml front matter.
// ---
// extend: 'source-file'
// replace: !!js/regexp /some-regex/
// OR
// replace:
// - !!js/regexp /foo/
// - !!js/regexp /bar/
// ---
const yaml = require('yaml-front-matter')
const parsed = yaml.loadFront(template)
const content = parsed.__content
let finalTemplate = content.trim() + '\n'
if (parsed.when) {
finalTemplate = (
`<%_ if (${parsed.when}) { _%>` +
finalTemplate +
'<%_ } _%>'
)
// use ejs.render to test the conditional expression
// if evaluated to falsy value, return early to avoid extra cost for extend expression
const result = ejs.render(finalTemplate, data, ejsOptions)
if (!result) {
return ''
}
public getSlidePosition(editor:TextEditor){
let start = new vscode.Position(0, 0);
let end = editor.selection.active;
let range = new vscode.Range(start, end);
let text = editor.document.getText(range);
var frontConfig = front.loadFront(text);
let content = frontConfig.__content;
let position = this.getSlideCount(content) - 1;
let regex = new RegExp(this.config.slidifyOptions.separator, "gm");
let slides = text.split(regex);
let currentSlide = slides[slides.length-1];
let innerSlide = this.getInnerSlideCount(currentSlide);
return `#/${position}/${innerSlide}`;
}
function parseMarkdownFile(filepath, markdownIt) {
const fileContent = fs.readFileSync(filepath, 'utf8')
let entity = {}
try {
entity = yamlFront.loadFront(fileContent)
} catch (e) {
console.log(`${filepath} : compilation of front-matter failed for file 😱`)
throw e
}
try {
entity.__html = markdownIt.render(entity.__content)
delete entity.__content
} catch (e) {
console.log(`${filepath} : rendering of markdown failed for file 😱`)
throw e
}
return entity
}
cachedPages[page.filename] = page;
}
site.pages = [];
let nSkip = 0;
console.log(`readPages ${site.files.length}`);
for (let file of site.files) {
let page = _.cloneDeep(defaultPage);
if (_.has(cachedPages, file)) {
_.assign(page, cachedPages[file]);
}
page.filename = file;
let modified = getModifiedDate(file);
if (Date.parse(modified) != Date.parse(page.modified)) {
_.assign(page, yamlFront.loadFront(file, "content"));
let markdown = page.content
let html = convertUnicodeCharsToHtml(render(markdown))
page.content = html
page.modified = modified;
} else {
nSkip += 1;
}
if (page.date) {
page.date = new Date(page.date);
}
if (!page.slug) {
let name = path.basename(stripExtOfPathname(page.filename));
page.slug = slug(normalize(name));
}
if (!page.url) {
function baseInfo(file, path) {
const meta = YFM.loadFront(file);
const content = meta.__content;
delete meta.__content;
return {
meta : meta,
path : path,
content: MD(content),
raw : content
}
}
function parseNote(content) {
var note = new Note();
var doc = yaml.loadFront(content);
if (doc.title != undefined)
note.title = doc.title;
else { //auto generate note title and write new title into YAML metadata
note.title = getTitle(doc.__content);
}
//remove line breaks
try {
note.title = note.title.trim().replace(/(\r\n|\n|\r)/gm,"");
}
catch (e) {
return ErrorHandler.LogError('error when replacing note.title line breaks: ' + e);
}
if (doc.tags != undefined)
extractFromString (str) {
let obj = yamlFront.loadFront(str)
delete obj.__content
if (_.size(obj) !== 0) {
return obj
} else {
return false
}
}