How to use the front-matter 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 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 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 Popmotion / popmotion / site / pages / docs.js View on Github external
static async getInitialProps({ query: { id }}) {
    const request = new Request(
      'https://raw.githubusercontent.com/Popmotion/popmotion/master/docs/api/calc.md',
      {
        headers: new Headers({
          'Content-Type': 'text/plain'
        })
      }
    );
    const response = await fetch(request);
    const doc = await response.text();
    const { attributes, body } = frontMatter(doc);
    const { title, description } = attributes;

    return {
      title,
      description,
      body
    };
  }
github CloudBreadProject / CloudBread-Admin-Web / src / api / content / index.js View on Github external
function parseJade(jadeContent) {
  const fmContent = fm(jadeContent);
  const htmlContent = jade.render(fmContent.body);
  return Object.assign({ content: htmlContent }, fmContent.attributes);
}
github ionic-team / stencil-site / scripts / markdown-to-html.ts View on Github external
return Promise.resolve();
    }
    let htmlContents = '';
    let markdownMetadata: MarkdownContent = {};
    const jsonFileName = path.relative(SOURCE_DIR, filePath);
    const destinationFileName = path.join(
      DESTINATION_DIR,
      path.dirname(jsonFileName),
      path.basename(jsonFileName, '.md') + '.json'
    );
    markdownMetadata.headings = [];

    const markdownContents = await readFile(filePath, { encoding: 'utf8' });

    try {
      let parsedMarkdown = frontMatter(markdownContents);
      parsedMarkdown = await getGithubData(filePath, parsedMarkdown);

      const renderer = new marked.Renderer();

      collectHeadingMetadata(renderer, markdownMetadata);
      changeCodeCreation(renderer);
      localizeMarkdownLink(renderer, destinationFileName.replace('src',''), siteStructureJson);
      htmlContents = marked(parsedMarkdown.body, {
        renderer,
        headerIds: true
      }).trim();

      await mkdirp(path.join(
        DESTINATION_DIR,
        path.dirname(jsonFileName)
      ));
github awslabs / aws-api-gateway-developer-portal / dev-portal / src / services / get-fragments.js View on Github external
fetch(path).then(response => response.text().then(text => {
    let parsedMarkdown = frontmatter(text)

    fragments[fragment] = {
      jsx: () => (
        
      ),
      ...parsedMarkdown.attributes
    }
  }))
}
github patternplate / patternplate / packages / server / source / library / utilities / get-pattern-tree.js View on Github external
if (existing) {
                level = existing;
                return null;
              }

              const fromPatterns = path.resolve.bind(null, "./patterns");
              const contents = await getDoc(fromPatterns(...itemPath), {
                type
              });

              const ast = remark().parse(contents);
              const first = find(ast, { type: "heading", depth: 1 });
              const front =
                typeof contents === "string"
                  ? frontmatter(contents).attributes
                  : {};
              const manifest = merge({}, DEFAULT_MANIFEST, front);
              manifest.name = first ? first.children[0].value : name;
              manifest.displayName = manifest.displayName || manifest.name;

              const item = {
                contents,
                name,
                manifest: type === "folder" ? manifest : file.manifest,
                id: parts.slice(0, i + 1).join("/"),
                path: itemPath,
                type
              };

              level.children.push(item);

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