How to use the yaml-front-matter.loadFront function in yaml-front-matter

To help you get started, we’ve selected a few yaml-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 wxsms / blog / build / build-posts.js View on Github external
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
github vuejs / vue-cli / packages / @vue / cli / lib / GeneratorAPI.js View on Github external
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 ''
    }
github scottstanfield / markdown-to-json / lib / m2j.js View on Github external
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'];
github luoxue-victor / webpack-box / packages / cli / lib / GeneratorAPI.js View on Github external
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 ''
    }
github evilz / vscode-reveal / src / Helpers.ts View on Github external
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}`;
    }
github popcorn-nantes / popcorn-nantes / modules / gustave / lib / markdown.js View on Github external
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
}
github boscoh / embellish / embellish.js View on Github external
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) {
github NG-ZORRO / ng-zorro-antd / scripts / site / utils / generate-docs.js View on Github external
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
  }
}
github tgig / Gnotes / lambda / DB-retrieve-files / index.js View on Github external
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)
github mustardamus / lehm / lib / front_matter.js View on Github external
extractFromString (str) {
    let obj = yamlFront.loadFront(str)

    delete obj.__content

    if (_.size(obj) !== 0) {
      return obj
    } else {
      return false
    }
  }

yaml-front-matter

yaml front matter for JS. Parse yaml or JSON from the beginning of files.

MIT
Latest version published 4 years ago

Package Health Score

50 / 100
Full package analysis