Markdown Repository

npm versionLicense

Use markdown files like a database. Read directories of .md or .mdx files, query them by frontmatter fields, sort, filter, and limit — with an API modeled after Firestore.

$ npm install markdown-repository

Examples

import { MarkdownRepository, get } from "markdown-repository";

const posts = new MarkdownRepository("posts");
const all = get(posts);

Query Operators

All Firestore comparison operators, applied to frontmatter fields.

==Equal
!=Not equal
<Less than
<=Less than or equal
>Greater than
>=Greater than or equal
array-containsArray includes value
array-contains-anyArray includes any of values
inValue is one of
not-inValue is none of

Features

Firestore-style API

Functional query builder with where, orderBy, limit — compose constraints naturally.

.md and .mdx

Both extensions supported by default. No configuration needed.

Recursive directories

Nested folder structures with path-based slugs like discovery/worth-building.

TypeScript generics

Full type safety with custom validators. Generics flow through repository to query to get.

Zero config

Point at a directory, start querying. Sensible defaults for extensions and behavior.

Sync and lightweight

One dependency (gray-matter). Synchronous reads — perfect for static site generation.

Item Shape

interface MarkdownItem {
  slug: string;       // filename without extension
  content: string;    // markdown body after frontmatter
  excerpt: string;    // auto-extracted excerpt
  [key: string]: any; // all frontmatter fields
}

How It Works

1

Point at a directory

Create a MarkdownRepository with the path to your .md or .mdx files. Both extensions are supported by default.

2

Build a query

Compose constraints with where(), orderBy(), and limit() — the same pattern as Firestore's modular SDK.

3

Execute with get()

Call get() to read files, parse frontmatter, and return typed results. Get all items, one by slug, or query results.

Firestore-Style Query Builder for Markdown

markdown-repository brings Firestore's functional query pattern to local markdown files. Constraints are standalone functions that compose via query() and execute via get(). Filter by any frontmatter field using 10 operators: equality, comparison, array membership, and value membership.

Built for Static Sites and Content-Heavy Apps

Designed for Next.js, Astro, and any framework that reads content at build time. Synchronous reads work with generateStaticParams and getStaticProps. One dependency (gray-matter), TypeScript generics for type-safe frontmatter access, and recursive directory support for nested content structures.

FAQ

Varstatt Toolkit

Each tool works standalone, runs entirely in your browser, and requires no signup.

Built & Maintained by Varstatt

Varstatt is a one-person product studio run by Jurij Tokarski, product engineer since 2011. These tools are free and open — no signup, no catch.