npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

flatpages

v0.2.4

Published

Flask-FlatPages for Node.js

Downloads

8

Readme

flatpages

Build Status Coverage Status JavaScript Style Guide

Like Flask-FlatPages but in javascript. It's useful for annotating markdown files with some basic metadata.

Flatpages parses markdown files by splitting it at the first empty line (or a custom string) and interpreting the first section as YAML using js-yaml, and the second as Markdown using Marked. When given a directory, flatpages traverses it and parses each file it finds that matches its sought extension (.md and .markdown by default). Once it's done, it returns a Promise that resolves to the meta data, html text, and raw text of each parsed file.

For example, consider this markdown file:

cats-on-roombas.md

tags:
  - cats
  - roombas
  - cats on roombas

# Cats on Roombas

Cats are sometimes known to sit atop household automotons like the "Roomba" vacuum cleaner, appearing to ride it. Between 2010 and 2012 media depicting cats on roombas garnered tens of millions of views on YouTube alone, becoming a memetic phenomenon. While such media is still produced, the novelty has waned over time as advanced household automotons have become more common.

You can use flatpages to read such annotated markdown files like this:

const flatpages = require('flatpages')

flatpages('./cats-on-roombas.md').then((result) {
  console.log(result)
  // {
  //   meta: {
  //     tags: ['cats', 'roombas', 'cats on roombas']
  //   },
  //   body: '# Cats on Roombas\n\Cats are sometimes known to...',
  //   html: '<h1>Cats on Roombas</h1>...'
  // }
  })

Note: Flatpages breaks pages at the first empty line (or a specified string) and assume that everything above it is YAML while everything below it is Markdown. If you want no YAML on your page, make its first line blank (or otherwise make sure it matches the split string you specify).

Installation

Install with npm:

npm install flatpages

Usage

async flatpages(string fileOrDirPath = '.', object options = {})

options:

  • split: A string used to identify where to separate the YAML portion of the document from the Markdown portion.
  • extension: A regex describing what file extensions to accept. By default, flatpages accepts any file that ends in .md or .markdown.

Returns a promise that resolves to the parsed contents of each file found:

  • meta: An object describing the metadata parsed from the file's YAML.
  • html: The HTML compiled from the file's markdown.
  • body: The file's raw markdown.

Given a file, the promise resolves to an object like this:

{
  meta: {
    tags: ['cats', 'roombas', 'cats on roombas']
  },
  body: '# Cats on Roombas\n\Cats are sometimes known to...',
  html: '<h1>Cats on Roombas</h1>...'
}

Given a directory, the promise resolves to an object reflecting the traversed directory structure, like this:

{
  'entry.md': {
    meta: {
      title: 'Hello, world!'
    },
    body: '# Greetings!',
    html: '<h1>Greetings!</h1>'
  },
  drafts: {
    'feelings.md': {
      meta: {
        title: 'A Case of the Feels'
      },
      body: 'Sad :( _but_ doing my **best**!',
      html: '<p>Sad :( <em>but</em> doing my <strong>best</strong>!</p>'
    }
  }
}

Tests

npm test