How to use the gray-matter 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 getgridea / gridea / src / server / posts.ts View on Github external
await Promise.all(results.map(async (result: any, index: any) => {
      const postMatter = matter(result)
      const data = (postMatter.data as any)

      data.title = formatYamlString(data.title)

      if (data && data.date) {
        if (typeof data.date === 'string') {
          data.date = moment(data.date).format('YYYY-MM-DD HH:mm:ss')
        } else {
          data.date = moment(data.date).subtract(8, 'hours').format('YYYY-MM-DD HH:mm:ss')
        }
      }

      // If there is a `tag` and it is of string type, it is corrected to array type.
      if (data && typeof data.tags === 'string') {
        const tagReg = /tags: [^\s[]/i
        const newTagString = data.tags.split(' ').toString()
github FormidableLabs / spectacle / config / plugins / mdx-plugin / parse.js View on Github external
const parse = (src, options) => {
  const inlineModules = [];
  const { data, content } = matter(src);

  const separatedContent = normalizeNewline(content)
    /*
     * Set aside all inline JSX import and export statements from the MDX file.
     * When mdx.sync() compiles MDX into JSX, it will stub any component that doesn't
     * have a corresponding import. Therefore, we will re-add all of the imports/exports
     * to each slide before compiling the MDX via mdx.sync().
     */
    .replace(MOD_REG, (value, group1) => {
      if (!group1) {
        // group1 is empty, so this is not the import/export case we're looking for
        return value;
      } else {
        // found an inline export or import statement
        inlineModules.push(value);
        return '';
github nuxt-community / nuxtent-module / lib / content / page.ts View on Github external
get _rawData(): Nuxtent.Page.RawData {
    if (isDev || !this.cached.data.fileName) {
      const source = readFileSync(this.__meta.filePath).toString()
      const fileName = this.__meta.fileName
      this.cached.data.fileName = fileName
      if (fileName.search(/\.(md|html)$/) !== -1) {
        // { data: attributes, content: body } = matter(source)
        const result = matter(source, {
          excerpt: !!this.config.excerpt,
        })
        this.cached.data.attributes = result.data
        if (!!this.config.excerpt) {
          this.cached.data.attributes.excerpt =
            fileName.endsWith('md') &&
            this.config.markdown.parser &&
            result.excerpt
              ? this.config.markdown.parser.render(result.excerpt)
              : result.excerpt
        }
        this.cached.data.body.content = result.content
      } else if (fileName.search(/\.(yaml|yml)$/) !== -1) {
        this.cached.data.body.content = yaml.load(source)
      } else if (fileName.endsWith('.json')) {
        this.cached.data.body.content = JSON.parse(source)
github openmultiplayer / web / frontend / src / pages / docs / [[...path]].tsx View on Github external
context: GetStaticPropsContext<{ path: string[] }>
): Promise> {
  const { locale } = context;
  const route = context?.params.path || ["index"];

  let result: { source: string; fallback: boolean };
  const path = route.join("/");
  try {
    result = await readLocaleDocs(path, locale);
  } catch (e) {
    return {
      props: { error: `File ${path} (${locale}) not found: ${e.message}` },
    };
  }

  const { content, data } = matter(result.source);

  // TODO: plugins for admonitions and frontmatter etc
  // also, pawn syntax highlighting
  const mdxSource = await renderToString(content, {
    components,
    remarkPlugins: [admonitions],
  });

  return {
    props: {
      source: mdxSource,
      data,
      fallback: result.fallback,
    },
  };
}
github vuejs / vuepress / packages / @vuepress / shared-utils / src / parseFrontmatter.ts View on Github external
export = function parseFrontmatter (content: string) {
  return matter(content, {
    // eslint-disable-next-line @typescript-eslint/camelcase
    excerpt_separator: '',
    engines: {
      toml: toml.parse.bind(toml)
    }
  })
}
github rigor789 / nativescript-vue-documentation / src / markdown-it-extends.js View on Github external
axios.get(matter.extends.toString()).then(res => {
        md.isExtending = true;
        md.extendMatter = matter;

        const addition = '\n' + grayMatter(store.state.current.raw_content).content;
        store.commit('SET_CURRENT_RAW_CONTENT', res.data);
        store.commit('SET_CURRENT_CONTENT', md.render(res.data) + md.render(addition));
      });
    }
github mdx-js / mdx / src / JSXCodeBlock.js View on Github external
export default ({
  components,
  theme = {},
  code,
  className,
  frontmatter,
  ...props
})  => {
  const fullScope = Object.assign({}, components, {
    ...frontmatter,
    ThemeProvider,
    theme
  })

  const lang = (className[0] || '').split(/-\./)[1] || 'jsx'
  const parsedCode = matter(code)

  return (
     transformCode(newCode, theme, lang)}
      {...props}
    >
      
      {parsedCode.data.liveEditor ?  : null}
      
    
  )
}
github c8r / kit / src / LiveEditor.js View on Github external
constructor (props) {
    super()

    const {
      code,
      theme,
      components,
      scope
    } = props

    const { content, data = {} } = matter(code)

    const defaultScope = {
      ThemeProvider,
      XRay,
      props,
      theme
    }

    const fullScope = Object.assign(defaultScope, components, scope)

    this.state = {
      fullScope,
      rawCode: content,
      options: data,
      xray: false,
      viewport: data.viewport
github nuxt-community / nuxtent-module / lib / loader.ts View on Github external
`The folder ${section} is not configured in nuxtent and therefore ignored`
    )
    return
  }

  const [, fileName = ''] =
    this.resourcePath.match(/[/\\]content([/\\\w\-_]*)(\.comp\.md$)?|$/) || []
  if (!fileName) {
    this.emitError(new Error('The resource is not a markdown file'))
  }

  if (!dirOpts.markdown.parser) {
    return this.emitError(new Error('Could not found markdown parser'))
  }

  const frontmatter = matter(source)

  const { transformedSource, components } = transformMdComponents(
    frontmatter.content,
    componentsDir,
    extensions
  )

  /**
   * import components from the array on the frontmatter $components
   */
  if (
    frontmatter.data.$components &&
    Array.isArray(frontmatter.data.$components)
  ) {
    for (const name of frontmatter.data.$components) {
      const usedComponent = _.camelCase(name)

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 3 years ago

Package Health Score

76 / 100
Full package analysis