0.1.8 ā€¢ Published 11 months ago

@flowershow/markdowndb v0.1.8

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

MarkdownDB

npm.io

MarkdownDB is a javascript library for treating markdown files as a database -- as a "MarkdownDB". Specifically, it:

  • Parses your markdown files to extract structured data (frontmatter, tags etc) and creates an index in a local SQLite database
  • Provides a lightweight javascript API for querying the database and importing files into your application

šŸš§ MarkdownDB is in its early development stage

Quick start

Install the MarkdownDB package in your Node.js project:

npm i @flowershow/markdowndb

And run the following command, passing the path to your markdown content folder as an argument.

npx mddb <path-to-your-content-folder>
# e.g.
# npx mddb my-mddb-content

...or, if you don't have a Node.js project and just want to index your content into an SQLite databse and handle the rest on your own:

npx @flowershow/markdowndb <path-to-your-content>

šŸŽ‰ Done! You should see a new markdown.db file created in the directory where you ran the command.

You can preview it with any SQLite viewer, e.g. https://sqlitebrowser.org/.

You can also add it as a script to your package.json file:

{
  "name": "my-mddb-app",
  "scripts": {
    ...
    "mddb": "mddb <path-to-your-content-folder>",
    "prebuild": "npm run mddb"
  },
  ...
}

Now, once the data is in the database, you can add the following script to your project (e.g. in /lib folder). It will allow you to establish a single connection to the database and use it across you app.

// lib/mddb.ts
import { MarkdownDB } from "@flowershow/markdowndb";

const dbPath = "markdown.db";

const client = new MarkdownDB({
    client: "sqlite3",
    connection: {
        filename: dbPath,
    },
});

const clientPromise = client.init();

export default clientPromise;

Now, you can import it across your project to query the database, e.g.:

import clientPromise from "@/lib/mddb";

const mddb = await clientPromise;
const blogs = await mddb.getFiles({
  folder: "blog",
  extensions: ["md", "mdx"],
});

With Next.js project

For example, in your Next.js project's pages, you could do:

// /pages/blog/index.ts

import clientPromise from "@/lib/mddb";
import { BlogsList, SimpleLayout } from "@/components";

export default function Blog({ blogs }) {
  return (
    <>
      <SimpleLayout title="Blog posts">
        <BlogsList blogs={blogs} />
      </SimpleLayout>
    </>
  );
}

export async function getStaticProps() {
  const mddb = await clientPromise;
  let blogs = await mddb.getFiles({
    folder: "blog",
    extensions: ["md", "mdx"],
  });

  const blogsObjects = blogs.map((b) => b.toObject());

  return {
    props: {
      blogs: blogsObjects,
    },
  };
}

API reference

TBD

Features

  • indexing markdown files into an SQLite database, with:
    • frontmatter data extraction (specifically tags and document types)
    • wiki links extraction (CommonMark links, Obsidian links and embeds)
  • querying database for:
    • a list of all or some of the markdown files in your content folder: e.g. get all your blog posts tagged with "tutorial"
    • get backlinks to or forward on a given page, and e.g. list them in the bottom of your pages, so that users can quickly find related content

Upcoming features

  • custom document types and schemas with data validation
  • computed fields
  • indexing multiple folders
  • extracting tasks
  • and much more...
0.1.8

11 months ago

0.1.7

11 months ago

0.1.6

11 months ago

0.1.5

12 months ago

0.1.4

12 months ago

0.1.3

12 months ago

0.1.2

12 months ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago