How to use the front-matter.test function in front-matter

To help you get started, we’ve selected a few front-matter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github HelixDesignSystem / helix-ui / scripts / _generate / context.js View on Github external
function _getFrontMatter (relPath) {
    let frontMatter = {};

    try {
        let content = fs.readFileSync(`${CONFIG.docsDir}/${relPath}`, 'utf8');
        if (fm.test(content)) {
            Object.assign(frontMatter, fm(content).attributes);
        }
    } finally {
        // nothing to do
    }

    return frontMatter;
}//_getFrontMatter()
github brackets-userland / brackets-sass-lint / node_modules / sass-lint / lib / groot.js View on Github external
module.exports = function (text, syntax, filename) {
  var tree;

  // Run `.toString()` to allow Buffers to be passed in
  text = helpers.stripBom(text.toString());

  // if we're skipping front matter do it here, fall back to just our text in case it fails
  if (fm.test(text)) {
    text = fm(text).body || text;
  }

  try {
    tree = gonzales.parse(text, {
      'syntax': syntax
    });
  }
  catch (e) {
    throw {
      message: e.message,
      file: filename,
      line: e.line
    };
  }
github hanamura / gulp-minisite / src / index.js View on Github external
var initFile = function(file) {
    var data = file.data = parse(file.relative, {locales: options.locales});

    // data.locale
    data.locale || (data.locale = options.defaultLocale);

    // data.document
    if (~(options.dataExtensions || []).indexOf(data.extname)) {
      data.document = 'data';
    } else if (fm.test(file.contents.toString())) {
      data.document = 'text';
    } else {
      data.document = false;
    }

    // data.filepaths
    data.filepaths = [];
    data.filepaths.push(data.locale === options.defaultLocale ? null : data.locale);
    data.filepaths.push.apply(data.filepaths, data.dirnames);
    if (data.document) {
      data.filepaths.push(data.index ? null : data.slug);
      data.filepaths.push('index.html');
    } else {
      data.filepaths.push(data.slug + '.' + data.extname);
    }
    data.filepaths = data.filepaths.filter(function(x) { return x });
github Siedrix / paperpress / paperpress.js View on Github external
item.title = item.title || name
		item.slug = item.slug || slug

		if (item.date) {
			item.date = new Date(item.date)
		}
	} else {
		item = {
			title: name,
			slug: slug,
			content: fileContent,
			path: null
		}
	}

	if (frontMatter.test(fileContent)) {
		var contentData = frontMatter(fileContent)
		var dataAttributes = contentData.attributes

		Object.keys(dataAttributes)
			.filter(function (k) { // prevents attribute leaking
				return dataAttributes.hasOwnProperty(k)
			})
			.forEach(function (k) { // merges into item object
				item[k] = dataAttributes[k]
			})

		// Assign parsed content
		item.content = contentData.body

		// If date exists then parse it
		if (dataAttributes.date) {
github markedjs / marked / test / index.js View on Github external
fs.readdirSync(path.resolve(__dirname, 'original')).forEach(function(file) {
    var text = fs.readFileSync(path.resolve(__dirname, 'original', file), 'utf8');

    if (path.extname(file) === '.md') {
      if (fm.test(text)) {
        text = fm(text);
        text = '---\n' + text.frontmatter + '\ngfm: false\n---\n' + text.body;
      } else {
        text = '---\ngfm: false\n---\n' + text;
      }
    }

    fs.writeFileSync(path.resolve(__dirname, 'compiled_tests', file), text);
  });
github sawyerh / highlight-utils / packages / highlights-email-to-json / index.js View on Github external
function valid(text) {
  return text && frontmatter.test(text.trim());
}
github DragonsInn / BIRD3 / app / System / Config / webpack.js View on Github external
mdOpt.preprocess = function(parser, env, source) {
            var fm = require("front-matter");
            var _ = require("microdash");
            if(fm.test(source)) {
                var fmData = fm(source);
                env = _.extend(env, fmData.attributes);
                return fmData.body;
            } else {
                return source;
            }
        }
        return mdOpt;
github HelixDesignSystem / helix-ui / scripts / _generate / markup.js View on Github external
fs.readFile(`${CONFIG.docsDir}/${relPath}`, 'utf8', (err, data) => {
        if (err) {
            next(err);
        } else {
            const nextFile = {
                path: relPath,
                content: (fm.test(data) ? fm(data).body : data)
            };

            next(err, nextFile, ctx);
        }
    });
}//_readWithContext

front-matter

Extract YAML front matter from a string

MIT
Latest version published 4 years ago

Package Health Score

71 / 100
Full package analysis

Popular front-matter functions