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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@contedra/md-importer

v0.2.2

Published

CLI tool to import YAML-frontmatter Markdown files + images into Firestore using model definition JSON

Downloads

158

Readme

@contedra/md-importer

CLI tool and library to import YAML-frontmatter Markdown files (with images) into Firestore, using Conteditor model definition JSON for schema validation.

Installation

pnpm add @contedra/md-importer

CLI Usage

npx @contedra/md-importer \
  --md-dir ./content \
  --model ./models/blog_posts.json \
  --project-id your-project-id \
  --credential ./service-account.json \
  --storage-bucket your-project-id.firebasestorage.app

CLI Options

| Option | Required | Description | |--------|----------|-------------| | --md-dir <path> | Yes | Directory containing .md files | | --model <path> | Yes | Path to model definition JSON | | --project-id <id> | Yes | Firebase project ID | | --credential <path> | No | Path to service account JSON (uses ADC if omitted) | | --collection <name> | No | Firestore collection name (defaults to modelName) | | --storage-bucket <name> | No* | Firebase Storage bucket name (e.g. your-project.firebasestorage.app) | | --no-images | No | Skip image extraction, upload, and URL replacement | | --image-base-dir <path> | No | Directory for resolving absolute image paths (e.g. ./public) | | --image-fields <fields> | No | Comma-separated frontmatter field names containing image paths (e.g. heroImage,cover) | | --field-mapping <json> | No | JSON mapping frontmatter keys to model properties |

* --storage-bucket is required unless --no-images is set.

Field Mapping

When your Markdown frontmatter keys don't match the model property names, use --field-mapping:

npx @contedra/md-importer \
  --md-dir ./content \
  --model ./models/blog_posts.json \
  --project-id your-project-id \
  --field-mapping '{"article_title":"title","article_date":"publishedAt"}'

Unmapped frontmatter keys that match model property names are auto-matched.

Programmatic API

mdImporter(config): Promise<ImportResult>

import { mdImporter } from "@contedra/md-importer";

const result = await mdImporter({
  mdDir: "./content",
  modelFile: "./models/blog_posts.json",
  firebaseConfig: {
    projectId: "your-project-id",
    credential: "./service-account.json",
    storageBucket: "your-project-id.firebasestorage.app",
  },
  fieldMapping: {
    article_title: "title",
    article_date: "publishedAt",
  },
  imageFields: ["heroImage", "cover"],  // frontmatter fields containing image paths
  // noImages: true,  // set to skip all image processing
});

console.log(`Imported: ${result.imported.length}`);
console.log(`Errors: ${result.errors.length}`);

Custom Image Resolver

By default, local images referenced in Markdown are read from the filesystem and uploaded to Firebase Storage (assets/{modelName}/{contentId}/{fileName}). Provide a custom resolver to change this behavior:

const result = await mdImporter({
  mdDir: "./content",
  modelFile: "./models/blog_posts.json",
  firebaseConfig: { projectId: "your-project-id" },
  resolveImage: async (imagePath, mdFilePath) => {
    const response = await fetch(`https://cdn.example.com/${imagePath}`);
    return Buffer.from(await response.arrayBuffer());
  },
});

Helper Functions

  • generateDocId(filePath) — Converts a filename to a slugified Firestore document ID
  • parseMarkdownFile(filePath) — Parses a .md file into { frontmatter, body }
  • parseMarkdownString(content) — Parses a markdown string (uses gray-matter)
  • mapFields(frontmatter, model, fieldMapping?) — Maps frontmatter fields to model properties, returns { data, unmapped }

Image Handling

Images referenced in Markdown (e.g., ![alt](./images/photo.png)) are:

  1. Extracted from the markdown body
  2. Resolved via the local filesystem (or custom resolveImage)
  3. Uploaded to Firebase Storage at assets/{modelName}/{contentId}/{fileName}
  4. Replaced in the markdown body with asset:// URIs

External URLs (http://, https://) and asset:// URIs are skipped.

License

MIT