Catalog - compile time content processing engine for markdown, json, yaml, and more

Hey all,

I created a library that allows you to easily process your content or data files at compile time, Catalog. It works off of the same root idea as NimblePublisher, but expanded a bit to work with a wider array of use cases.

Check out the docs!

Check out the code!

Example

For those not familiar with the approach, it is commonly used for something like storing blog posts in your Elixir project. For example, if your posts are located in the posts/ directory:

defmodule MyApp.Catalog
  use Catalog

  markdown(:posts, "posts/**.md")

  def all_posts(), do: @posts
end

The markdown macro processes all markdown files in the specified glob path by processing any frontmatter and transforming the markdown into html. You then have a simple API in your project for retrieving that in-memory processed representation of your file. So if you have a single file, hello.md, that contains:

+++
author = "Kevin Lang"
title = "Hello World"
date: 2021-08-19
+++
This is a markdown *document*.

Then the @posts attribute will have the following value:

[%{
  content: "<p>\nThis is a markdown <em>document</em>.</p>\n"
  frontmatter: %{
    author: "Kevin Lang",
    title: "Hello World",
    date: ~D[2021-08-19]
  },
  path: "posts/hello.md"
}]

Features

Some key advantages over NimblePublisher:

  • supports YAML, TOML, and Elixir-code frontmatter
  • supports using multiple times per module, instead of once per module
  • supports JSON, TOML, YAML, CSV, FILE (text/html), MARKDOWN file types

I hope to use this in a static site generator in Elixir I’m working on. I hope it is useful to others too.

4 Likes