How to use front-matter - 10 common examples

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 callstack / component-docs / src / parsers / md.js View on Github external
.split('\n')
    .map(line => {
      if (/^\/.+\.md$/.test(line)) {
        const f = path.join(path.dirname(filepath), line);
        const result = md(f, { root });

        dependencies.push(...result.dependencies, f);

        return result.data;
      }
      return line;
    })
    .join('\n');

  // Load YAML frontmatter
  const { body: data, attributes: meta } = frontmatter(text);

  const title = meta.title || getNameFromPath(filepath);

  return {
    filepath: path.relative(root, filepath),
    title,
    description: meta.description || '',
    link: meta.link || dashify(title),
    data,
    type: 'md',
    dependencies,
  };
}
github anvilabs / anvilabs.co / post-build.js View on Github external
_.map((post: BlogPostType & {path: string, requirePath: string}) => {
      // read the markdown file
      const content = String(
        fs.readFileSync(path.join(__dirname, `/pages/${post.requirePath}`))
      );
      // extract yaml meta tags
      const meta = frontMatter(content);
      // render markdown to html
      const html = md.render(meta.body);
      // replace relative links with absolute ones
      const $ = parseHtml(html, {
        recognizeSelfClosing: true,
        decodeEntities: false,
      });
      $('img').each((idx: number, elem: Object) => {
        const src = _.last(
          $(elem)
            .attr('src')
            .split('./')
        );
        $(elem).attr('src', `${hostname}${post.path}${src}`);
      });
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 egoist / eme / src / vuex / modules / editor.js View on Github external
const renderHTML = tab => {
  const render = tab => md.render(tab.content).replace(/src="([^"]+)"/g, (m, p1) => {
    if (p1[0] === '.') {
      p1 = path.join(path.dirname(tab.filePath), p1)
      return `src="${p1}"`
    }
    return m
  })

  const data = fm(tab.content)

  if (tab.isPresentationMode) {
    return {
      attrs: data.attributes,
      html: data.body.split('\n\n---\n\n')
        .map(content => render({
          content,
          filePath: tab.filePath
        }))
    }
  }
  return {
    attrs: data.attributes,
    html: xss(render({content: data.body, filePath: tab.filePath}))
  }
}
github runelite / runelite.net / rollup.config.js View on Github external
transform (md, id) {
      if (!/\.md$/.test(id)) return null
      if (!filter(id)) return null

      const data = fm(md)
      data.body = snarkdown(data.body)
      return {
        code: `export default ${JSON.stringify(data)};`,
        map: { mappings: '' }
      }
    }
  }
github sawyerh / highlight-utils / packages / highlights-email-to-json / index.js View on Github external
function valid(text) {
  return text && frontmatter.test(text.trim());
}

front-matter

Extract YAML front matter from a string

MIT
Latest version published 4 years ago

Package Health Score

58 / 100
Full package analysis

Popular front-matter functions