Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
`\nFrontmatter key '${key}' is required but ${file.metadata.fileName} for source ${file.metadata.source} is missing it and will be ignored`,
);
// is there a defaultable value we can provide
} else if (valueIsInvalid && DEFAULTS[key]) {
frontmatter[key] = DEFAULTS[key]();
}
});
// attach front matter properties to metadata
file.metadata = {
...file.metadata,
resourceTitle: frontmatter.title,
resourceDescription: frontmatter.description,
ignore: frontmatter.ignore,
};
// create 'new' md string with updated front matter
file.content = matter.stringify(data.content, frontmatter);
return file;
}
return file;
};
toFile(data, sortedKeys) {
const { body = '', ...meta } = data;
// Stringify to YAML if the format was not set
const format = this.format || getFormatOpts('yaml');
if (this.customDelimiter) this.format.delimiters = this.customDelimiter;
// `sortedKeys` is not recognized by gray-matter, so it gets passed through to the parser
return matter.stringify(body, meta, { engines: parsers, sortedKeys, ...format });
}
}
data.subtitle = post.subtitle;
}
if (post.excerpt) {
data.excerpt = post.excerpt;
}
if (thumbPath) {
data.thumb_img_path = thumbPath;
}
if (post.splashImageUrl) {
data.content_img_path = imageMap.has(post.splashImageUrl)
? `images/${slug}/${imageMap.get(post.splashImageUrl)}`
: post.splashImageUrl;
}
const outputFilename = path.join(outputDir, `${slug}.md`);
const yamlContent = matter.stringify(bodyMarkdown, data);
fs.writeFileSync(outputFilename, yamlContent);
console.log('done with ' + outputFilename);
});
}
function updateUpdatedDate( bestOfTemplatePath, updatedDate ) {
var bestofFrontMatter = matter( fs.readFileSync( bestOfTemplatePath, 'utf8') );
var data = bestofFrontMatter.data;
data.dataUpdatedDate = updatedDate;
console.log( "Writing", bestOfTemplatePath );
fs.writeFileSync( bestOfTemplatePath, matter.stringify(bestofFrontMatter.content, data, {lineWidth: 9999}));
}
function writeFile(path, name, frontMatter, content = '') {
try {
fs.writeFileSync(path, matter.stringify(content, frontMatter));
const type = program.draft ? 'Draft' : 'Post';
if (name.endsWith('.md')) {
console.log(`${type} '${name}' created.`);
} else {
console.log(`${type} '${name}.md' created.`);
}
return true;
} catch (err) {
console.log(err);
return false;
}
}
saveWorkbook() {
if (this.workbookEditor != null && this.workbook != null) {
const contentToSave = this.workbookEditor.getContentToSave()
const saveableManifest = this.workbook.getManifestToSave()
const workbook = matter.stringify(contentToSave, saveableManifest, {
delims: ["---", "---\n"]
})
var blob = new Blob([workbook], { type: "text/markdown;charset=utf-8" })
saveAs(blob, `${this.workbook.manifest.title}.workbook`)
}
}
function buildFile(file) {
return matter.stringify(file.bodyLines.join('\n'), file.frontmatter)
}
set ( content: string, metadata: object ): string {
content = Gutter.add ( matter ( content, Metadata.options ).content );
if ( !_.isEmpty ( metadata ) ) {
content = matter.stringify ( content, metadata, Metadata.options );
}
return content;
},
export function stringify(str = '', data = {}) {
return matter.stringify(str, data);
}
module.exports = function webpackCodeInjectLoader(source) {
const options = getOptions(this) || {};
validateOptions(schema, options, 'Mdx Code Inject Loader');
const codeToInject = [
options.globalImports,
hasDefinedLayout(source) ? null : options.defaultLayout,
]
.filter(Boolean)
.join('\n');
if (!codeToInject) return source;
const { data, content } = grayMatter(source);
return grayMatter.stringify(`${codeToInject}\n\n${content}`, data);
};