How to use the gray-matter.stringify function in gray-matter

To help you get started, we’ve selected a few gray-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 bcgov / devhub-app-web / app-web / plugins / gatsby-source-github-all / utils / plugins.js View on Github external
`\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;
};
github netlify / netlify-cms / packages / netlify-cms-core / src / formats / frontmatter.js View on Github external
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 });
  }
}
github stackbithq / stackbit-medium-importer / src / importer.js View on Github external
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);
    });
}
github zachleat / zachleat.com / grunt-tasks / bestof.js View on Github external
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}));
		}
github robcrocombe / jekyll-post / post.js View on Github external
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;
  }
}
github microsoft / workbooks / Clients / Xamarin.Interactive.Client.Web / ClientApp / components / WorkbookShell.tsx View on Github external
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`)
        }
    }
github okta / okta-developer-docs / packages / @okta / migrate-from-jekyll / index.js View on Github external
function buildFile(file) {
  return matter.stringify(file.bodyLines.join('\n'), file.frontmatter)
}
github notable / notable / src / renderer / utils / metadata.ts View on Github external
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;

  },
github reptar / reptar / lib / parse / front-matter.js View on Github external
export function stringify(str = '', data = {}) {
  return matter.stringify(str, data);
}
github karolis-sh / gatsby-mdx / packages / gatsby-transformer-mdx / utils / webpack-mdx-inject-loader.js View on Github external
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);
};

gray-matter

Parse front-matter from a string or file. Fast, reliable and easy to use. Parses YAML front matter by default, but also has support for YAML, JSON, TOML or Coffee Front-Matter, with options to set custom delimiters. Used by metalsmith, assemble, verb and

MIT
Latest version published 4 years ago

Package Health Score

76 / 100
Full package analysis